Skip to content

Commit

Permalink
Merge pull request #5 from fabulous-dev/fix-maui-interfaces-name-conf…
Browse files Browse the repository at this point in the history
…litcs

Fix Interface naming conflicts
  • Loading branch information
TimLariviere authored Jan 18, 2023
2 parents c42d2b0 + db97dc6 commit 24f35ca
Show file tree
Hide file tree
Showing 114 changed files with 897 additions and 977 deletions.
8 changes: 2 additions & 6 deletions src/Fabulous.MauiControls/AppHostBuilderExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@

open Fabulous
open System.Runtime.CompilerServices
open Microsoft.Maui.Controls
open Microsoft.Maui.Handlers
open Microsoft.Maui.Hosting
open Microsoft.Maui.Controls.Hosting
open Microsoft.Maui.Controls.Compatibility.Hosting
open Microsoft.Extensions.DependencyInjection.Extensions
open System

[<Extension>]
type AppHostBuilderExtensions =
[<Extension>]
static member UseFabulousApp<'model, 'msg, 'marker when 'marker :> Fabulous.Maui.IApplication>
static member UseFabulousApp<'model, 'msg, 'marker when 'marker :> IFabApplication>
(
this: MauiAppBuilder,
program: Program<unit, 'model, 'msg, 'marker>
) : MauiAppBuilder =
this.UseMauiApp(fun (_serviceProvider: IServiceProvider) -> (Program.startApplication program) :> Microsoft.Maui.IApplication)

