From d12f2a609635d18ee89547131ff0a11eca59266c Mon Sep 17 00:00:00 2001 From: brandondiamond <1036976+brandondiamond@users.noreply.github.com> Date: Wed, 8 Jan 2020 21:26:44 -0500 Subject: [PATCH] Add support for on/off switch labels when built on iOS 13. (#12467) --- lib/ui/window.dart | 8 ++++++++ lib/ui/window/window.h | 1 + lib/web_ui/lib/src/ui/window.dart | 9 +++++++++ .../ios/framework/Source/FlutterViewController.mm | 11 +++++++++++ 4 files changed, 29 insertions(+) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index dfad860b3..2572d2da1 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -1213,6 +1213,7 @@ class AccessibilityFeatures { static const int _kDisableAnimationsIndex = 1 << 2; static const int _kBoldTextIndex = 1 << 3; static const int _kReduceMotionIndex = 1 << 4; + static const int _kOnOffSwitchLabelsIndex = 1 << 5; // A bitfield which represents each enabled feature. final int _index; @@ -1240,6 +1241,11 @@ class AccessibilityFeatures { /// Only supported on iOS. bool get reduceMotion => _kReduceMotionIndex & _index != 0; + /// The platform is requesting that on/off labels be added to switches. + /// + /// Only supported on iOS. + bool get onOffSwitchLabels => _kOnOffSwitchLabelsIndex & _index != 0; + @override String toString() { final List features = []; @@ -1253,6 +1259,8 @@ class AccessibilityFeatures { features.add('boldText'); if (reduceMotion) features.add('reduceMotion'); + if (onOffSwitchLabels) + features.add('onOffSwitchLabels'); return 'AccessibilityFeatures$features'; } diff --git a/lib/ui/window/window.h b/lib/ui/window/window.h index bddcb70f3..86547ec0c 100644 --- a/lib/ui/window/window.h +++ b/lib/ui/window/window.h @@ -44,6 +44,7 @@ enum class AccessibilityFeatureFlag : int32_t { kDisableAnimations = 1 << 2, kBoldText = 1 << 3, kReduceMotion = 1 << 4, + kOnOffSwitchLabels = 1 << 5, }; class WindowClient { diff --git a/lib/web_ui/lib/src/ui/window.dart b/lib/web_ui/lib/src/ui/window.dart index d81159b37..4cee1c2aa 100644 --- a/lib/web_ui/lib/src/ui/window.dart +++ b/lib/web_ui/lib/src/ui/window.dart @@ -995,6 +995,7 @@ class AccessibilityFeatures { static const int _kDisableAnimationsIndex = 1 << 2; static const int _kBoldTextIndex = 1 << 3; static const int _kReduceMotionIndex = 1 << 4; + static const int _kOnOffSwitchLabelsIndex = 1 << 5; // A bitfield which represents each enabled feature. final int _index; @@ -1022,6 +1023,11 @@ class AccessibilityFeatures { /// Only supported on iOS. bool get reduceMotion => _kReduceMotionIndex & _index != 0; + /// The platform is requesting that on/off labels be added to switches. + /// + /// Only supported on iOS. + bool get onOffSwitchLabels => _kOnOffSwitchLabelsIndex & _index != 0; + @override String toString() { final List features = []; @@ -1040,6 +1046,9 @@ class AccessibilityFeatures { if (reduceMotion) { features.add('reduceMotion'); } + if (onOffSwitchLabels) { + features.add('onOffSwitchLabels'); + } return 'AccessibilityFeatures$features'; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 1e082ec4e..20f560631 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -238,6 +238,13 @@ typedef enum UIAccessibilityContrast : NSInteger { selector:@selector(onUserSettingsChanged:) name:UIContentSizeCategoryDidChangeNotification object:nil]; + + if (@available(iOS 13, *)) { + [center addObserver:self + selector:@selector(onAccessibilityStatusChanged:) + name:UIAccessibilityOnOffSwitchLabelsDidChangeNotification + object:nil]; + } } - (void)setInitialRoute:(NSString*)route { @@ -889,6 +896,10 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) flags |= static_cast(flutter::AccessibilityFeatureFlag::kReduceMotion); if (UIAccessibilityIsBoldTextEnabled()) flags |= static_cast(flutter::AccessibilityFeatureFlag::kBoldText); + if (@available(iOS 13, *)) { + if (UIAccessibilityIsOnOffSwitchLabelsEnabled()) + flags |= static_cast(flutter::AccessibilityFeatureFlag::kOnOffSwitchLabels); + } #if TARGET_OS_SIMULATOR // There doesn't appear to be any way to determine whether the accessibility // inspector is enabled on the simulator. We conservatively always turn on the -- GitLab