-
Notifications
You must be signed in to change notification settings - Fork 2k
Cache the dynamic AppTheme value in Controls (and not Essentials) #11200
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
Changes from 9 commits
0df031b
76e7a76
1b8e5a3
9d38c70
14b4cf3
bc5225b
3911e83
ee5d862
5da32cd
349efa3
af2415a
95bc6ea
1df3547
7bc75c6
844d62d
2a78409
bbe5898
8c7735c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,10 +111,8 @@ public virtual void CloseWindow(Window window) | |
|
|
||
| void IApplication.ThemeChanged() | ||
| { | ||
| if (UserAppTheme != AppTheme.Unspecified) | ||
| return; | ||
|
|
||
| TriggerThemeChangedActual(); | ||
| PlatformAppTheme = AppInfo.RequestedTheme; | ||
| PlatformLayoutDirection = AppInfo.RequestedLayoutDirection; | ||
|
mattleibow marked this conversation as resolved.
Outdated
|
||
| } | ||
|
Comment on lines
112
to
115
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of being smart here, we just cache the new value from the OS and let the application decide what it wants to do. It is the same class, but now the property responds in a normal way to raise an event if the value has changed. |
||
|
|
||
| protected virtual Window CreateWindow(IActivationState? activationState) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -561,7 +561,8 @@ private protected override void OnHandlerChangingCore(HandlerChangingEventArgs a | |
|
|
||
| if (FlowDirection == FlowDirection.MatchParent && mauiContext != null) | ||
| { | ||
| FlowController.EffectiveFlowDirection = mauiContext.GetFlowDirection().ToEffectiveFlowDirection(true); | ||
| var flowDirection = Application?.PlatformLayoutDirection.ToFlowDirection() ?? FlowDirection.LeftToRight; | ||
| FlowController.EffectiveFlowDirection = flowDirection.ToEffectiveFlowDirection(true); | ||
|
Comment on lines
-564
to
+566
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this only called once per new
This comment was marked as outdated.
Sorry, something went wrong.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverting the layout direction changes as this is a larger thing and affect locale. Android supports configuration changes on Application and Activity, and each have different effects and requirements. I still reverted the lazy layout direction in the AppInfo as this just fires once when the handler changes - which should basically be once. This code also means that the Activity will need to restart if the locale changes. And this is done automatically by the OS because we don't have the |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,6 @@ class AppInfoImplementation : IAppInfo | |
| #pragma warning disable CS0618, CA1416, CA1422 // Deprecated in API 33: https://developer.android.com/reference/android/content/pm/PackageManager#getPackageInfo(java.lang.String,%20int) | ||
| static readonly Lazy<PackageInfo> _packageInfo = new Lazy<PackageInfo>(() => Application.Context.PackageManager.GetPackageInfo(_packageName.Value, PackageInfoFlags.MetaData)); | ||
| #pragma warning restore CS0618, CA1416, CA1422 | ||
| static readonly Lazy<AppTheme> _requestedTheme = new Lazy<AppTheme>(GetRequestedTheme); | ||
| static readonly Lazy<LayoutDirection> _layoutDirection = new Lazy<LayoutDirection>(GetLayoutDirection); | ||
|
Comment on lines
-19
to
-20
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't cache these as things in the |
||
|
|
||
| public string PackageName => _packageName.Value; | ||
|
|
||
|
|
@@ -44,14 +42,21 @@ public void ShowSettingsUI() | |
| context.StartActivity(settingsIntent); | ||
| } | ||
|
|
||
| static AppTheme GetRequestedTheme() => (Application.Context.Resources.Configuration.UiMode & UiMode.NightMask) switch | ||
| static AppTheme GetRequestedTheme() | ||
| { | ||
| UiMode.NightYes => AppTheme.Dark, | ||
| UiMode.NightNo => AppTheme.Light, | ||
| _ => AppTheme.Unspecified | ||
| }; | ||
| var config = Application.Context.Resources?.Configuration; | ||
|
mattleibow marked this conversation as resolved.
|
||
| if (config == null) | ||
| return AppTheme.Unspecified; | ||
|
|
||
| return (config.UiMode & UiMode.NightMask) switch | ||
| { | ||
| UiMode.NightYes => AppTheme.Dark, | ||
| UiMode.NightNo => AppTheme.Light, | ||
| _ => AppTheme.Unspecified | ||
| }; | ||
| } | ||
|
|
||
| public AppTheme RequestedTheme => _requestedTheme.Value; | ||
| public AppTheme RequestedTheme => GetRequestedTheme(); | ||
|
|
||
| public AppPackagingModel PackagingModel => AppPackagingModel.Packaged; | ||
|
|
||
|
|
@@ -61,10 +66,11 @@ static LayoutDirection GetLayoutDirection() | |
| if (config == null) | ||
| return LayoutDirection.Unknown; | ||
|
|
||
| return (config.LayoutDirection == Android.Views.LayoutDirection.Rtl) ? LayoutDirection.RightToLeft : | ||
| LayoutDirection.LeftToRight; | ||
| return (config.LayoutDirection == Android.Views.LayoutDirection.Rtl) | ||
| ? LayoutDirection.RightToLeft | ||
| : LayoutDirection.LeftToRight; | ||
| } | ||
|
|
||
| public LayoutDirection RequestedLayoutDirection => _layoutDirection.Value; | ||
| public LayoutDirection RequestedLayoutDirection => GetLayoutDirection(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.