Skip to content

Commit

Permalink
Add support for Increase Contrast on iOS (#15343)
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelbeltran committed Feb 22, 2020
1 parent c3f4c1a commit d0c2418
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ class AccessibilityFeatures {
static const int _kDisableAnimationsIndex = 1 << 2;
static const int _kBoldTextIndex = 1 << 3;
static const int _kReduceMotionIndex = 1 << 4;
static const int _kHighContrastIndex = 1 << 5;

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

/// The platform is requesting that UI be rendered with darker colors.
///
/// Only supported on iOS.
bool get highContrast => _kHighContrastIndex & _index != 0;

@override
String toString() {
final List<String> features = <String>[];
Expand All @@ -1252,6 +1258,8 @@ class AccessibilityFeatures {
features.add('boldText');
if (reduceMotion)
features.add('reduceMotion');
if (highContrast)
features.add('highContrast');
return 'AccessibilityFeatures$features';
}

Expand Down
1 change: 1 addition & 0 deletions lib/ui/window/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum class AccessibilityFeatureFlag : int32_t {
kDisableAnimations = 1 << 2,
kBoldText = 1 << 3,
kReduceMotion = 1 << 4,
kHighContrast = 1 << 5,
};

class WindowClient {
Expand Down
9 changes: 9 additions & 0 deletions lib/web_ui/lib/src/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ class AccessibilityFeatures {
static const int _kDisableAnimationsIndex = 1 << 2;
static const int _kBoldTextIndex = 1 << 3;
static const int _kReduceMotionIndex = 1 << 4;
static const int _kHighContrastIndex = 1 << 5;

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

/// The platform is requesting that UI be rendered with darker colors.
///
/// Only supported on iOS.
bool get highContrast => _kHighContrastIndex & _index != 0;

@override
String toString() {
final List<String> features = <String>[];
Expand All @@ -1041,6 +1047,9 @@ class AccessibilityFeatures {
if (reduceMotion) {
features.add('reduceMotion');
}
if (highContrast) {
features.add('highContrast');
}
return 'AccessibilityFeatures$features';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ - (void)setupNotificationCenterObservers {
name:UIAccessibilityBoldTextStatusDidChangeNotification
object:nil];

[center addObserver:self
selector:@selector(onAccessibilityStatusChanged:)
name:UIAccessibilityDarkerSystemColorsStatusDidChangeNotification
object:nil];

[center addObserver:self
selector:@selector(onUserSettingsChanged:)
name:UIContentSizeCategoryDidChangeNotification
Expand Down Expand Up @@ -962,6 +967,8 @@ - (void)onAccessibilityStatusChanged:(NSNotification*)notification {
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kReduceMotion);
if (UIAccessibilityIsBoldTextEnabled())
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kBoldText);
if (UIAccessibilityDarkerSystemColorsEnabled())
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kHighContrast);
#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
Expand Down

0 comments on commit d0c2418

Please sign in to comment.