adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
588 stars 49 forks source link

Reacting to Light and Dark theme #155

Closed AswinPG closed 1 year ago

AswinPG commented 1 year ago

What would be the best way to use Appthemebinding in MauiReactor

adospace commented 1 year ago

The calculator sample app show a possible implementation: https://github.com/adospace/reactorui-maui/blob/main/samples/Calculator/Pages/MainPage.cs

protected override void OnMounted()
{
    if (MauiControls.Application.Current != null)
    {
        MauiControls.Application.Current.RequestedThemeChanged += (sender, args) => Invalidate();
    }

    base.OnMounted();
}

also the ChateoApp:

https://github.com/adospace/mauireactor-samples/blob/main/ChateoApp/Chateo/Pages/SettingsPage.cs

essentially, you should create a class that returns your brushes/colors/etc based on the current Theme, attach it to the RequestedThemeChanged event on the OnMounted of the root component (page), and invalidate it.

adospace commented 1 year ago

BTW if you attach RequestedThemeChanged in a component that is not the root be aware to detach it in the Unmount() override

AswinPG commented 1 year ago

Wow that was fast! Thanks.

adospace commented 1 year ago

if you use XAML styles, take a look at the WeatherTwentyOne https://github.com/adospace/reactorui-maui/tree/main/samples/MauiReactor.WeatherTwentyOne