-
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 1 commit
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; | ||
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. for my own understanding, is this correct? anything we ask for NSWorkspace, we should be on the UIthread right? 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. Great point! I'll change this. |
||
} | ||
|
||
- (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,7 @@ - (void)dealloc | |
[[NSWorkspace sharedWorkspace] removeObserver:self | ||
forKeyPath:@"voiceOverEnabled" | ||
context:AccessibilityVoiceOverChangeContext]; | ||
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self]; | ||
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self]; | ||
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. do we need this line? "If your app targets iOS 9.0 and later or macOS 10.11 and later, and you used addObserver:selector:name:object:, you do not need to unregister the observer. If you forget or are unable to remove the observer, the system cleans up the next time it would have posted to it." https://developer.apple.com/documentation/foundation/nsnotificationcenter/1413994-removeobserver 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. True, but it's certainly more explicit to just leave this because otherwise somebody needs to know this behavior when reading this code. 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. Don't we not support iOS 8.0 anymore? I'm always in favor of deleting code that has no functional benefit :) |
||
} | ||
|
||
RCT_EXPORT_METHOD(announceForAccessibility:(NSString *)announcement) | ||
|
@@ -67,6 +67,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 +130,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