Skip to content

Commit

Permalink
Merge branch 'main' into release/2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Oct 22, 2023
2 parents 6880d77 + 078708d commit 9b8d0b6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions samples/Playground/App.fs
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/Fabulous.MauiControls/Attributes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Fabulous.MauiControls/Views/Controls/DatePicker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module DatePicker =
// Set the new event handler
let handler =
EventHandler<DateChangedEventArgs>(fun _ args ->
let r = curr.Event args
let (MsgValue r) = curr.Event args
Dispatcher.dispatch node r)

node.SetHandler(name, ValueSome handler)
Expand Down
21 changes: 12 additions & 9 deletions src/Fabulous.MauiControls/Views/_VisualElement.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ module VisualElementUpdaters =
let updateVisualElementFocus oldValueOpt (newValueOpt: ValueEventData<bool, bool> 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
Expand All @@ -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
Expand All @@ -72,23 +74,24 @@ 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<FocusEventArgs>(fun _ args ->
let r = curr.Event true
let (MsgValue r) = curr.Event true
Dispatcher.dispatch node r)

node.SetHandler(onEventName, ValueSome onHandler)
onEvent.AddHandler(onHandler)

let offHandler =
EventHandler<FocusEventArgs>(fun _ args ->
let r = curr.Event false
let (MsgValue r) = curr.Event false
Dispatcher.dispatch node r)

node.SetHandler(offEventName, ValueSome offHandler)
Expand Down

0 comments on commit 9b8d0b6

Please sign in to comment.