Repository navigation
Support AccessibilityInfo.isBoldTextEnabled and boldTextChanged on Android - #59176
camilopires wants to merge 1 commit into
Conversation
…droid Android 12 (API 31) exposes the Bold Text setting as Configuration.fontWeightAdjustment. Read it, listen for configuration changes, and emit boldTextChanged. Earlier versions still resolve to false. If the native module predates this change, isBoldTextEnabled still resolves to false. Adds Kotlin unit tests for the adjustment values, Jest tests for the getter and the event wiring, and shows the Bold Text examples on Android in RNTester. 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! |
Summary:
On Android,
AccessibilityInfo.isBoldTextEnabled()always resolves tofalse, andboldTextChangednever fires. Android 12 (API 31) added a Bold Text setting, exposed asConfiguration.fontWeightAdjustment. Apps currently can't detect it, even though it changes text layout (for example #54931).This reads
fontWeightAdjustmenton Android 12 and later and treats a positive adjustment as Bold Text. A negative value means lighter text, andFONT_WEIGHT_ADJUSTMENT_UNDEFINEDmeans the value isn't known; neither counts. The module listens for configuration changes while the app is resumed, reads the value again on resume, and emitsboldTextChanged. On Android versions before 12, the method still resolves tofalse. If the native module predates this change,isBoldTextEnabledstill resolves tofalserather than rejecting.RNTester now shows the Bold Text examples on Android.
Discussion: react-native-community/discussions-and-proposals#477
Changelog:
[ANDROID] [ADDED] -
AccessibilityInfo.isBoldTextEnabled()andboldTextChangednow work on Android 12 and laterTest 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:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.modules.accessibilityinfo.*": 4 new tests pass, covering adjustments of 300, 0, -100 and undefinedRNTester on an Android 16 (API 36) emulator, Accessibility → "Check if the display options are enabled":
adb shell settings put secure font_weight_adjustment 300→ "Bold Text is enabled."… 0→ "Bold Text is disabled."… -100(lighter text) → "Bold Text is disabled."fontWeightAdjustmentto RNTester'sconfigChanges, locally and not in this PR, so the activity isn't recreated. Switching 0 → 300 → 0 updated the row in place in the same process.RNTester on an Android 10 (API 29) emulator: the row shows "Bold Text is disabled." even with the setting at 300, and there were no crashes across launch and resume.
Not run: Android 12–13 (API 31–33) devices. The
SDK_INTguard covers them.