From 0bf4ecab96c4edf6572e19781739b75c83180155 Mon Sep 17 00:00:00 2001 From: Brandon Diamond <1036976+brandondiamond@users.noreply.github.com> Date: Thu, 26 Sep 2019 16:17:48 -0400 Subject: [PATCH] Add support for on/off switch labels when built on iOS 13. --- 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 +++++++++++ shell/platform/fuchsia/runtime/dart/utils/BUILD.gn | 4 ++-- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index a810551e38254..edff156af1ef4 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -1194,6 +1194,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; @@ -1221,6 +1222,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 = []; @@ -1234,6 +1240,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 99a8585a6910a..6039b9e178dc0 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 80f15c712d165..56c09a4133dd7 100644 --- a/lib/web_ui/lib/src/ui/window.dart +++ b/lib/web_ui/lib/src/ui/window.dart @@ -1012,6 +1012,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; @@ -1039,6 +1040,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 = []; @@ -1057,6 +1063,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 87e605e97fd48..24b55427d9166 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -238,6 +238,13 @@ - (void)setupNotificationCenterObservers { 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 { @@ -857,6 +864,10 @@ - (void)onAccessibilityStatusChanged:(NSNotification*)notification { 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 diff --git a/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn b/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn index b1c94a762da59..1dca94e3c2acd 100644 --- a/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn +++ b/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn @@ -34,10 +34,10 @@ source_set("utils") { "$fuchsia_sdk_root/pkg:async-loop-default", "$fuchsia_sdk_root/pkg:fdio", "$fuchsia_sdk_root/pkg:memfs", - "$fuchsia_sdk_root/pkg:syslog", - "$fuchsia_sdk_root/pkg:zx", "$fuchsia_sdk_root/pkg:sys_cpp", + "$fuchsia_sdk_root/pkg:syslog", "$fuchsia_sdk_root/pkg:vfs_cpp", + "$fuchsia_sdk_root/pkg:zx", "//third_party/tonic", ]