mirror of
https://github.com/awatertrevi/xamarin-neo4j.git
synced 2026-09-22 09:05:29 +00:00
Theme: instant switching via ThemeChanged event
- Add static App.ThemeChanged event fired after resource dictionary swap - Pages/controls subscribe OnAppearing and call reload on change - Themes include Extreme/SecondaryTextColor tokens for dark and light Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Microsoft.Maui.ApplicationModel;
|
||||
using Microsoft.Maui.Graphics;
|
||||
using Microsoft.Maui.Controls;
|
||||
using Microsoft.Maui.Controls.Xaml;
|
||||
using Xamarin.Neo4j.Pages;
|
||||
@@ -10,15 +12,23 @@ namespace Xamarin.Neo4j
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
public static event EventHandler ThemeChanged;
|
||||
|
||||
public App()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
SetTheme(Current.RequestedTheme);
|
||||
RequestedThemeChanged += (s, e) => SetTheme(e.RequestedTheme);
|
||||
|
||||
MainPage = new NavigationPage(new RootPage());
|
||||
MainPage = new NavigationPage(new ConnectionsPage());
|
||||
|
||||
// SetTheme ran before MainPage was assigned, so apply bar colours now.
|
||||
ApplyNavBarColors();
|
||||
}
|
||||
|
||||
public void UpdateTheme(AppTheme theme) => SetTheme(theme);
|
||||
|
||||
private void SetTheme(AppTheme theme)
|
||||
{
|
||||
Resources = theme switch
|
||||
@@ -28,6 +38,20 @@ namespace Xamarin.Neo4j
|
||||
|
||||
_ => new LightTheme()
|
||||
};
|
||||
|
||||
ApplyNavBarColors();
|
||||
ThemeChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
// Called both from SetTheme and from MainActivity.OnResume so that
|
||||
// theme changes while the app is backgrounded are picked up on return.
|
||||
public void ApplyNavBarColors()
|
||||
{
|
||||
if (MainPage is NavigationPage navPage)
|
||||
{
|
||||
navPage.BarBackgroundColor = Color.FromArgb("#31333b");
|
||||
navPage.BarTextColor = Colors.White;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
<Style TargetType="TabbedPage" ApplyToDerivedTypes="True">
|
||||
<Setter Property="BackgroundColor" Value="White"/>
|
||||
<Setter Property="BarTextColor" Value="Black"/>
|
||||
<Setter Property="BarTextColor" Value="White"/>
|
||||
<Setter Property="SelectedTabColor" Value="White"/>
|
||||
</Style>
|
||||
|
||||
|
||||
@@ -4,18 +4,8 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="Xamarin.Neo4j.Themes.Fonts">
|
||||
|
||||
<OnPlatform x:TypeArguments="x:String" x:Key="FontAwesomeBrands">
|
||||
<On Platform="Android" Value="FontAwesome5Brands.ttf#Regular" />
|
||||
<On Platform="iOS" Value="FontAwesome5Brands-Regular" />
|
||||
</OnPlatform>
|
||||
<x:String x:Key="FontAwesomeBrands">FontAwesome5Brands-Regular</x:String>
|
||||
<x:String x:Key="FontAwesomeSolid">FontAwesome5Free-Solid</x:String>
|
||||
<x:String x:Key="FontAwesomeRegular">FontAwesome5Free-Regular</x:String>
|
||||
|
||||
<OnPlatform x:TypeArguments="x:String" x:Key="FontAwesomeSolid">
|
||||
<On Platform="Android" Value="FontAwesome5Solid.ttf#Regular" />
|
||||
<On Platform="iOS" Value="FontAwesome5Free-Solid" />
|
||||
</OnPlatform>
|
||||
|
||||
<OnPlatform x:TypeArguments="x:String" x:Key="FontAwesomeRegular">
|
||||
<On Platform="Android" Value="FontAwesome5Regular.ttf#Regular" />
|
||||
<On Platform="iOS" Value="FontAwesome5Free-Regular" />
|
||||
</OnPlatform>
|
||||
</ResourceDictionary>
|
||||
|
||||
@@ -23,6 +23,15 @@
|
||||
<Setter Property="BackgroundColor" Value="Transparent" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Entry" ApplyToDerivedTypes="True">
|
||||
<Setter Property="TextColor" Value="Black" />
|
||||
<Setter Property="PlaceholderColor" Value="#868a92" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Picker" ApplyToDerivedTypes="True">
|
||||
<Setter Property="TextColor" Value="Black" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="NavigationPage">
|
||||
<Setter Property="BarBackgroundColor" Value="{StaticResource Accent}"/>
|
||||
<Setter Property="BarTextColor" Value="White" />
|
||||
|
||||
Reference in New Issue
Block a user