Skip to content

Fix Android text size on displays with a different density - #57935

Open
matinzd wants to merge 4 commits into
react:mainfrom
matinzd:feat-per-surface-text-scale-android
Open

Fix Android text size on displays with a different density#57935
matinzd wants to merge 4 commits into
react:mainfrom
matinzd:feat-per-surface-text-scale-android

Conversation

@matinzd

@matinzd matinzd commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes Android text rendering on secondary displays with a different density from the primary display.

Previously, text could render too large and overflow its layout because Fabric used the current display's density, while the Java text pipeline used the primary display's density.

The change makes the text pipeline use the density of the display where the surface is actually rendered.

For example, on a device with a 2.625x primary display and a 1.0x external display, a 16sp label could be laid out as 42px but mounted into a 16px box. With this change, both measurement and rendering use the 1.0x display density, so the text fits correctly.

This applies to scenarios such as:

  • Samsung DeX
  • Desktop mode
  • External monitors
  • Freeform windows
  • Emulator virtual displays

On single-display devices, behavior remains unchanged.

The fix is behind enablePerSurfaceTextScaleAndroid and is off by default.

Related: #57183, #56129, #56894, #55659, and the discussion on #56895.

Changelog

[Android] [Fixed] - Text now uses the density of the display it is rendered on, preventing oversized and clipped text on displays with different densities.

How to test

  1. Add a secondary display with a different density.
adb emu multidisplay add 1 1920 1080 160 0 # index, width, height, dpi, flags
  1. Flip the default feature flag and regenerate:
# scripts/featureflags/ReactNativeFeatureFlags.config.js
#   enablePerSurfaceTextScaleAndroid: { defaultValue: false -> true
yarn featureflags --update

Test Plan

Verified with unit tests and on a Pixel 9 AVD using a 2.625x primary display and a 1.0x virtual secondary display.

Before: text was rendered too large and clipped.

Screen.Recording.2026-08-13.at.09.25.29.mov

After: text renders at the correct size and fits within its layout.

Screen.Recording.2026-08-13.at.11.39.00.mov

Primary display: unchanged.

@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 Aug 13, 2026
@github-actions

Copy link
Copy Markdown

Caution

Missing Changelog

Please add a Changelog to your PR description. See Changelog format

[ANDROID] [FIXED] - Measure and draw text at the surface's display density, not the primary display's
@matinzd
matinzd force-pushed the feat-per-surface-text-scale-android branch from 8d247ca to c743f86 Compare August 13, 2026 15:01
@matinzd
matinzd marked this pull request as ready for review August 13, 2026 15:29
@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 Aug 13, 2026
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