Skip to content

Commit d12f2a6

Browse files
brandondiamondcbracken
authored andcommitted
Add support for on/off switch labels when built on iOS 13. (flutter#12467)
1 parent 5c9e134 commit d12f2a6

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

lib/ui/window.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,7 @@ class AccessibilityFeatures {
12131213
static const int _kDisableAnimationsIndex = 1 << 2;
12141214
static const int _kBoldTextIndex = 1 << 3;
12151215
static const int _kReduceMotionIndex = 1 << 4;
1216+
static const int _kOnOffSwitchLabelsIndex = 1 << 5;
12161217

12171218
// A bitfield which represents each enabled feature.
12181219
final int _index;
@@ -1240,6 +1241,11 @@ class AccessibilityFeatures {
12401241
/// Only supported on iOS.
12411242
bool get reduceMotion => _kReduceMotionIndex & _index != 0;
12421243

1244+
/// The platform is requesting that on/off labels be added to switches.
1245+
///
1246+
/// Only supported on iOS.
1247+
bool get onOffSwitchLabels => _kOnOffSwitchLabelsIndex & _index != 0;
1248+
12431249
@override
12441250
String toString() {
12451251
final List<String> features = <String>[];
@@ -1253,6 +1259,8 @@ class AccessibilityFeatures {
12531259
features.add('boldText');
12541260
if (reduceMotion)
12551261
features.add('reduceMotion');
1262+
if (onOffSwitchLabels)
1263+
features.add('onOffSwitchLabels');
12561264
return 'AccessibilityFeatures$features';
12571265
}
12581266

lib/ui/window/window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum class AccessibilityFeatureFlag : int32_t {
4444
kDisableAnimations = 1 << 2,
4545
kBoldText = 1 << 3,
4646
kReduceMotion = 1 << 4,
47+
kOnOffSwitchLabels = 1 << 5,
4748
};
4849

4950
class WindowClient {

lib/web_ui/lib/src/ui/window.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ class AccessibilityFeatures {
995995
static const int _kDisableAnimationsIndex = 1 << 2;
996996
static const int _kBoldTextIndex = 1 << 3;
997997
static const int _kReduceMotionIndex = 1 << 4;
998+
static const int _kOnOffSwitchLabelsIndex = 1 << 5;
998999

9991000
// A bitfield which represents each enabled feature.
10001001
final int _index;
@@ -1022,6 +1023,11 @@ class AccessibilityFeatures {
10221023
/// Only supported on iOS.
10231024
bool get reduceMotion => _kReduceMotionIndex & _index != 0;
10241025

1026+
/// The platform is requesting that on/off labels be added to switches.
1027+
///
1028+
/// Only supported on iOS.
1029+
bool get onOffSwitchLabels => _kOnOffSwitchLabelsIndex & _index != 0;
1030+
10251031
@override
10261032
String toString() {
10271033
final List<String> features = <String>[];
@@ -1040,6 +1046,9 @@ class AccessibilityFeatures {
10401046
if (reduceMotion) {
10411047
features.add('reduceMotion');
10421048
}
1049+
if (onOffSwitchLabels) {
1050+
features.add('onOffSwitchLabels');
1051+
}
10431052
return 'AccessibilityFeatures$features';
10441053
}
10451054

shell/platform/darwin/ios/framework/Source/FlutterViewController.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ - (void)setupNotificationCenterObservers {
238238
selector:@selector(onUserSettingsChanged:)
239239
name:UIContentSizeCategoryDidChangeNotification
240240
object:nil];
241+
242+
if (@available(iOS 13, *)) {
243+
[center addObserver:self
244+
selector:@selector(onAccessibilityStatusChanged:)
245+
name:UIAccessibilityOnOffSwitchLabelsDidChangeNotification
246+
object:nil];
247+
}
241248
}
242249

243250
- (void)setInitialRoute:(NSString*)route {
@@ -889,6 +896,10 @@ - (void)onAccessibilityStatusChanged:(NSNotification*)notification {
889896
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kReduceMotion);
890897
if (UIAccessibilityIsBoldTextEnabled())
891898
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kBoldText);
899+
if (@available(iOS 13, *)) {
900+
if (UIAccessibilityIsOnOffSwitchLabelsEnabled())
901+
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kOnOffSwitchLabels);
902+
}
892903
#if TARGET_OS_SIMULATOR
893904
// There doesn't appear to be any way to determine whether the accessibility
894905
// inspector is enabled on the simulator. We conservatively always turn on the

0 commit comments

Comments
 (0)