Skip to content

Commit

Permalink
[Android] Fix Slider semantics double tap behaviors (#56452)
Browse files Browse the repository at this point in the history
## Description

Android fix for [[A11y] Double Tap brings the Slider thumb to the center of the widget.](flutter/flutter#156427). Similar to [the iOS engine fix](#56427).

Slider widget doesn't define a Semantics.onTap handler, so a double-click while in accessibility mode defaults to a regular tap down event to which _RenderSlider reacts by changing the slider value.

Adding a onTap callback on the framework side was tried in flutter/flutter#157601 but it breaks one accessibility guideline test, see flutter/flutter#157601 (comment)). 

See flutter/flutter#157601 (comment) for the reasoning to make the change at the engine level.

## Related Issue

Android fix for [[A11y] Double Tap brings the Slider thumb to the center of the widget.](flutter/flutter#156427).

## Tests

Adds 1 test.
  • Loading branch information
bleroux authored Nov 14, 2024
1 parent cc3574f commit 72569a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,15 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
result.addAction(AccessibilityNodeInfo.ACTION_CLICK);
result.setClickable(true);
}
} else {
// Prevent Slider to receive a regular tap which will change the value.
//
// This is needed because it causes slider to select to middle if it
// doesn't have a semantics tap.
if (semanticsNode.hasFlag(Flag.IS_SLIDER)) {
result.addAction(AccessibilityNodeInfo.ACTION_CLICK);
result.setClickable(true);
}
}
if (semanticsNode.hasAction(Action.LONG_PRESS)) {
if (semanticsNode.onLongPressOverride != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,21 @@ public void SetSourceAndPackageNameForAccessibilityEvent() {
verify(mockEvent).setSource(eq(mockRootView), eq(123));
}

@Test
public void itAddsClickActionToSliderNodeInfo() {
AccessibilityBridge accessibilityBridge = setUpBridge();

TestSemanticsNode testSemanticsNode = new TestSemanticsNode();
testSemanticsNode.addFlag(AccessibilityBridge.Flag.IS_SLIDER);
TestSemanticsUpdate testSemanticsUpdate = testSemanticsNode.toUpdate();
testSemanticsUpdate.sendUpdateToBridge(accessibilityBridge);
AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);

assertEquals(nodeInfo.isClickable(), true);
List<AccessibilityNodeInfo.AccessibilityAction> actions = nodeInfo.getActionList();
assertTrue(actions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK));
}

AccessibilityBridge setUpBridge() {
return setUpBridge(null, null, null, null, null, null);
}
Expand Down

0 comments on commit 72569a6

Please sign in to comment.