Skip to content

Commit a473d5e

Browse files
authored
fix TouchBehavior Android KeyBoard activation (#2497)
1 parent a67f94a commit a473d5e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.android.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ protected override void OnAttachedTo(VisualElement bindable, AView platformView)
4444
viewGroup = platformView.GetParentOfType<ViewGroup>();
4545

4646
platformView.Touch += OnTouch;
47+
platformView.KeyPress += OnKeyPressed;
4748
UpdateClickHandler();
4849
accessibilityManager = platformView.Context?.GetSystemService(Context.AccessibilityService) as AccessibilityManager;
4950

@@ -89,6 +90,7 @@ protected override void OnDetachedFrom(VisualElement bindable, AView platformVie
8990
{
9091
view.Touch -= OnTouch;
9192
view.Click -= OnClick;
93+
view.KeyPress -= OnKeyPressed;
9294
}
9395

9496
Element = null;
@@ -117,6 +119,15 @@ void UpdateClickHandler()
117119
}
118120
}
119121

122+
void OnKeyPressed(object? sender, AView.KeyEventArgs e)
123+
{
124+
if (e.KeyCode == Keycode.Space && e.Event?.Action == KeyEventActions.Up)
125+
{
126+
IsCanceled = false;
127+
HandleTouchEnded(TouchStatus.Completed);
128+
}
129+
}
130+
120131
void OnClick(object? sender, EventArgs args)
121132
{
122133
if (!IsEnabled)

0 commit comments

Comments
 (0)