Skip to content
This repository has been archived by the owner on Apr 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #14 from edgarfgp/Add-NavigationPage-Extensions
Browse files Browse the repository at this point in the history
Add more NavigationPage extension
  • Loading branch information
TimLariviere committed Nov 29, 2021
2 parents 7fb08aa + df717e5 commit 4797fba
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 44 deletions.
89 changes: 46 additions & 43 deletions samples/Xamarin.Forms/CounterApp/CounterApp/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,52 +58,55 @@ module App =

let view model =
Application(
ContentPage("Counter",
VerticalStackLayout([
Label(string model.Count)
.automationId("CountLabel")
.centerTextHorizontal()
.style (
createStyleFor [ Label.TextColorProperty, box Color.Green
Label.FontSizeProperty, box 24. ]
)

Button("Increment", Increment)
.style(
createStyleFor [ Button.BackgroundColorProperty, box Color.Green
Button.TextColorProperty, box Color.White ]
NavigationPage([
ContentPage("Counter",
VerticalStackLayout([
Label(string model.Count)
.automationId("CountLabel")
.centerTextHorizontal()
.style (
createStyleFor [ Label.TextColorProperty, box Color.Green
Label.FontSizeProperty, box 24. ]
)
.automationId("IncrementButton")

Button("Decrement", Decrement)
.automationId("DecrementButton")
.alignStartVertical(expand = true)

HorizontalStackLayout([
Label("Timer")

Switch(model.TimerOn, TimerToggled)
.automationId("TimerSwitch")
Button("Increment", Increment)
.style(
createStyleFor [ Button.BackgroundColorProperty, box Color.Green
Button.TextColorProperty, box Color.White ]
)
.automationId("IncrementButton")

Button("Decrement", Decrement)
.automationId("DecrementButton")
.alignStartVertical(expand = true)

HorizontalStackLayout([
Label("Timer")

Switch(model.TimerOn, TimerToggled)
.automationId("TimerSwitch")
])
.paddingLayout(20.)
.centerHorizontal()

Slider(min = 0., max = 10., value = float model.Step, onValueChanged = StepChanged)
.automationId("StepSlider")
.centerHorizontal()

Label($"Step size: {model.Step}")
.automationId("StepSizeLabel")
.centerHorizontal()

Button("Reset", Reset)
.automationId("ResetButton")
.isEnabled(model <> initModel ())
.centerHorizontal()
])
.paddingLayout(20.)
.centerHorizontal()

Slider(min = 0., max = 10., value = float model.Step, onValueChanged = StepChanged)
.automationId("StepSlider")
.centerHorizontal()

Label($"Step size: {model.Step}")
.automationId("StepSizeLabel")
.centerHorizontal()

Button("Reset", Reset)
.automationId("ResetButton")
.isEnabled(model <> initModel ())
.centerHorizontal()
])
.paddingLayout(30.)
.centerVertical()
)
.paddingLayout(30.)
.centerVertical()
).hasNavigationBar(false)
])

)

let program = Program.statefulApplicationWithCmdMsg init update view mapCmdMsgToCmd
2 changes: 2 additions & 0 deletions src/Fabulous.XamarinForms/Xamarin.Forms.Core.Attributes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ module NavigationPage =
let Pages = Attributes.defineWidgetCollectionWithConverter "NavigationPage_Pages" ViewUpdaters.applyDiffNavigationPagePages ViewUpdaters.updateNavigationPagePages
let BarBackgroundColor = Attributes.defineBindable<Color> Xamarin.Forms.NavigationPage.BarBackgroundColorProperty
let BarTextColor = Attributes.defineBindable<Color> Xamarin.Forms.NavigationPage.BarTextColorProperty
let HasNavigationBar = Attributes.defineBindable<bool> Xamarin.Forms.NavigationPage.HasNavigationBarProperty
let HasBackButton = Attributes.defineBindable<bool> Xamarin.Forms.NavigationPage.HasBackButtonProperty
let Popped = Attributes.defineEvent<NavigationEventArgs> ViewNode.getViewNode "NavigationPage_Popped" (fun target -> (target :?> Xamarin.Forms.NavigationPage).Popped)

module Entry =
Expand Down
9 changes: 8 additions & 1 deletion src/Fabulous.XamarinForms/Xamarin.Forms.Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,14 @@ type ViewExtensions () =
static member inline popped(this: NavigationPage<'msg>, value: 'msg) =
this.AddScalarAttribute(NavigationPage.Popped.WithValue(fun _ -> box value))

[<Extension>]
static member inline hasNavigationBar(this: #IPageWidgetBuilder<'msg>, value: bool) =
this.AddScalarAttribute(NavigationPage.HasNavigationBar.WithValue(value))

[<Extension>]
static member inline hasBackButton(this: #IPageWidgetBuilder<'msg>, value: bool) =
this.AddScalarAttribute(NavigationPage.HasBackButton.WithValue(value))

[<AbstractClass; Sealed>]
type View private () =
static member inline Application<'msg>(mainPage) = Application<'msg>.Create(mainPage)
Expand Down Expand Up @@ -603,4 +611,3 @@ type View private () =
static member inline ViewCell<'msg>(view) = ViewCell<'msg>.Create(view)
static member inline ImageButton<'msg>(path: string, onClicked, aspect) = ImageButton<'msg>.Create(path, onClicked, aspect)
static member inline TabbedPage<'msg>(title, children) = TabbedPage<'msg>.Create(title, children)

0 comments on commit 4797fba

Please sign in to comment.