Skip to content

Commit d0c2418

Browse files
Add support for Increase Contrast on iOS (#15343)
1 parent c3f4c1a commit d0c2418

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

lib/ui/window.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ class AccessibilityFeatures {
12121212
static const int _kDisableAnimationsIndex = 1 << 2;
12131213
static const int _kBoldTextIndex = 1 << 3;
12141214
static const int _kReduceMotionIndex = 1 << 4;
1215+
static const int _kHighContrastIndex = 1 << 5;
12151216

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

1243+
/// The platform is requesting that UI be rendered with darker colors.
1244+
///
1245+
/// Only supported on iOS.
1246+
bool get highContrast => _kHighContrastIndex & _index != 0;
1247+
12421248
@override
12431249
String toString() {
12441250
final List<String> features = <String>[];
@@ -1252,6 +1258,8 @@ class AccessibilityFeatures {
12521258
features.add('boldText');
12531259
if (reduceMotion)
12541260
features.add('reduceMotion');
1261+
if (highContrast)
1262+
features.add('highContrast');
12551263
return 'AccessibilityFeatures$features';
12561264
}
12571265

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+
kHighContrast = 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
@@ -996,6 +996,7 @@ class AccessibilityFeatures {
996996
static const int _kDisableAnimationsIndex = 1 << 2;
997997
static const int _kBoldTextIndex = 1 << 3;
998998
static const int _kReduceMotionIndex = 1 << 4;
999+
static const int _kHighContrastIndex = 1 << 5;
9991000

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

1027+
/// The platform is requesting that UI be rendered with darker colors.
1028+
///
1029+
/// Only supported on iOS.
1030+
bool get highContrast => _kHighContrastIndex & _index != 0;
1031+
10261032
@override
10271033
String toString() {
10281034
final List<String> features = <String>[];
@@ -1041,6 +1047,9 @@ class AccessibilityFeatures {
10411047
if (reduceMotion) {
10421048
features.add('reduceMotion');
10431049
}
1050+
if (highContrast) {
1051+
features.add('highContrast');
1052+
}
10441053
return 'AccessibilityFeatures$features';
10451054
}
10461055

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ - (void)setupNotificationCenterObservers {
298298
name:UIAccessibilityBoldTextStatusDidChangeNotification
299299
object:nil];
300300

301+
[center addObserver:self
302+
selector:@selector(onAccessibilityStatusChanged:)
303+
name:UIAccessibilityDarkerSystemColorsStatusDidChangeNotification
304+
object:nil];
305+
301306
[center addObserver:self
302307
selector:@selector(onUserSettingsChanged:)
303308
name:UIContentSizeCategoryDidChangeNotification
@@ -962,6 +967,8 @@ - (void)onAccessibilityStatusChanged:(NSNotification*)notification {
962967
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kReduceMotion);
963968
if (UIAccessibilityIsBoldTextEnabled())
964969
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kBoldText);
970+
if (UIAccessibilityDarkerSystemColorsEnabled())
971+
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kHighContrast);
965972
#if TARGET_OS_SIMULATOR
966973
// There doesn't appear to be any way to determine whether the accessibility
967974
// inspector is enabled on the simulator. We conservatively always turn on the

0 commit comments

Comments
 (0)