From dbf03fc500997ac84e508cae6446e20a8bcdda7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9=20LARIVIERE?= Date: Thu, 30 Mar 2023 10:21:01 +0200 Subject: [PATCH] Add support for onAppLinkRequestReceived to Application widget --- CHANGELOG.md | 4 +++- src/Fabulous.MauiControls/Views/Application.fs | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d84928..0c206d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -_No unreleased changes_ + +### Added +- Add modifier `onAppLinkRequestReceived` to `Application` widget by @TimLariviere ## [2.5.0] - 2023-03-06 diff --git a/src/Fabulous.MauiControls/Views/Application.fs b/src/Fabulous.MauiControls/Views/Application.fs index 499c0eb..f26d0bb 100644 --- a/src/Fabulous.MauiControls/Views/Application.fs +++ b/src/Fabulous.MauiControls/Views/Application.fs @@ -15,6 +15,7 @@ type FabApplication() = let start = Event() let sleep = Event() let resume = Event() + let appLinkRequestReceived = Event, Uri>() [] member _.Start = start.Publish @@ -31,6 +32,12 @@ type FabApplication() = override this.OnResume() = resume.Trigger(this, EventArgs()) + [] + member _.AppLinkRequestReceived = appLinkRequestReceived.Publish + + override this.OnAppLinkRequestReceived(uri) = + appLinkRequestReceived.Trigger(this, uri) + module Application = let WidgetKey = Widgets.register() @@ -62,6 +69,9 @@ module Application = let Start = Attributes.defineEventNoArg "Application_Start" (fun target -> (target :?> FabApplication).Start) + let AppLinkRequestReceived = + Attributes.defineEvent "Application_AppLinkRequestReceived" (fun target -> (target :?> FabApplication).AppLinkRequestReceived) + let UserAppTheme = Attributes.defineEnum "Application_UserAppTheme" (fun _ newValueOpt node -> let application = node.Target :?> Application @@ -140,6 +150,13 @@ type ApplicationModifiers = static member inline onRequestedThemeChanged(this: WidgetBuilder<'msg, #IFabApplication>, fn: AppTheme -> 'msg) = this.AddScalar(Application.RequestedThemeChanged.WithValue(fun args -> fn args.RequestedTheme |> box)) + /// Listen for the AppLinkRequestReceived event + /// Current widget + /// Message to dispatch + [] + static member inline onAppLinkRequestReceived(this: WidgetBuilder<'msg, #IFabApplication>, fn: Uri -> 'msg) = + this.AddScalar(Application.AppLinkRequestReceived.WithValue(fun args -> fn args |> box)) + /// Set the user app theme /// Current widget /// The user app theme