Skip to content
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

AppLinkEntry Support #963

Closed
wants to merge 10 commits into from
Closed

AppLinkEntry Support #963

wants to merge 10 commits into from

Conversation

edgarfgp
Copy link
Member

@edgarfgp edgarfgp commented Jun 24, 2022

Implementation of fabulous-dev/Fabulous.XamarinForms#21

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

  • Create a Fabulous CustomApplication so we can override the relevant method and expose a Event so we can add a method extension.
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)
  • Adds and extension method fore the event :
let LinkRequestReceived =
Attributes.defineEvent<LinkRequestReceivedEventArgs>
    "Application_LinkRequestReceived"
    (fun target -> (target :?> CustomApplication).LinkRequestReceived)

[<Extension>]
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 :
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

  • Use ViewRef to to get access to the Register and DeRegister methods
let applicationRef = ViewRef<Application>()
let createLink =
     let pageLink = new Xamarin.Forms.AppLinkEntry()
     pageLink.Title <- "Im a deep link"
     pageLink.Description <- "Counter App"
     pageLink.AppLinkUri <- Uri("https://www.xamarin.com/platform")
     pageLink.IsLinkActive <- true

     pageLink.KeyValues.Add("contentType", "TodoItemPage");
     pageLink.KeyValues.Add("appName", "");
     pageLink.KeyValues.Add("companyName", "Xamarin");

     pageLink

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

@edgarfgp
Copy link
Member Author

@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
Copy link
Member

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

@TimLariviere
Copy link
Member

TimLariviere commented Jun 24, 2022

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)

@edgarfgp edgarfgp changed the title Draft AppLinkEntry Support AppLinkEntry Support Jul 12, 2022
@edgarfgp edgarfgp marked this pull request as ready for review July 12, 2022 07:40
@edgarfgp edgarfgp closed this by deleting the head repository Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants