Skip to content
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

feat: unify platform specific high contrast APIs to AccessibilityInfo.isHighContrastEnabled #49965

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Saadnajmi
Copy link
Contributor

@Saadnajmi Saadnajmi commented Mar 12, 2025

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.

  • On Android, it's isHighTextContrastEnabled, introduced in RN 0.77 with d4ea147
  • On iOS, it's isDarkerSystemColorsEnabled, introduced in RN 0.77 with af3bee6
    • Sidenote: this API natively seems to be superseded by accessibilityContrast. Luckily, inspecting UIKits headers tells me the two should report the same info most of the time.
  • On macOS, we chose isHighContrastEnabled which is at least as old as RNM 0.66 but probably older
  • On Windows, it's AppTheme.isHighContrast, which I'm not sure how old it is.
    • Sidenote: The inspiration for this PR was to introduce an API to 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

  • RN 0.79: Add the new API, deprecate the old ones
  • RN 0.80+: Remove the old ones
    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

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Microsoft Partner: Microsoft Partner labels Mar 12, 2025
@Saadnajmi Saadnajmi changed the title chore: Unify platform high contrast APIs to chore: Unify platform high contrast APIs to "is HighContrastEnabled" Mar 12, 2025
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Mar 12, 2025
@Saadnajmi Saadnajmi changed the title chore: Unify platform high contrast APIs to "is HighContrastEnabled" chore: unify platform high contrast APIs to "is HighContrastEnabled" Mar 12, 2025
@Saadnajmi Saadnajmi changed the title chore: unify platform high contrast APIs to "is HighContrastEnabled" feat: unify platform high contrast APIs to "is HighContrastEnabled" Mar 12, 2025
@Saadnajmi Saadnajmi changed the title feat: unify platform high contrast APIs to "is HighContrastEnabled" feat: unify platform specific high contrast APIs to AccessibilityInfo.isHighContrastEnabled Mar 12, 2025
@facebook-github-bot
Copy link
Contributor

@jorge-cab has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Microsoft Partner: Microsoft Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants