diff --git a/CHANGELOG.md b/CHANGELOG.md index 55e0d9d..1b41ce3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 _No unreleased changes_ +## [2.8.1] - 2023-10-22 + +### Fixed +- Check the focus state of the target before calling focus/unfocus by @TimLariviere (https://github.com/fabulous-dev/Fabulous.MauiControls/pull/43) +- Fix crash when dispatching a message after an event occurred by @TimLariviere (https://github.com/fabulous-dev/Fabulous.MauiControls/pull/44) + ## [2.8.0] - 2023-08-08 ### Changed -- Remove ambiguity when declaring event attributes by using MsgValue instead of obj by @edgarfgp (#42) +- Remove ambiguity when declaring event attributes by using MsgValue instead of obj by @edgarfgp (https://github.com/fabulous-dev/Fabulous.MauiControls/pull/42) ## [2.7.0] - 2023-06-01 @@ -112,7 +118,8 @@ _No unreleased changes_ ### Changed - Fabulous.MauiControls has moved from the Fabulous repository to its own repository: [https://github.com/fabulous-dev/Fabulous.MauiControls](https://github.com/fabulous-dev/Fabulous.MauiControls) -[unreleased]: https://github.com/fabulous-dev/Fabulous.MauiControls/compare/2.8.0...HEAD +[unreleased]: https://github.com/fabulous-dev/Fabulous.MauiControls/compare/2.8.1...HEAD +[2.8.1]: https://github.com/fabulous-dev/Fabulous.MauiControls/releases/tag/2.8.1 [2.8.0]: https://github.com/fabulous-dev/Fabulous.MauiControls/releases/tag/2.8.0 [2.7.0]: https://github.com/fabulous-dev/Fabulous.MauiControls/releases/tag/2.7.0 [2.6.0]: https://github.com/fabulous-dev/Fabulous.MauiControls/releases/tag/2.6.0 diff --git a/samples/Playground/App.fs b/samples/Playground/App.fs index fad3c5b..5791e6b 100644 --- a/samples/Playground/App.fs +++ b/samples/Playground/App.fs @@ -1,11 +1,6 @@ namespace Playground -open Fabulous open Fabulous.Maui -open Microsoft.Maui -open Microsoft.Maui.Graphics -open Microsoft.Maui.Accessibility -open Microsoft.Maui.Primitives open type Fabulous.Maui.View diff --git a/src/Fabulous.MauiControls/Attributes.fs b/src/Fabulous.MauiControls/Attributes.fs index 91fdfa1..bd616fe 100644 --- a/src/Fabulous.MauiControls/Attributes.fs +++ b/src/Fabulous.MauiControls/Attributes.fs @@ -3,7 +3,6 @@ namespace Fabulous.Maui open System.Runtime.CompilerServices open Fabulous open Fabulous.ScalarAttributeDefinitions -open Fabulous.Maui open Microsoft.Maui.Controls open System @@ -160,7 +159,7 @@ module Attributes = // Set the new event handler let handler = EventHandler<'args>(fun _ args -> - let r = curr.Event args + let (MsgValue r) = curr.Event args Dispatcher.dispatch node r) node.SetHandler(name, ValueSome handler) diff --git a/src/Fabulous.MauiControls/Views/Controls/DatePicker.fs b/src/Fabulous.MauiControls/Views/Controls/DatePicker.fs index 2c66889..d351343 100644 --- a/src/Fabulous.MauiControls/Views/Controls/DatePicker.fs +++ b/src/Fabulous.MauiControls/Views/Controls/DatePicker.fs @@ -59,7 +59,7 @@ module DatePicker = // Set the new event handler let handler = EventHandler(fun _ args -> - let r = curr.Event args + let (MsgValue r) = curr.Event args Dispatcher.dispatch node r) node.SetHandler(name, ValueSome handler) diff --git a/src/Fabulous.MauiControls/Views/_VisualElement.fs b/src/Fabulous.MauiControls/Views/_VisualElement.fs index 020b750..6aeb516 100644 --- a/src/Fabulous.MauiControls/Views/_VisualElement.fs +++ b/src/Fabulous.MauiControls/Views/_VisualElement.fs @@ -39,10 +39,10 @@ module VisualElementUpdaters = let updateVisualElementFocus oldValueOpt (newValueOpt: ValueEventData voption) (node: IViewNode) = let target = node.Target :?> VisualElement - let onEventName = $"Focus_On" + let onEventName = "Focus_On" let onEvent = target.Focused - let offEventName = $"Focus_Off" + let offEventName = "Focus_Off" let offEvent = target.Unfocused match newValueOpt with @@ -59,7 +59,9 @@ module VisualElementUpdaters = // Only clear the property if a value was set before match oldValueOpt with | ValueNone -> () - | ValueSome _ -> target.Unfocus() + | ValueSome _ -> + if target.IsFocused then + target.Unfocus() | ValueSome curr -> // Clean up the old event handlers if any @@ -72,15 +74,16 @@ module VisualElementUpdaters = | ValueSome handler -> offEvent.RemoveHandler(handler) // Set the new value - if curr.Value then - target.Focus() |> ignore - else - target.Unfocus() + if target.IsFocused <> curr.Value then + if curr.Value then + target.Focus() |> ignore + else + target.Unfocus() // Set the new event handlers let onHandler = EventHandler(fun _ args -> - let r = curr.Event true + let (MsgValue r) = curr.Event true Dispatcher.dispatch node r) node.SetHandler(onEventName, ValueSome onHandler) @@ -88,7 +91,7 @@ module VisualElementUpdaters = let offHandler = EventHandler(fun _ args -> - let r = curr.Event false + let (MsgValue r) = curr.Event false Dispatcher.dispatch node r) node.SetHandler(offEventName, ValueSome offHandler)