Fabulous
Fabulous copied to clipboard
AppLinkEntry Support
Implementation of #960
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")
@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
Maybe you can add a AppLinks collection to CustomApplication to be able to use widget collection?
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)