[iOS] Fix slider semantics node answer to accessibility activate (flutter/engine#56427)

## Description

iOS fix [[A11y] Double Tap brings the Slider thumb to the center of the widget.](https://github.com/flutter/flutter/issues/156427) per instruction from https://github.com/flutter/flutter/pull/157601#discussion_r1829992890

I don't have a physical iOS device to double check, but using the iOS Simulator and accessibility tools, the behavior seems ok. Without this PR, the slider thumb goes to the center when clicking 'Activate', with this PR it does not :

https://github.com/user-attachments/assets/697acadd-7fb1-40a5-ba5a-b549cac381a1

## Related Issue

iOS fix for [[A11y] Double Tap brings the Slider thumb to the center of the widget.](https://github.com/flutter/flutter/issues/156427)

## Tests

Adds 1 test.
This commit is contained in:
Bruno Leroux
2024-11-12 12:21:23 +01:00
committed by GitHub
parent 34b684d470
commit 157b28e3a9
2 changed files with 21 additions and 0 deletions

View File

@@ -692,6 +692,13 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
return NO;
}
if (!self.node.HasAction(flutter::SemanticsAction::kTap)) {
// Prevent sliders to receive a regular tap which will change the value.
//
// This is needed because it causes slider to select to middle if it
// does not have a semantics tap.
if (self.node.HasFlag(flutter::SemanticsFlags::kIsSlider)) {
return YES;
}
return NO;
}
self.bridge->DispatchSemanticsAction(self.uid, flutter::SemanticsAction::kTap);

View File

@@ -1206,4 +1206,18 @@ const float kFloatCompareEpsilon = 0.001;
XCTAssertTrue([itemsInRect containsObject:child1]);
XCTAssertTrue([itemsInRect containsObject:child2]);
}
- (void)testSliderSemanticsObject {
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
new flutter::testing::MockAccessibilityBridge());
fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
flutter::SemanticsNode node;
node.flags = static_cast<int32_t>(flutter::SemanticsFlags::kIsSlider);
SemanticsObject* object = [[SemanticsObject alloc] initWithBridge:bridge uid:0];
[object setSemanticsNode:&node];
[object accessibilityBridgeDidFinishUpdate];
XCTAssertEqual([object accessibilityActivate], YES);
}
@end