[<Extension>]
static member UseFabulousApp<'arg, 'model, 'msg, 'marker when 'marker :> Fabulous.Maui.IApplication>
static member UseFabulousApp<'arg, 'model, 'msg, 'marker when 'marker :> IFabApplication>
(
this: MauiAppBuilder,
program: Program<'arg, 'model, 'msg, 'marker>,
Expand Down
88 changes: 44 additions & 44 deletions src/Fabulous.MauiControls/CollectionBuilderExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,178 +7,178 @@ open Fabulous.StackAllocatedCollections
[<Extension>]
type CollectionBuilderExtensions =
[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IPage>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabPage>
(
_: CollectionBuilder<'msg, 'marker, IPage>,
_: CollectionBuilder<'msg, 'marker, IFabPage>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IView>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabView>
(
_: CollectionBuilder<'msg, 'marker, IView>,
_: CollectionBuilder<'msg, 'marker, IFabView>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> ISpan>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabSpan>
(
_: CollectionBuilder<'msg, 'marker, ISpan>,
_: CollectionBuilder<'msg, 'marker, IFabSpan>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IGeometry>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabGeometry>
(
_: CollectionBuilder<'msg, 'marker, IGeometry>,
_: CollectionBuilder<'msg, 'marker, IFabGeometry>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IGradientStop>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabGradientStop>
(
_: CollectionBuilder<'msg, 'marker, IGradientStop>,
_: CollectionBuilder<'msg, 'marker, IFabGradientStop>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IPathFigure>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabPathFigure>
(
_: CollectionBuilder<'msg, 'marker, IPathFigure>,
_: CollectionBuilder<'msg, 'marker, IFabPathFigure>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IPathSegment>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabPathSegment>
(
_: CollectionBuilder<'msg, 'marker, IPathSegment>,
_: CollectionBuilder<'msg, 'marker, IFabPathSegment>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> ITransform>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabTransform>
(
_: CollectionBuilder<'msg, 'marker, ITransform>,
_: CollectionBuilder<'msg, 'marker, IFabTransform>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> ISwipeItem>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabSwipeItem>
(
_: CollectionBuilder<'msg, 'marker, ISwipeItem>,
_: CollectionBuilder<'msg, 'marker, IFabSwipeItem>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IGestureRecognizer>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabGestureRecognizer>
(
_: AttributeCollectionBuilder<'msg, 'marker, IGestureRecognizer>,
_: AttributeCollectionBuilder<'msg, 'marker, IFabGestureRecognizer>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IToolbarItem>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabToolbarItem>
(
_: AttributeCollectionBuilder<'msg, 'marker, IToolbarItem>,
_: AttributeCollectionBuilder<'msg, 'marker, IFabToolbarItem>,
x: WidgetBuilder<'msg, 'itemType>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }


[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IPage>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabPage>
(
_: CollectionBuilder<'msg, 'marker, IPage>,
_: CollectionBuilder<'msg, 'marker, IFabPage>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IView>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabView>
(
_: CollectionBuilder<'msg, 'marker, IView>,
_: CollectionBuilder<'msg, 'marker, IFabView>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> ISpan>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabSpan>
(
_: CollectionBuilder<'msg, 'marker, ISpan>,
_: CollectionBuilder<'msg, 'marker, IFabSpan>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IGeometry>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabGeometry>
(
_: CollectionBuilder<'msg, 'marker, IGeometry>,
_: CollectionBuilder<'msg, 'marker, IFabGeometry>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IBrush>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabBrush>
(
_: CollectionBuilder<'msg, 'marker, IGradientStop>,
_: CollectionBuilder<'msg, 'marker, IFabGradientStop>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IPathFigure>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabPathFigure>
(
_: CollectionBuilder<'msg, 'marker, IPathFigure>,
_: CollectionBuilder<'msg, 'marker, IFabPathFigure>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IPathSegment>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabPathSegment>
(
_: CollectionBuilder<'msg, 'marker, IPathSegment>,
_: CollectionBuilder<'msg, 'marker, IFabPathSegment>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> ITransform>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabTransform>
(
_: CollectionBuilder<'msg, 'marker, ITransform>,
_: CollectionBuilder<'msg, 'marker, IFabTransform>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> ISwipeItem>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabSwipeItem>
(
_: CollectionBuilder<'msg, 'marker, ISwipeItem>,
_: CollectionBuilder<'msg, 'marker, IFabSwipeItem>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IGestureRecognizer>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabGestureRecognizer>
(
_: AttributeCollectionBuilder<'msg, 'marker, IGestureRecognizer>,
_: AttributeCollectionBuilder<'msg, 'marker, IFabGestureRecognizer>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }

[<Extension>]
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IToolbarItem>
static member inline Yield<'msg, 'marker, 'itemType when 'itemType :> IFabToolbarItem>
(
_: AttributeCollectionBuilder<'msg, 'marker, IToolbarItem>,
_: AttributeCollectionBuilder<'msg, 'marker, IFabToolbarItem>,
x: WidgetBuilder<'msg, Memo.Memoized<'itemType>>
) : Content<'msg> =
{ Widgets = MutStackArray1.One(x.Compile()) }
8 changes: 3 additions & 5 deletions src/Fabulous.MauiControls/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
open Fabulous
open Fabulous.ScalarAttributeDefinitions
open Fabulous.WidgetCollectionAttributeDefinitions
open Microsoft.Maui
open Microsoft.Maui.ApplicationModel
open Microsoft.Maui.Controls
open System
Expand Down Expand Up @@ -117,7 +116,7 @@ module Program =
let statefulWithCmd
(init: 'arg -> 'model * Cmd<'msg>)
(update: 'msg -> 'model -> 'model * Cmd<'msg>)
(view: 'model -> WidgetBuilder<'msg, #Fabulous.Maui.IApplication>)
(view: 'model -> WidgetBuilder<'msg, #IFabApplication>)
=
define init update view

Expand All @@ -133,15 +132,14 @@ module Program =
define (fun arg -> let m, c = init arg in m, mapCmds c) (fun msg model -> let m, c = update msg model in m, mapCmds c) view

/// Start the program
let startApplicationWithArgs (arg: 'arg) (program: Program<'arg, 'model, 'msg, #Fabulous.Maui.IApplication>) : Microsoft.Maui.Controls.Application =
let startApplicationWithArgs (arg: 'arg) (program: Program<'arg, 'model, 'msg, #IFabApplication>) : Application =
let runner = Runners.create program
runner.Start(arg)
let adapter = ViewAdapters.create ViewNode.get runner
adapter.CreateView() |> unbox

/// Start the program
let startApplication (program: Program<unit, 'model, 'msg, #Fabulous.Maui.IApplication>) : Microsoft.Maui.Controls.Application =
startApplicationWithArgs () program
let startApplication (program: Program<unit, 'model, 'msg, #IFabApplication>) : Application = startApplicationWithArgs () program

/// Subscribe to external source of events.
/// The subscription is called once - with the initial model, but can dispatch new messages at any time.
Expand Down
12 changes: 6 additions & 6 deletions src/Fabulous.MauiControls/Views/Any.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ module AnyBuilders =
type Fabulous.Maui.View with

/// Downcast to IView to allow to return different types of views in a single expression (e.g. if/else, match with pattern, etc.)
static member AnyView<'msg, 'marker when 'marker :> Fabulous.Maui.IView>(widget: WidgetBuilder<'msg, 'marker>) =
WidgetBuilder<'msg, IView>(widget.Key, widget.Attributes)
static member AnyView<'msg, 'marker when 'marker :> IFabView>(widget: WidgetBuilder<'msg, 'marker>) =
WidgetBuilder<'msg, IFabView>(widget.Key, widget.Attributes)

/// Downcast to IPage to allow to return different types of pages in a single expression (e.g. if/else, match with pattern, etc.)
static member AnyPage<'msg, 'marker when 'marker :> Fabulous.Maui.IPage>(widget: WidgetBuilder<'msg, 'marker>) =
WidgetBuilder<'msg, IPage>(widget.Key, widget.Attributes)
static member AnyPage<'msg, 'marker when 'marker :> IFabPage>(widget: WidgetBuilder<'msg, 'marker>) =
WidgetBuilder<'msg, IFabPage>(widget.Key, widget.Attributes)

/// Downcast to ICell to allow to return different types of cells in a single expression (e.g. if/else, match with pattern, etc.)
static member AnyCell<'msg, 'marker when 'marker :> Fabulous.Maui.ICell>(widget: WidgetBuilder<'msg, 'marker>) =
WidgetBuilder<'msg, ICell>(widget.Key, widget.Attributes)
static member AnyCell<'msg, 'marker when 'marker :> IFabCell>(widget: WidgetBuilder<'msg, 'marker>) =
WidgetBuilder<'msg, IFabCell>(widget.Key, widget.Attributes)
31 changes: 15 additions & 16 deletions src/Fabulous.MauiControls/Views/Application.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

open System.Runtime.CompilerServices
open Fabulous
open Microsoft.Maui
open Microsoft.Maui.Controls
open Microsoft.Maui.ApplicationModel

type IApplication =
inherit Fabulous.Maui.IElement
type IFabApplication =
inherit IFabElement

module Application =
let WidgetKey = Widgets.register<CustomApplication>()
Expand Down Expand Up @@ -68,55 +67,55 @@ module Application =
module ApplicationBuilders =
type Fabulous.Maui.View with

static member inline Application<'msg, 'marker when 'marker :> IPage>(mainPage: WidgetBuilder<'msg, 'marker>) =
WidgetHelpers.buildWidgets<'msg, IApplication> Application.WidgetKey [| Application.MainPage.WithValue(mainPage.Compile()) |]
static member inline Application<'msg, 'marker when 'marker :> IFabPage>(mainPage: WidgetBuilder<'msg, 'marker>) =
WidgetHelpers.buildWidgets<'msg, IFabApplication> Application.WidgetKey [| Application.MainPage.WithValue(mainPage.Compile()) |]

[<Extension>]
type ApplicationModifiers =
[<Extension>]
static member inline userAppTheme(this: WidgetBuilder<'msg, #IApplication>, value: AppTheme) =
static member inline userAppTheme(this: WidgetBuilder<'msg, #IFabApplication>, value: AppTheme) =
this.AddScalar(Application.UserAppTheme.WithValue(value))

[<Extension>]
static member inline resources(this: WidgetBuilder<'msg, #IApplication>, value: ResourceDictionary) =
static member inline resources(this: WidgetBuilder<'msg, #IFabApplication>, value: ResourceDictionary) =
this.AddScalar(Application.Resources.WithValue(value))

[<Extension>]
static member inline onRequestedThemeChanged(this: WidgetBuilder<'msg, #IApplication>, onRequestedThemeChanged: AppTheme -> 'msg) =
static member inline onRequestedThemeChanged(this: WidgetBuilder<'msg, #IFabApplication>, onRequestedThemeChanged: AppTheme -> 'msg) =
this.AddScalar(Application.RequestedThemeChanged.WithValue(fun args -> onRequestedThemeChanged args.RequestedTheme |> box))

[<Extension>]
static member inline onModalPopped(this: WidgetBuilder<'msg, #IApplication>, onModalPopped: ModalPoppedEventArgs -> 'msg) =
static member inline onModalPopped(this: WidgetBuilder<'msg, #IFabApplication>, onModalPopped: ModalPoppedEventArgs -> 'msg) =
this.AddScalar(Application.ModalPopped.WithValue(onModalPopped >> box))

[<Extension>]
static member inline onModalPopping(this: WidgetBuilder<'msg, #IApplication>, onModalPopping: ModalPoppingEventArgs -> 'msg) =
static member inline onModalPopping(this: WidgetBuilder<'msg, #IFabApplication>, onModalPopping: ModalPoppingEventArgs -> 'msg) =
this.AddScalar(Application.ModalPopping.WithValue(onModalPopping >> box))

[<Extension>]
static member inline onModalPushed(this: WidgetBuilder<'msg, #IApplication>, onModalPushed: ModalPushedEventArgs -> 'msg) =
static member inline onModalPushed(this: WidgetBuilder<'msg, #IFabApplication>, onModalPushed: ModalPushedEventArgs -> 'msg) =
this.AddScalar(Application.ModalPushed.WithValue(onModalPushed >> box))

[<Extension>]
static member inline onModalPushing(this: WidgetBuilder<'msg, #IApplication>, onModalPushing: ModalPushingEventArgs -> 'msg) =
static member inline onModalPushing(this: WidgetBuilder<'msg, #IFabApplication>, onModalPushing: ModalPushingEventArgs -> 'msg) =
this.AddScalar(Application.ModalPushing.WithValue(onModalPushing >> box))

/// Dispatch a message when the application starts
[<Extension>]
static member inline onStart(this: WidgetBuilder<'msg, #IApplication>, onStart: 'msg) =
static member inline onStart(this: WidgetBuilder<'msg, #IFabApplication>, onStart: 'msg) =
this.AddScalar(Application.Start.WithValue(onStart))

/// Dispatch a message when the application is paused by the OS
[<Extension>]
static member inline onSleep(this: WidgetBuilder<'msg, #IApplication>, onSleep: 'msg) =
static member inline onSleep(this: WidgetBuilder<'msg, #IFabApplication>, onSleep: 'msg) =
this.AddScalar(Application.Sleep.WithValue(onSleep))

/// Dispatch a message when the application is resumed by the OS
[<Extension>]
static member inline onResume(this: WidgetBuilder<'msg, #IApplication>, onResume: 'msg) =
static member inline onResume(this: WidgetBuilder<'msg, #IFabApplication>, onResume: 'msg) =
this.AddScalar(Application.Resume.WithValue(onResume))

/// Link a ViewRef to access the direct Application instance
[<Extension>]
static member inline reference(this: WidgetBuilder<'msg, IApplication>, value: ViewRef<Application>) =
static member inline reference(this: WidgetBuilder<'msg, IFabApplication>, value: ViewRef<Application>) =
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox))
Loading

0 comments on commit 24f35ca

Please sign in to comment.