-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add high contrast API to AccessibilityInfo #742
Changes from 3 commits
9ee15f9
9fa3fc3
ad7c337
5fc6d93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ extern NSString *const RCTAccessibilityManagerDidUpdateMultiplierNotification; / | |
|
||
@property (nonatomic, assign) BOOL isBoldTextEnabled; | ||
@property (nonatomic, assign) BOOL isGrayscaleEnabled; | ||
@property (nonatomic, assign) BOOL isHighContrastEnabled; // TODO(macOS ISS#2323203) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. even if we leave the JS prop to be high contrast, I still think it is more natural that Apple has boolean property named isIncreasedContrastEnabled. what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we leave as is but add a comment "maps to IncreaseContrast for macOS" or something like that? Anyone whose written macOS code before may wonder how these two relate to each other so I think it should be documented somewhere |
||
@property (nonatomic, assign) BOOL isInvertColorsEnabled; | ||
@property (nonatomic, assign) BOOL isReduceMotionEnabled; | ||
@property (nonatomic, assign) BOOL isReduceTransparencyEnabled; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,12 +23,12 @@ @implementation RCTAccessibilityManager | |
|
||
static void *AccessibilityVoiceOverChangeContext = &AccessibilityVoiceOverChangeContext; | ||
|
||
+ (BOOL)requiresMainQueueSetup | ||
+ (BOOL)requiresMainQueueSetup | ||
{ | ||
return NO; | ||
return YES; | ||
} | ||
|
||
- (instancetype)init | ||
- (instancetype)init | ||
{ | ||
if (self = [super init]) { | ||
[[NSWorkspace sharedWorkspace] addObserver:self | ||
|
@@ -39,11 +39,11 @@ - (instancetype)init | |
selector:@selector(accessibilityDisplayOptionsChange:) | ||
name:NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification | ||
object:nil]; | ||
_isHighContrastEnabled = [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldIncreaseContrast]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not your fault but while we're touching these can we cache this to save all the extra time calling into the same method over and over again?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be a micro-optimization since calling these singleton methods take microseconds and I think it's fine to continue following the convention in React Native of calling them for each use (see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd argue those should get fixed too. Functionally speaking it will only improve performance (albeit a small amount) with no downsides if we fix up these calls everywhere. |
||
_isInvertColorsEnabled = [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldInvertColors]; | ||
_isReduceMotionEnabled = [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion]; | ||
_isReduceTransparencyEnabled = [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceTransparency]; | ||
_isVoiceOverEnabled = [[NSWorkspace sharedWorkspace] isVoiceOverEnabled]; | ||
|
||
} | ||
return self; | ||
} | ||
|
@@ -53,7 +53,6 @@ - (void)dealloc | |
[[NSWorkspace sharedWorkspace] removeObserver:self | ||
forKeyPath:@"voiceOverEnabled" | ||
context:AccessibilityVoiceOverChangeContext]; | ||
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self]; | ||
} | ||
|
||
RCT_EXPORT_METHOD(announceForAccessibility:(NSString *)announcement) | ||
|
@@ -67,6 +66,12 @@ - (void)dealloc | |
); | ||
} | ||
|
||
RCT_EXPORT_METHOD(getCurrentHighContrastState:(RCTResponseSenderBlock)callback | ||
error:(__unused RCTResponseSenderBlock)error) | ||
{ | ||
callback(@[@(_isHighContrastEnabled)]); | ||
} | ||
|
||
RCT_EXPORT_METHOD(getCurrentInvertColorsState:(RCTResponseSenderBlock)callback | ||
error:(__unused RCTResponseSenderBlock)error) | ||
{ | ||
|
@@ -124,9 +129,16 @@ - (void)observeValueForKeyPath:(NSString *)keyPath | |
|
||
- (void)accessibilityDisplayOptionsChange:(NSNotification *)notification | ||
{ | ||
BOOL newHighContrastEnabled = [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldIncreaseContrast]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, might as well be efficient and cache the |
||
BOOL newInvertColorsEnabled = [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldInvertColors]; | ||
BOOL newReduceMotionEnabled = [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion]; | ||
BOOL newReduceTransparencyEnabled = [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceTransparency]; | ||
|
||
if (_isHighContrastEnabled != newHighContrastEnabled) { | ||
_isHighContrastEnabled = newHighContrastEnabled; | ||
[_bridge.eventDispatcher sendDeviceEventWithName:@"highContrastChanged" | ||
body:@(_isHighContrastEnabled)]; | ||
} | ||
if (_isInvertColorsEnabled != newInvertColorsEnabled) { | ||
_isInvertColorsEnabled = newInvertColorsEnabled; | ||
[_bridge.eventDispatcher sendDeviceEventWithName:@"invertColorsChanged" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we call it hightcontrast when for apple platform it is increased contrast? high contrast is pretty Window's term right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. Apple also uses the term "high contrast", such as with the appearance names (i.e.
NSAppearanceNameAccessibilityHighContrastAqua
), and I think the industry in general refers to this accessibility mode as "high contrast". 😀There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to be shown I'm wrong here but I get the impression from Apple's support docs that
Increase Contrast
is the overarching feature encapsulating many different contrasts whereasHighContrast
is one of many contrast options within it (e.g.NSAppearanceNameAqua
,NSAppearanceNameDarkAqua
,NSAppearanceNameAccessibilityHighContrastDarkAqua
,NSAppearanceNameVibrantDark
,NSAppearanceNameAccessibilityHighContrastVibrantDark
).If other platforms call it "High Contrast" then I think we just have to choose the one that makes the most sense to go by because I get the impression it won't match up perfectly for all platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're writing this feature primarily for macOS, I'd also lean towards IncreaseContrast, but again am happy to see how I'm misunderstanding Apple's docs :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also plan to implement this API on iOS, Android, and Windows, which already use "high contrast" terminology in their APIs (i.e.
UIAccessibilityContrastHigh
on iOS,isHighTextContrastEnabled()
on Android,HighContrast()
on Windows and the-ms-high-contrast
media query in Edge). I really think "high contrast" is right choice for this API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea the main argument against using the macOS terminology is to keep it consistent cross-plat. I can see why that's important enough to keep it