Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry08 committed Nov 16, 2024
1 parent c8f0a52 commit 2b3ab6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
23 changes: 15 additions & 8 deletions Yosu/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,30 @@ public partial class App : Application

public static IAlertService AlertSvc { get; private set; } = default!;

public static bool IsChangingTheme { get; set; }

public App(IServiceProvider provider)
{
InitializeComponent();

Services = provider;
AlertSvc = Services.GetService<IAlertService>()!;
AlertSvc = Services.GetRequiredService<IAlertService>();

ApplyTheme();
}

private Window? CurrentWindow { get; set; }
protected override Window CreateWindow(IActivationState? activationState)
{
return new(new AppShell());
if (CurrentWindow is not null && IsChangingTheme)
{
IsChangingTheme = false;
return CurrentWindow;
}

CurrentWindow = new(new AppShell());

return CurrentWindow;
}

public static bool IsOnline(bool showSnackbar = true)
Expand Down Expand Up @@ -105,15 +116,11 @@ public static void RefreshCurrentPageBehaviors()
if (Current is null)
return;

var page = Current.MainPage;
if (page is null)
return;

var gray900Color = Current.Resources["Gray900"];

#if !MACCATALYST
#pragma warning disable CA1416
foreach (var behavior in page.Behaviors.OfType<StatusBarBehavior>())
foreach (var behavior in Shell.Current.Behaviors.OfType<StatusBarBehavior>())
{
behavior.SetAppTheme(
StatusBarBehavior.StatusBarColorProperty,
Expand All @@ -129,7 +136,7 @@ public static void RefreshCurrentPageBehaviors()
#pragma warning restore CA1416
#endif

foreach (var behavior in page.Behaviors.OfType<NavigationBarBehavior>())
foreach (var behavior in Shell.Current.Behaviors.OfType<NavigationBarBehavior>())
{
behavior.SetAppTheme(
NavigationBarBehavior.NavigationBarColorProperty,
Expand Down
3 changes: 3 additions & 0 deletions Yosu/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public SettingsViewModel(PreferenceService preferenceService, SettingsService se

if (e.PropertyName == nameof(Preference.AppTheme))
{
App.IsChangingTheme = true;
App.ApplyTheme();

#if ANDROID
Expand Down Expand Up @@ -65,6 +66,8 @@ private void ThemeSelected(int index)
{
Preference.AppTheme = (AppTheme)index;
Preference.Save();

App.IsChangingTheme = true;
App.ApplyTheme();

#if ANDROID
Expand Down

0 comments on commit 2b3ab6e

Please sign in to comment.