-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect UserAppTheme in RequestedTheme #5071
Conversation
public void ThemeChanged() | ||
void IApplication.ThemeChanged() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just an implementation detail and causes conflicts and ambiguity for user code trying to attach the the very similarly named event.
public AppTheme RequestedTheme => AppInfo.RequestedTheme; | ||
public AppTheme RequestedTheme => UserAppTheme != AppTheme.Unspecified ? UserAppTheme : PlatformAppTheme; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the bug!
@@ -167,8 +167,11 @@ public AppTheme UserAppTheme | |||
TriggerThemeChangedActual(new AppThemeChangedEventArgs(value)); | |||
} | |||
} | |||
|
|||
public AppTheme PlatformAppTheme => AppInfo.RequestedTheme; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a new property to get the OS theme so as not to break existing code in a subtle way. I know @PureWeen you suggested not doing this, but I just wanted to mention the potential breaks and if you thought it was worth it?
TriggerThemeChangedActual(new AppThemeChangedEventArgs(value)); | ||
TriggerThemeChangedActual(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was actually incorrect and my test detected it. If you set the user theme to unspecified, then the event would say it was unspecified - but this is not a valid state for the theme as it falls back to the OS theme.
var uiStyle = Platform.GetCurrentUIViewController()?.TraitCollection?.UserInterfaceStyle ?? | ||
UITraitCollection.CurrentTraitCollection.UserInterfaceStyle; | ||
var traits = | ||
MainThread.InvokeOnMainThread(() => Platform.GetCurrentUIViewController()?.TraitCollection) ?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API needs to be accessed from the UI thread.
Description of Change
The #4964 PR made some changes and inadvertently wiped out support for user setting the theme:
https://github.com/dotnet/maui/pull/4964/files?show-deleted-files=true&show-viewed-files=true&file-filters%5B%5D=#diff-e95ac81676df57c3de0226dc120b0e527fbd52bc7fc506ddfde7cccf34a8f489L188
Issues Fixed
Fix #5066