-
Notifications
You must be signed in to change notification settings - Fork 494
[BUG] Touchbehavior Keyboard Access Click not working on Android #2443
Description
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
When you use an App on Android via Keyboard access/navigation and you try to hit a button via space bar for example, the animation is executed, but the click event is not raised or executed
Expected Behavior
You would expect the Click to be executed normally, like it does on iOS
Steps To Reproduce
- Just add the Touchbehavior to any component
- try using the App with Keyboard
- navigate to that component
- press space bar to initiate click
In the Example App:
- Navigate via Tab on keyboard to the Border with TouchBehavior
- Press Space bar to Click -> nothing happens
- Touch normally -> works
- activate TalkBack
- Navigate again by Tab on Keyboard
- Press Space bar -> works
Link to public reproduction project repository
https://github.com/plewm/TouchbehaviorExample
Environment
- .NET MAUI CommunityToolkit: 9.1.0
- OS: macOS 15.1 (24B83)
- .NET MAUI: 8.0.402.1Anything else?
From my debugging I found the issue to be the accessibilityManager and bool IsAccessibilityMode. it seems the accessibilityManager is null and accessibility mode is just false if the App is only used with keyboard. It will only be set if TalkBack is activated on the device. The Keyboard actions than also work, when TalkBack is activated as well. But the App should be usable with only keyboard without TalkBack as well. The Problem is, that the bool IsAccessibilityMode is checked in the OnClick method and is not reaching the HandleTouchEnded if AccessibilityMode is false.:
`void UpdateClickHandler()
{
if (view is null || !view.IsAlive())
{
return;
}
view.Click -= OnClick;
if (IsAccessibilityMode || (IsEnabled && (Element?.IsEnabled ?? false)))
{
view.Click += OnClick;
return;
}
}
void OnClick(object? sender, EventArgs args)
{
if (!IsEnabled)
{
return;
}
if (!IsAccessibilityMode)
{
return;
}
IsCanceled = false;
HandleTouchEnded(TouchStatus.Completed);
}`
Furthermore that implementation feels not as Android intended cause the documentation on Android side says not to do different stuff based on the AccessibilityManger because it results in inconsistent behavior.
isEnabled
Added in API level 4
public boolean isEnabled ()
Returns if the accessibility in the system is enabled.
Note: This query is used for sending AccessibilityEvents, since events are only needed if accessibility is on. Avoid changing UI or app behavior based on the state of accessibility. While well-intentioned, doing this creates brittle, less well-maintained code that works for some users but not others. Shared code leads to more equitable experiences and less technical debt.
https://developer.android.com/reference/android/view/accessibility/AccessibilityManager