diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm index e0bec49c04..ff4ab7dc94 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm @@ -93,9 +93,11 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } // namespace -@implementation FlutterSwitchSemanticsObject { - UISwitch* _nativeSwitch; -} +@interface FlutterSwitchSemanticsObject () +@property(nonatomic, readonly) UISwitch* nativeSwitch; +@end + +@implementation FlutterSwitchSemanticsObject - (instancetype)initWithBridge:(fml::WeakPtr)bridge uid:(int32_t)uid { @@ -140,6 +142,12 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) { } - (UIAccessibilityTraits)accessibilityTraits { + if ([self node].HasFlag(flutter::SemanticsFlags::kIsEnabled)) { + _nativeSwitch.enabled = YES; + } else { + _nativeSwitch.enabled = NO; + } + return _nativeSwitch.accessibilityTraits; } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm index 5797dfb4eb..5be638ed05 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm @@ -734,7 +734,8 @@ class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos { // Handle initial setting of node with header. flutter::SemanticsNode node; node.flags = static_cast(flutter::SemanticsFlags::kHasToggledState) | - static_cast(flutter::SemanticsFlags::kIsToggled); + static_cast(flutter::SemanticsFlags::kIsToggled) | + static_cast(flutter::SemanticsFlags::kIsEnabled); node.label = "foo"; [object setSemanticsNode:&node]; // Create ab real UISwitch to compare the FlutterSwitchSemanticsObject with. @@ -746,7 +747,8 @@ class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos { // Set the toggled to false; flutter::SemanticsNode update; - update.flags = static_cast(flutter::SemanticsFlags::kHasToggledState); + update.flags = static_cast(flutter::SemanticsFlags::kHasToggledState) | + static_cast(flutter::SemanticsFlags::kIsEnabled); update.label = "foo"; [object setSemanticsNode:&update]; @@ -756,6 +758,28 @@ class MockAccessibilityBridgeNoWindow : public AccessibilityBridgeIos { XCTAssertEqual(object.accessibilityValue, nativeSwitch.accessibilityValue); } +- (void)testFlutterSwitchSemanticsObjectMatchesUISwitchDisabled { + fml::WeakPtrFactory factory( + new flutter::MockAccessibilityBridge()); + fml::WeakPtr bridge = factory.GetWeakPtr(); + FlutterSwitchSemanticsObject* object = [[FlutterSwitchSemanticsObject alloc] initWithBridge:bridge + uid:1]; + + // Handle initial setting of node with header. + flutter::SemanticsNode node; + node.flags = static_cast(flutter::SemanticsFlags::kHasToggledState) | + static_cast(flutter::SemanticsFlags::kIsToggled); + node.label = "foo"; + [object setSemanticsNode:&node]; + // Create ab real UISwitch to compare the FlutterSwitchSemanticsObject with. + UISwitch* nativeSwitch = [[UISwitch alloc] init]; + nativeSwitch.on = YES; + nativeSwitch.enabled = NO; + + XCTAssertEqual(object.accessibilityTraits, nativeSwitch.accessibilityTraits); + XCTAssertEqual(object.accessibilityValue, nativeSwitch.accessibilityValue); +} + - (void)testSemanticsObjectDeallocated { fml::WeakPtrFactory factory( new flutter::MockAccessibilityBridge());