From 8de962e86dc75e21d613a599f573a494cb02d203 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Fri, 11 Nov 2022 12:51:17 +0100 Subject: [PATCH] chore: Try focus keyup --- .../UI/Xaml/ApplicationActivity.Android.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/ApplicationActivity.Android.cs b/src/Uno.UI/UI/Xaml/ApplicationActivity.Android.cs index aa4757315ed2..1ae5c8d54389 100644 --- a/src/Uno.UI/UI/Xaml/ApplicationActivity.Android.cs +++ b/src/Uno.UI/UI/Xaml/ApplicationActivity.Android.cs @@ -123,14 +123,24 @@ public override bool DispatchKeyEvent(KeyEvent e) { if (CoreWindow.GetForCurrentThread() is ICoreWindowEvents ownerEvents) { - ownerEvents.RaiseKeyDown(args); - - var routerArgs = new KeyRoutedEventArgs(this, virtualKey) + if (e.Action == KeyEventActions.Down) { - CanBubbleNatively = false - }; + ownerEvents.RaiseKeyDown(args); + } - (FocusManager.GetFocusedElement() as FrameworkElement)?.RaiseEvent(UIElement.KeyDownEvent, routerArgs); + if (FocusManager.GetFocusedElement() is FrameworkElement element) + { + var routedArgs = new KeyRoutedEventArgs(this, virtualKey) + { + CanBubbleNatively = false + }; + + RoutedEvent routedEvent = e.Action == KeyEventActions.Down ? + UIElement.KeyDownEvent : + UIElement.KeyUpEvent; + + element?.RaiseEvent(routedEvent, routedArgs); + } handled = true; }