Repository navigation
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
Activity
jfversluis commentedon Jan 16, 2025
I see you mention .NET MAUI on .NET 8, are you able to test with .NET 9? And the latest Toolkit release? Does that change anything? Just to make sure we're looking at the latest and greatest?
It does seem that you already dug in quite a bit. Maybe you're able to propose a change for this through a PR?
plewm commentedon Jan 22, 2025
I just retested it with .NET9 and latest Maui release 9.0.100 and CommunityToolkit 11.0.0. Currently I can only test Android, but now the Touchbehavior is not working at all anymore.
Additional testing: 9.1.1 still works, 10.0.0 and 11.0.0 do not work
ne0rrmatrix commentedon Jan 26, 2025
Be sure to assign the
BindingContextafter switching to dotnet 9.x The toolkit no longer set binding context. It is a breaking change. More information is available in the release notes: https://github.com/CommunityToolkit/Maui/releases/tag/10.0.0Additional information available on StackOverflow: https://stackoverflow.com/a/79099574/5953643
plewm commentedon Jan 28, 2025
Yep, that helps. The standard functionality with that manual Binding works.
The original issue of the Android Keyboard usage persists. even with .NET 9 and newest Toolkit version
plewm commentedon Feb 5, 2025
I would like to create a PR for a change, but I have no rights to create a branch or something.
My proposal for a fix would be to separate the event of the KeyBoard action by reacting to the KeyPress event. It results so that the click event is not triggered by the spacebar anymore and only raises the KeyPress event:
TheCodeTraveler commentedon Feb 5, 2025
Thanks @plewm. You must first fork the repository before you can submit a pull request. Here's a walkthrough: https://opensource.com/article/19/7/create-pull-request-github
plewm commentedon Feb 6, 2025
you can look at:
#2497
do I have to add you guys or someone specific as reviewer somehow?