Repository navigation
Support AccessibilityInfo.isBoldTextEnabled and boldTextChanged on Android - #59176
camilopires wants to merge 8 commits into
Conversation
|
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
left a comment
There was a problem hiding this comment.
Please rebase and update C++ snapshots
…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>
The Android NativeAccessibilityInfo spec's isBoldTextEnabled now appears in the generated spec, so it shows up in the Apple snapshots. Generated with Doxygen 1.16.1 and Python 3.12, as in validate-cxx-api-snapshots.yml. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AccessibilityInfoModuleTest now drives the module through real configuration changes: a change sends boldTextDidChange once, turning bold text off sends false, nothing is sent while paused, after resuming twice and pausing once, or after invalidate, a change made while paused is sent on resume, and before Android 12 the value is always false and no event is sent. Removing the callback registration makes the change tests fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
21ed1c0 to
f3927c1
Compare
|
Rebased on main and updated the C++ API snapshots ( |
Visual regressionNo visual differences at android: no capture |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Read the font weight adjustment from `newConfig` instead of the Application's resources, register the callbacks only on Android 12 (API 31) and later, and rename the companion helper to isBoldFontWeightAdjustment. Test with a context that records each registration, including on API 30. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
invalidate() can run off the main thread. Remove the lifecycle listener first, set an invalidated flag that resume, registration and queued configuration callbacks check, and post the unregister to the main thread when needed, logging if the post fails. Mark the cached bold text value @volatile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI compiles tests with -PenableWarningsAsErrors=true, and BridgeReactContext is deprecated, so the test failed to compile there. Suppress the deprecation for the file, as DeviceInfoModuleTest and the other tests that use BridgeReactContext do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
RNTester's "is enabled" rows (bold text, reduce motion, accessibility service and the rest) now read their starting value, follow the event's value instead of flipping on every event, and show "Unavailable: …" if the starting read rejects. That fixes the same stale state on every row, not only bold text.
After a review pass, the module also uses the configuration Android passes to
onConfigurationChanged(Android 12+), registers its callbacks only on Android 12+, and ininvalidate()removes them on the UI thread, ignoring callbacks queued before teardown. Robolectric tests cover these (18 tests).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.