-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Fabulous 3.0.0-pre16 and remove SingleChild builders
- Loading branch information
1 parent
f5592cf
commit 24cb8da
Showing
26 changed files
with
155 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,82 @@ | ||
namespace HelloComponent | ||
|
||
open System | ||
open Fabulous | ||
open Fabulous.Maui | ||
open Microsoft.Maui.Hosting | ||
|
||
open type Fabulous.Maui.View | ||
open type Fabulous.Context | ||
|
||
open Microsoft.Maui.Storage | ||
|
||
type Settings() = | ||
inherit EnvironmentObject() | ||
|
||
let mutable usePaidMode = Preferences.Default.Get("UsePaidMode", false) | ||
|
||
member this.UsePaidMode | ||
with get () = usePaidMode | ||
and set v = | ||
usePaidMode <- v | ||
Preferences.Default.Set("UsePaidMode", v) | ||
this.NotifyChanged() | ||
|
||
module EnvironmentKeys = | ||
|
||
let Settings = EnvironmentKey<Settings>("Settings") | ||
|
||
module Child = | ||
let view name () = | ||
Component(name) { | ||
let! settings = Context.EnvironmentObject(EnvironmentKeys.Settings) | ||
|
||
VStack() { | ||
Label($"Paid mode = {settings.UsePaidMode}") | ||
Button("Toggle paid mode", fun () -> settings.UsePaidMode <- not settings.UsePaidMode) | ||
} | ||
} | ||
|
||
module MvuChild = | ||
type Model = { Settings: Settings } | ||
|
||
type Msg = | TogglePaidMode | ||
|
||
let init (settings: Settings) = { Settings = settings }, Cmd.none | ||
|
||
let update msg model = | ||
match msg with | ||
| TogglePaidMode -> model, Cmd.ofEffect(fun _ -> model.Settings.UsePaidMode <- not model.Settings.UsePaidMode) | ||
|
||
let program = Program.statefulWithCmd init update | ||
|
||
let view name () = | ||
Component(name) { | ||
let! settings = EnvironmentObject(EnvironmentKeys.Settings) | ||
let! _ = Mvu(program, settings) | ||
|
||
VStack() { | ||
Label($"Paid mode = {settings.UsePaidMode}") | ||
Button("Toggle paid mode", TogglePaidMode) | ||
} | ||
} | ||
|
||
module App = | ||
let view () = | ||
Component("root") { Application() { Window() { ContentPage() { (VStack() { Label("Hello Component").centerTextHorizontal() }).centerVertical() } } } } | ||
Component("root") { | ||
(Application() { | ||
Window( | ||
ContentPage( | ||
(VStack() { | ||
Child.view "1" () | ||
Child.view "2" () | ||
}) | ||
.center() | ||
) | ||
) | ||
}) | ||
.environment(EnvironmentKeys.Settings, new Settings()) | ||
} | ||
|
||
let createMauiApp () = | ||
MauiApp.CreateBuilder().UseFabulousApp(view).Build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.