-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First draft for component support #49
Merged
Merged
Conversation
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
edgarfgp
reviewed
Nov 20, 2023
Changed the ergonomics to be more in line with the current DSL: type Fabulous.Maui.View with
static member inline SimpleComponent() =
Component() {
Label("Hello Component")
.centerHorizontal()
}
static member inline Counter() =
Component() {
let! count = state 0
VStack() {
Label($"Count is {count.Current}")
.centerHorizontal()
Button'("Increment", fun () -> count.Set(count.Current + 1))
Button'("Decrement", fun () -> count.Set(count.Current - 1))
}
}
static member inline ParentChild_Child(count: int) =
Component() {
let! multiplier = state 1
let countMultiplied = count * multiplier.Current
VStack() {
Label($"Count * {multiplier.Current} = {countMultiplied}")
.centerHorizontal()
Button'("Increment Multiplier", fun () -> multiplier.Set(multiplier.Current + 1))
Button'("Decrement Multiplier", fun () -> multiplier.Set(multiplier.Current - 1))
}
}
static member inline ParentChild_Parent() =
Component() {
let! count = state 0
VStack() {
Label($"Count is {count.Current}")
.centerHorizontal()
Button'("Increment Count", fun () -> count.Set(count.Current + 1))
Button'("Decrement Count", fun () -> count.Set(count.Current - 1))
View.ParentChild_Child(count.Current)
}
}
static member inline Child(count: BindingRequest<'T>) =
Component() {
let! boundCount = count
VStack() {
Label($"Child.Count is {boundCount.Current}")
.centerHorizontal()
Button'("Increment", fun () -> boundCount.Set(boundCount.Current + 1))
Button'("Decrement", fun () -> boundCount.Set(boundCount.Current - 1))
}
}
static member inline BindingBetweenParentAndChild() =
Component() {
let! count = state 0
VStack() {
Label($"Parent.Count is {count.Current}")
.centerHorizontal()
Button'("Increment", fun () -> count.Set(count.Current + 1))
Button'("Decrement", fun () -> count.Set(count.Current - 1))
View.Child(ofState count)
}
}
static member inline SharedContextBetweenComponents() =
Component() {
let sharedContext = ComponentContext()
VStack() {
View.Counter()
.withContext(sharedContext)
View.Counter()
.withContext(sharedContext)
}
} |
@edgarfgp btw I managed to remove the need for the intermediate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Details here: https://github.com/fabulous-dev/FabPlaygroundCE/blob/main/FabPlaygroundCE/Playground.fs
Simple stateful component
comp.mov
Parent-child communication
compchild.mov