Skip to content

[BUG] Touchbehavior Keyboard Access Click not working on Android #2443

@plewm

Description

@plewm

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

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

  1. Just add the Touchbehavior to any component
  2. try using the App with Keyboard
  3. navigate to that component
  4. press space bar to initiate click

In the Example App:

  1. Navigate via Tab on keyboard to the Border with TouchBehavior
  2. Press Space bar to Click -> nothing happens
  3. Touch normally -> works
  4. activate TalkBack
  5. Navigate again by Tab on Keyboard
  6. 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.1

Anything 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/behaviorsIssue/Discussion/PR that has to do with BehaviorsbugSomething isn't workingunverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions