Skip to content

Support AccessibilityInfo.isBoldTextEnabled and boldTextChanged on Android - #59176

Open
camilopires wants to merge 8 commits into
react:mainfrom
camilopires:a11y/android-bold-text
Open

camilopires wants to merge 8 commits into
react:mainfrom
camilopires:a11y/android-bold-text

Conversation

@camilopires

@camilopires camilopires commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

On Android, AccessibilityInfo.isBoldTextEnabled() always resolves to false, and boldTextChanged never fires. Android 12 (API 31) added a Bold Text setting, exposed as Configuration.fontWeightAdjustment. Apps currently can't detect it, even though it changes text layout (for example #54931).

This reads fontWeightAdjustment on Android 12 and later and treats a positive adjustment as Bold Text. A negative value means lighter text, and FONT_WEIGHT_ADJUSTMENT_UNDEFINED means 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 emits boldTextChanged. On Android versions before 12, the method still resolves to false. If the native module predates this change, isBoldTextEnabled still resolves to false rather 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 in invalidate() 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() and boldTextChanged now work on Android 12 and later

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
  • ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.modules.accessibilityinfo.*": 4 new tests pass, covering adjustments of 300, 0, -100 and undefined

RNTester 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."
  • Live event without activity recreation. I temporarily added fontWeightAdjustment to RNTester's configChanges, 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.
  • Changed while in the background: set 300, then brought the app back. The row showed "enabled" 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_INT guard covers them.

@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

@javache javache left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase and update C++ snapshots

camilopires and others added 3 commits October 24, 2026 00:48
…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>
@camilopires
camilopires force-pushed the a11y/android-bold-text branch from 21ed1c0 to f3927c1 Compare October 24, 2026 00:08
@camilopires

Copy link
Copy Markdown
Contributor Author

Rebased on main and updated the C++ API snapshots (scripts/cxx-api, generated with Doxygen 1.16.1 as in CI). I also added Robolectric tests for the bold text listener: events on configuration changes, nothing while paused or after invalidate, catch-up on resume, and always false before Android 12.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at a0e7258f1288.

android: no capture

camilopires and others added 5 commits October 24, 2026 14:37
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>

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.

2 participants