Skip to content

Add AccessibilityInfo.getContrastLevel and contrastLevelChanged on Android - #59181

Open
camilopires wants to merge 1 commit into
react:mainfrom
camilopires:a11y/android-contrast-level
Open

camilopires wants to merge 1 commit into
react:mainfrom
camilopires:a11y/android-contrast-level

Conversation

@camilopires

Copy link
Copy Markdown
Contributor

Summary:

Android 14 (API 34) added a system contrast level (Settings → Accessibility → Color and motion → Contrast), from -1 to 1, read with UiModeManager.getContrast(). It is Android's equivalent of iOS Increase Contrast, which React Native already exposes as isDarkerSystemColorsEnabled(). The existing Android method, isHighTextContrastEnabled(), reads a different setting that only changes how text is drawn.

This adds AccessibilityInfo.getContrastLevel(): Promise<number> and a numeric contrastLevelChanged event, for Android only.

  • A ContrastChangeListener is registered while the app is resumed, and removed on pause and in invalidate().
  • The value is read again on resume, because registering doesn't report the current value.
  • The listener is created lazily, so older Android versions never load the API 34 interface.
  • On Android before 14 and on iOS, the method resolves to 0.
  • The TypeScript declarations add an addEventListener overload, because this event's payload is a number rather than a boolean.

RNTester gets a small example that shows the value and the last event's payload.

Discussion: react-native-community/discussions-and-proposals#1026

Changelog:

[ANDROID] [ADDED] - AccessibilityInfo.getContrastLevel() and contrastLevelChanged (Android 14+ contrast level)

Test Plan:

  • yarn jest packages/react-native/Libraries/Components/AccessibilityInfo: all tests pass
  • yarn flow-check: 0 errors
  • yarn lint: passes
  • yarn build-types --validate: API snapshot up to date
  • yarn test-generated-typescript and yarn test-typescript-legacy: pass
  • yarn format-check-kotlin: passes
  • RNTester builds: ./gradlew :packages:rn-tester:android:app:assembleDebug

RNTester on an Android 16 (API 36) emulator:

  • Getter: adb shell settings put secure contrast_level with 0, 0.5, 1.0 and -0.5 gave "Contrast level is 0." / "0.5." / "1." / "-0.5."
  • Events: Android recreates the activity when the contrast changes, so I logged the listener temporarily, locally and not in this PR. Setting 0.25, -0.75 and 0.0 logged contrastLevelChanged with exactly 0.25, -0.75 and 0, all in the same process.
  • Changed while in the background: set 0.75, then brought the app back. The row showed "Contrast level is 0.75."

RNTester on an Android 10 (API 29) emulator: "Contrast level is 0.", with no crashes across launch and resume.

…droid

Android 14 (API 34) exposes the system contrast level, from -1 to 1, through
UiModeManager.getContrast(). It is the Android equivalent of Increase
Contrast on iOS; isHighTextContrastEnabled reads a different setting that
only changes how text is drawn. Register a ContrastChangeListener while the
app is resumed and read the value again on resume. Earlier versions and iOS
resolve to 0.

Adds Jest tests for the getter and the numeric event, and an RNTester
example that shows the value and the last event.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@meta-cla

meta-cla Bot commented Oct 18, 2026

Copy link
Copy Markdown

Hi @camilopires!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions

Copy link
Copy Markdown

Warning

JavaScript API change detected

This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API.

  • Please include a clear changelog message.
  • This change will be subject to additional review.

This change was flagged as: POTENTIALLY_BREAKING

@meta-cla

meta-cla Bot commented Oct 18, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 18, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 18, 2026
@meta-codesync

meta-codesync Bot commented Oct 19, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D126038114.

This branch has not been deployed

No deployments
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. 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.

1 participant