-
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
Conversation
e5978d3
to
3ec1253
Compare
/** | ||
* macOS only | ||
*/ | ||
isHighContrastEnabled: function(): Promise<boolean> { |
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 whereas HighContrast
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
@@ -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 comment
The 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 comment
The 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 comment
The 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 :)
@@ -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 comment
The 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 comment
The 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
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Great point! I'll change this.
@@ -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 comment
The 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?
NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace
and just use that var throughout the method
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.
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 [NSNotificationCenter defaultCenter]
calls in other native modules).
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'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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, might as well be efficient and cache the sharedWorkspace
@@ -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 comment
The 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.
@@ -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 comment
The 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
This reverts commit e9e4980.
This reverts commit e9e4980.
Please select one of the following
Summary
This adds the
isHighContrastEnabled()
method andhighContrastChanged
event to theAccessibilityInfo
module. This matches the existing API conventions we have in React Native macOS for other accessibility features. React Native Windows has a similar API with itsAppTheme
module, but that module doesn't exist for other React Native platforms and this is more appropriate inAccessibilityInfo
.Changelog
[macOS] [Added] - Add high contrast API to AccessibilityInfo
Test Plan
Tested in RNTester. Observed live updates when changing the Increase contrast setting under System Preferences.
Microsoft Reviewers: Open in CodeFlow