App left in incorrect UserStyleInterface when app is backgrounded

Number:rdar://FB8734191 Date Originated:09/23/2020
Status:Open Resolved:
Product:Dark Mode Product Version:14.0
Classification:Operating System Reproducible:Yes
## Current behavior 
When an app is being put into the background a UIView's `traitCollectionDidChange(previousTraitCollection:)` is called twice. Once with the `traitCollection.userInterfaceStyle` set to the current `userInterfaceStyle` value and once again with the opposite `userInterfaceStyle` style. So for example, if the app was being displayed with the `dark` user interface style, the order would be:
- traitCollection.userInterfaceStyle = .dark
- traitCollection.userInterfaceStyle = .light
Because the last userInterfaceStyle is the opposite of the version at the time of backgrounding, `traitCollectionDidChange` is called with the current OS userInterfaceStyle every time the app subsequently enters the foreground from the background. The app code is then required to switch back to original `userInterfaceStyle`. Continuing with the same example, here is the sequence of events:
** App is in foreground with userInterfaceStyle of `.dark`
** App is backgrounded
- `traitCollectionDidChange(_:)` call with `traitCollection.userInterfaceStyle = .dark`
- `traitCollectionDidChange(_:)` call with `traitCollection.userInterfaceStyle = .light`

** App is brought to the foreground from the background.
- `traitCollectionDidChange(_:)` call with `traitCollection.userInterfaceStyle = .dark`

## Expected Behavior
The app should have the same `userInterfaceStyle` value when entering the foreground from the background as it had before it was backgrounded. That way if the user themselves has not changed their preferred `userInterfaceStyle` the call to `traitCollectionDidChange(_:)` when entering the foreground would be a no-op. 

## Why this is a problem
This causes a user facing problem when switching between user interface styles is not instantaneous. For example, when switching to a custom dark mode or light mode map style. Applying an entire custom map style is not instant. So when the user foregrounds the app there is slight "flicker" when the map is apply the correct style to match the userInterfaceStyle. Even though it shouldn't have to because the user didn't _actually_ change their Dark Mode and Light Mode settings before foregrounding the app.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!