fabulous-dev / Fabulous

Declarative UI framework for cross-platform mobile & desktop apps, using MVU and F# functional programming
https://fabulous.dev
Apache License 2.0
1.13k stars 122 forks source link

AppLinkEntry Support #963

Closed edgarfgp closed 1 year ago

edgarfgp commented 2 years ago

Implementation of fabulous-dev/Fabulous.XamarinForms#21

In order to support Deep linking a Indexing we need to:

type CustomApplication() =
    inherit Application()

    let linkRequestReceived = Event<EventHandler<LinkRequestReceivedEventArgs>, _>()

    [<CLIEvent>]
    member _.LinkRequestReceived = linkRequestReceived.Publish

    override this.OnAppLinkRequestReceived(uri : Uri)=
        linkRequestReceived.Trigger(this, LinkRequestReceivedEventArgs(uri))
        base.OnAppLinkRequestReceived(uri)

[] static member inline onLinkReceived(this: WidgetBuilder<'msg, #IApplication>, fn: LinkRequestReceivedEventArgs -> 'msg) = this.AddScalar(Application.LinkRequestReceived.WithValue(fn >> box))


## Limitation

- The initial idea was to have a DSL like : 
```fsharp
Application(...)
    .onAppLinkReceived(NavigateDeepInAppMsg)
        .appLinks {
            AppLink(...)
            AppLink(...)
        }

BUT AppLinks is not a List of AppLink is just and Intercase AppLinks . So can not use a widget collection.

Workaround

match applicationRef.TryValue with | Some target -> target.AppLinks.RegisterLink(createLink) | None -> failwith "No application ref")

edgarfgp commented 2 years ago

@twop After some investigation this how the feature could be implemented. and detailed some of the limitation . Not sure if there is a way to fix the limitation I found. @TimLariviere and yourself know the internals better that I do . So any feedback is appreciated

TimLariviere commented 2 years ago

Maybe you can add a AppLinks collection to CustomApplication to be able to use widget collection?

TimLariviere commented 2 years ago

Hmm, actually you can do it without adding a new property to CustomApplication. You can create a fake "AppLinks" collection attribute that would direct update Application.AppLinks.Register/Deregister (see NavigationPage.Pages for example)