feat: unify platform specific high contrast APIs to AccessibilityInfo.isHighContrastEnabled
#49965
+139
−39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Every platform has some form of "high Contrast", with a separate React Native API to access it. These all do the same thing, query the OS to see if its version of "high contrast" is enabled, and report it back to AccessibilityInfo. Sadly, each platform (Android, iOS, macOS, Windows) used their own platform specific name to read this in JS.
AccessibilityInfo
upstream of React Native macOS and Windows so they both could implement it and in the new architecture, we would have a simpler API.This leads to real divergences in product code, where we must fork our JS per platform to do essentially the same thing (see microsoft/react-native-gallery#470 for an example).
Let's unify the APIs under a single
isHighContrastEnabled
API. A bit cheeky I chose the API name from the fork of React Native I maintain (React Native macOS), but I do think it's the most coherent name.To help migration, I added a deprecation warning to the iOS and Android APIs. The idea being
so that users have time to migrate
Changelog:
[GENERAL] [ADDED] - Add isHighContrastEnabled to AccessibilityInfo
Test Plan:
I updated the AccessibilityExample page on RNTester with both the old and new API.
On both Android and iOS, the new API matches the old API when high contrast is enabled through system settings
Screen.Recording.2025-03-12.at.5.02.11.AM.mp4