Skip to content

Commit

Permalink
Merge pull request #13 from AccessibilityWorkWithPhysicalKeyboardAndroid
Browse files Browse the repository at this point in the history
  • Loading branch information
IeuanWalker authored Feb 24, 2022
2 parents 0c14996 + b24bc65 commit 890ff5e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Demo/App.Android/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Scr/StateButton.Android/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Scr/StateButton.Android/StateButtonRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Xamarin.Forms.Platform.Android;
using Android.Views.Accessibility;
using AndroidView = Android.Views;
using Android.Runtime;

[assembly: ExportRenderer(typeof(StateButton.StateButton), typeof(StateButtonRenderer))]

Expand Down Expand Up @@ -68,6 +69,22 @@ protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
};
}

public override bool OnKeyUp([GeneratedEnum] Keycode keyCode, KeyEvent e)
{
if(keyCode == Keycode.Space || keyCode == Keycode.Enter)
{
foreach (IGestureRecognizer recognizer in Element.GestureRecognizers.Where(x => x is TouchGestureRecognizer))
{
if (recognizer is TouchGestureRecognizer touchGestureRecognizer)
{
touchGestureRecognizer.Clicked();
}
}
}

return base.OnKeyUp(keyCode, e);
}

private class MyAccessibilityDelegate : AccessibilityDelegate
{
public override void OnInitializeAccessibilityNodeInfo(AndroidView.View host, AccessibilityNodeInfo info)
Expand Down

0 comments on commit 890ff5e

Please sign in to comment.