From c22454b7dd1bddec2732c31ad0fd74d40c5741da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9=20Larivi=C3=A8re?= Date: Fri, 1 Dec 2023 08:46:10 +0100 Subject: [PATCH] . --- samples/Components/HelloComponent/App.fs | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/samples/Components/HelloComponent/App.fs b/samples/Components/HelloComponent/App.fs index d1e6801..043418e 100644 --- a/samples/Components/HelloComponent/App.fs +++ b/samples/Components/HelloComponent/App.fs @@ -6,8 +6,31 @@ open Microsoft.Maui.ApplicationModel open Microsoft.Maui.Hosting open type Fabulous.Maui.View +[] +module AppEnvironmentKeys = + let CountKey = EnvironmentKey("Count", 0) + type EnvironmentKeys with + static member Count = CountKey + +open type Fabulous.Maui.EnvironmentKeys + module App = - let Count = EnvironmentKey("Count", 0) + let themeViewer() = + Component() { + let! theme = Environment(Theme) + + VStack() { + Label($"[themeViewer] Current theme is %A{theme.Current}") + Button("[themeViewer] Toggle theme", fun () -> + theme.Set( + if theme.Current = AppTheme.Light then + AppTheme.Dark + else + AppTheme.Light + ) + ) + } + } let subCountViewer() = Component() { @@ -61,15 +84,18 @@ module App = let view() = (Component() { let! count = Environment(Count) + let! theme = Environment(Theme) Application() { ContentPage() { VStack() { + Label($"[view] Current theme is %A{theme.Current}") Label($"[view] Count = {count.Current}") Button("[view] Increment", fun () -> count.Set(count.Current + 1)) Button("[view] Decrement", fun () -> count.Set(count.Current - 1)) count'() subCount() + themeViewer() } } }