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

Add support for onAppLinkRequestReceived to Application widget #34

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions src/Fabulous.MauiControls/Views/Application.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type FabApplication() =
let start = Event<EventHandler, EventArgs>()
let sleep = Event<EventHandler, EventArgs>()
let resume = Event<EventHandler, EventArgs>()
let appLinkRequestReceived = Event<EventHandler<Uri>, Uri>()

[<CLIEvent>]
member _.Start = start.Publish
Expand All @@ -31,6 +32,12 @@ type FabApplication() =

override this.OnResume() = resume.Trigger(this, EventArgs())

[<CLIEvent>]
member _.AppLinkRequestReceived = appLinkRequestReceived.Publish

override this.OnAppLinkRequestReceived(uri) =
appLinkRequestReceived.Trigger(this, uri)

module Application =
let WidgetKey = Widgets.register<FabApplication>()

Expand Down Expand Up @@ -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<AppTheme> "Application_UserAppTheme" (fun _ newValueOpt node ->
let application = node.Target :?> Application
Expand Down Expand Up @@ -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))

/// <summary>Listen for the AppLinkRequestReceived event</summary>
/// <param name="this">Current widget</param>
/// <param name="fn">Message to dispatch</param>
[<Extension>]
static member inline onAppLinkRequestReceived(this: WidgetBuilder<'msg, #IFabApplication>, fn: Uri -> 'msg) =
this.AddScalar(Application.AppLinkRequestReceived.WithValue(fun args -> fn args |> box))

/// <summary>Set the user app theme</summary>
/// <param name="this">Current widget</param>
/// <param name="value">The user app theme</param>
Expand Down