From d0c2418dfed3e828c1a003ff8ac4a1baaf5e7ae8 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Sat, 22 Feb 2020 23:04:04 +0100 Subject: [PATCH] Add support for Increase Contrast on iOS (#15343) --- lib/ui/window.dart | 8 ++++++++ lib/ui/window/window.h | 1 + lib/web_ui/lib/src/ui/window.dart | 9 +++++++++ .../darwin/ios/framework/Source/FlutterViewController.mm | 7 +++++++ 4 files changed, 25 insertions(+) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 36c0fc282..c830b6f4c 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -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; @@ -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 features = []; @@ -1252,6 +1258,8 @@ class AccessibilityFeatures { features.add('boldText'); if (reduceMotion) features.add('reduceMotion'); + if (highContrast) + features.add('highContrast'); return 'AccessibilityFeatures$features'; } diff --git a/lib/ui/window/window.h b/lib/ui/window/window.h index bddcb70f3..fac2861a4 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, + kHighContrast = 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 c22e10149..d143c5046 100644 --- a/lib/web_ui/lib/src/ui/window.dart +++ b/lib/web_ui/lib/src/ui/window.dart @@ -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; @@ -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 features = []; @@ -1041,6 +1047,9 @@ class AccessibilityFeatures { if (reduceMotion) { features.add('reduceMotion'); } + if (highContrast) { + features.add('highContrast'); + } return 'AccessibilityFeatures$features'; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index a94f6b657..5b04408ec 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -298,6 +298,11 @@ typedef enum UIAccessibilityContrast : NSInteger { name:UIAccessibilityBoldTextStatusDidChangeNotification object:nil]; + [center addObserver:self + selector:@selector(onAccessibilityStatusChanged:) + name:UIAccessibilityDarkerSystemColorsStatusDidChangeNotification + object:nil]; + [center addObserver:self selector:@selector(onUserSettingsChanged:) name:UIContentSizeCategoryDidChangeNotification @@ -962,6 +967,8 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) flags |= static_cast(flutter::AccessibilityFeatureFlag::kReduceMotion); if (UIAccessibilityIsBoldTextEnabled()) flags |= static_cast(flutter::AccessibilityFeatureFlag::kBoldText); + if (UIAccessibilityDarkerSystemColorsEnabled()) + flags |= static_cast(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 -- GitLab