Repository navigation
Add AccessibilityInfo.getContrastLevel and contrastLevelChanged on Android - #59181
camilopires wants to merge 1 commit into
Conversation
…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>
|
Hi @camilopires! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D126038114. |
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 asisDarkerSystemColorsEnabled(). The existing Android method,isHighTextContrastEnabled(), reads a different setting that only changes how text is drawn.This adds
AccessibilityInfo.getContrastLevel(): Promise<number>and a numericcontrastLevelChangedevent, for Android only.ContrastChangeListeneris registered while the app is resumed, and removed on pause and ininvalidate().0.addEventListeneroverload, 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()andcontrastLevelChanged(Android 14+ contrast level)Test Plan:
yarn jest packages/react-native/Libraries/Components/AccessibilityInfo: all tests passyarn flow-check: 0 errorsyarn lint: passesyarn build-types --validate: API snapshot up to dateyarn test-generated-typescriptandyarn test-typescript-legacy: passyarn format-check-kotlin: passes./gradlew :packages:rn-tester:android:app:assembleDebugRNTester on an Android 16 (API 36) emulator:
adb shell settings put secure contrast_levelwith 0, 0.5, 1.0 and -0.5 gave "Contrast level is 0." / "0.5." / "1." / "-0.5."contrastLevelChangedwith exactly 0.25, -0.75 and 0, all in the same process.RNTester on an Android 10 (API 29) emulator: "Contrast level is 0.", with no crashes across launch and resume.