Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[iOS] Fixed RequestedThemeChanged raised twice issue #12895

Merged
merged 1 commit into from
Nov 20, 2020
Merged

Conversation

jsuarezruiz
Copy link
Contributor

Description of Change

The issue is in fact an iOS feature. Is doing multiple snapshots of the app's UI that will be presented in the App Switcher. And since the user could change to Dark Mode while your app is in the background, iOS does snapshots in both interface styles to always show the correct one.

Happens something like: The system takes a screenshot of your Light UI, switches to Dark (first trigger), takes a screenshot (off-screen), and switches back to Light (second trigger). And we have raised twice RequestedThemeChanged.

This PR include changes to only raise RequestedThemeChanged if the App is not in Background. Why?. To avoid raise the event while app snapshots are being taken when going to background. In that way, the App raise the event just 1 time when pass from background to foreground.

Issues Resolved

API Changes

None

Platforms Affected

  • iOS

Behavioral/Visual Changes

None

Before/After Screenshots

Not applicable

Testing Procedure

Launch Core Gallery and navigate to the issue 12512. Then, follow the instructions.

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

Copy link
Member

@jfversluis jfversluis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Yeah, this should bring down the theme switching even more. Did you test what happens when you put the app in the background, then switch theme and then go back to the app? Does it then also pick up the change?

From code this looks like it makes sense!

@rmarinho rmarinho merged commit 350fcfb into 5.0.0 Nov 20, 2020
@rmarinho rmarinho deleted the fix-12512 branch November 20, 2020 15:00
@samhouts samhouts added this to the 5.0.0 milestone Dec 8, 2020
@jsuarezruiz
Copy link
Contributor Author

@jfversluis Yes, tested that case and is working.

@darrencBAS
Copy link

There is an issue with this that is stopping me from using anything newer than -pre4, when double clicking home button to see the application manager on ios, if you have changed the theme the app still in background doesn't show the theme change as it hasn't yet been to foreground to re-render. Prior to pre5 it worked perfectly and as expected, all other apps work like this too in that the app manager shows the app with the correct theme applied.

if (Forms.IsiOS13OrNewer && previousTraitCollection.UserInterfaceStyle != TraitCollection.UserInterfaceStyle)
if (Forms.IsiOS13OrNewer &&
previousTraitCollection.UserInterfaceStyle != TraitCollection.UserInterfaceStyle &&
UIApplication.SharedApplication.ApplicationState != UIApplicationState.Background)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is stopping ios appliaction manager from showing the theme changes until the app is brought back to foreground by the user. It used to show the theme changes because when it went to background ios calls the theme change twice on the app to take a static screenshot of both light and dark theme ready for use in the application manager. Suggest removing UIApplication.SharedApplication.ApplicationState != UIApplicationState.Background from the if statement, this should rectify the problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Application.RequestedThemeChanged raised twice on iOS when switching to home screen and back
5 participants