Skip to content

Commit

Permalink
Merge pull request #44 from fabulous-dev/fix-crash-events
Browse files Browse the repository at this point in the history
Fix crash events
  • Loading branch information
TimLariviere authored Oct 22, 2023
2 parents 6084b91 + 462e23e commit 9a68d55
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### 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

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
13 changes: 7 additions & 6 deletions src/Fabulous.MauiControls/Views/_VisualElement.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,24 @@ module VisualElementUpdaters =
| ValueSome handler -> offEvent.RemoveHandler(handler)

// Set the new value
if curr.Value && target.IsFocused <> 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 9a68d55

Please sign in to comment.