Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 72569a6

Browse files
authored
[Android] Fix Slider semantics double tap behaviors (#56452)
## 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.
1 parent cc3574f commit 72569a6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

shell/platform/android/io/flutter/view/AccessibilityBridge.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,15 @@ public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId) {
802802
result.addAction(AccessibilityNodeInfo.ACTION_CLICK);
803803
result.setClickable(true);
804804
}
805+
} else {
806+
// Prevent Slider to receive a regular tap which will change the value.
807+
//
808+
// This is needed because it causes slider to select to middle if it
809+
// doesn't have a semantics tap.
810+
if (semanticsNode.hasFlag(Flag.IS_SLIDER)) {
811+
result.addAction(AccessibilityNodeInfo.ACTION_CLICK);
812+
result.setClickable(true);
813+
}
805814
}
806815
if (semanticsNode.hasAction(Action.LONG_PRESS)) {
807816
if (semanticsNode.onLongPressOverride != null) {

shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,21 @@ public void SetSourceAndPackageNameForAccessibilityEvent() {
21652165
verify(mockEvent).setSource(eq(mockRootView), eq(123));
21662166
}
21672167

2168+
@Test
2169+
public void itAddsClickActionToSliderNodeInfo() {
2170+
AccessibilityBridge accessibilityBridge = setUpBridge();
2171+
2172+
TestSemanticsNode testSemanticsNode = new TestSemanticsNode();
2173+
testSemanticsNode.addFlag(AccessibilityBridge.Flag.IS_SLIDER);
2174+
TestSemanticsUpdate testSemanticsUpdate = testSemanticsNode.toUpdate();
2175+
testSemanticsUpdate.sendUpdateToBridge(accessibilityBridge);
2176+
AccessibilityNodeInfo nodeInfo = accessibilityBridge.createAccessibilityNodeInfo(0);
2177+
2178+
assertEquals(nodeInfo.isClickable(), true);
2179+
List<AccessibilityNodeInfo.AccessibilityAction> actions = nodeInfo.getActionList();
2180+
assertTrue(actions.contains(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLICK));
2181+
}
2182+
21682183
AccessibilityBridge setUpBridge() {
21692184
return setUpBridge(null, null, null, null, null, null);
21702185
}

0 commit comments

Comments
 (0)