Skip to content

Commit

Permalink
Add fix for ImageButton
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Corsaro committed Dec 17, 2024
1 parent 42b33a3 commit c70b64a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Core/src/Handlers/ImageButton/ImageButtonHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public partial class ImageButtonHandler : ViewHandler<IImageButton, Button>

PointerEventHandler? _pointerPressedHandler;
PointerEventHandler? _pointerReleasedHandler;
bool _isPressed;

protected override Button CreatePlatformView()
{
Expand Down Expand Up @@ -44,6 +45,7 @@ protected override void ConnectHandler(Button platformView)
}

platformView.Click += OnClick;
platformView.Unloaded += OnUnloaded;
platformView.AddHandler(UIElement.PointerPressedEvent, _pointerPressedHandler, true);
platformView.AddHandler(UIElement.PointerReleasedEvent, _pointerReleasedHandler, true);

Expand All @@ -59,6 +61,7 @@ protected override void DisconnectHandler(Button platformView)
}

platformView.Click -= OnClick;
platformView.Unloaded -= OnUnloaded;
platformView.RemoveHandler(UIElement.PointerPressedEvent, _pointerPressedHandler);
platformView.RemoveHandler(UIElement.PointerReleasedEvent, _pointerReleasedHandler);

Expand Down Expand Up @@ -104,14 +107,25 @@ void OnClick(object sender, RoutedEventArgs e)

void OnPointerPressed(object sender, PointerRoutedEventArgs e)
{
_isPressed = true;
VirtualView?.Pressed();
}

void OnPointerReleased(object sender, PointerRoutedEventArgs e)
{
_isPressed = false;
VirtualView?.Released();
}

void OnUnloaded(object sender, RoutedEventArgs e)
{
// WinUI will not raise the PointerReleased event if the pointer is pressed and then unloaded
if (_isPressed)
{
VirtualView?.Released();
}
}

void OnImageOpened(object sender, RoutedEventArgs routedEventArgs)
{
VirtualView?.UpdateIsLoading(false);
Expand Down

0 comments on commit c70b64a

Please sign in to comment.