Skip to content

Measure text at the window's density on Android (#59087) - #59087

Closed
brunocramos wants to merge 1 commit into
react:mainfrom
brunocramos:export-D123975873
Closed

brunocramos wants to merge 1 commit into
react:mainfrom
brunocramos:export-D123975873

Conversation

@brunocramos

@brunocramos brunocramos commented Oct 14, 2026 •

Copy link
Copy Markdown

Summary:

DisplayMetricsHolder.initDisplayMetrics() takes density and densityDpi from Display.getRealMetrics(), the physical display, but scaledDensity from the window's configuration. When a window renders at a different density than its display, text is measured at one density and laid out at the other, so it comes out clipped or oversized.

With the new useWindowDensityForDisplayMetricsAndroid feature flag on, the screen metrics keep the window's density and densityDpi and take only the screen size from the display. The flag is off by default, so nothing changes for apps that don't turn it on. initDisplayMetrics reads the flag only when the window's density differs from the display's, so in the usual case it doesn't touch feature flags, and apps can still set their flags after calling it.

How to use: return true from your app's feature flag overrides, before React Native starts:

override fun useWindowDensityForDisplayMetricsAndroid(): Boolean = true

Changelog:
[Internal]

Reviewed By: javache

Differential Revision: D123975873

@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 14, 2026
@meta-codesync

meta-codesync Bot commented Oct 14, 2026

Copy link
Copy Markdown

@brunocramos has exported this pull request. If you are a Meta employee, you can view the originating Diff in D123975873.

@meta-codesync meta-codesync Bot changed the title Measure text at the window's density on Android Measure text at the window's density on Android (#59087) Oct 14, 2026
brunocramos pushed a commit to brunocramos/react-native that referenced this pull request Oct 14, 2026
Summary:

`DisplayMetricsHolder.initDisplayMetrics()` takes `density` and `densityDpi` from `Display.getRealMetrics()`, the physical display, but `scaledDensity` from the window's configuration. When a window renders at a different density than its display, text is measured at one density and laid out at the other, so it comes out clipped or oversized.

With the new `useWindowDensityForDisplayMetricsAndroid` feature flag on, the screen metrics keep the window's `density` and `densityDpi` and take only the screen size from the display. The flag is off by default, so nothing changes for apps that don't turn it on. `initDisplayMetrics` reads the flag only when the window's density differs from the display's, so in the usual case it doesn't touch feature flags, and apps can still set their flags after calling it.

**How to use:** return `true` from your app's feature flag overrides, before React Native starts:

```
override fun useWindowDensityForDisplayMetricsAndroid(): Boolean = true
```

Changelog:
[Internal]

Reviewed By: javache

Differential Revision: D123975873
Summary:

`DisplayMetricsHolder.initDisplayMetrics()` takes `density` and `densityDpi` from `Display.getRealMetrics()`, the physical display, but `scaledDensity` from the window's configuration. When a window renders at a different density than its display, text is measured at one density and laid out at the other, so it comes out clipped or oversized.

With the new `useWindowDensityForDisplayMetricsAndroid` feature flag on, the screen metrics keep the window's `density` and `densityDpi` and take only the screen size from the display. The flag is off by default, so nothing changes for apps that don't turn it on. `initDisplayMetrics` reads the flag only when the window's density differs from the display's, so in the usual case it doesn't touch feature flags, and apps can still set their flags after calling it.

**How to use:** return `true` from your app's feature flag overrides, before React Native starts:

```
override fun useWindowDensityForDisplayMetricsAndroid(): Boolean = true
```

Changelog:
[Internal]

Reviewed By: javache

Differential Revision: D123975873
@meta-codesync meta-codesync Bot closed this in 43c9b88 Oct 14, 2026
@meta-codesync meta-codesync Bot added the Merged This PR has been merged. label Oct 14, 2026
@meta-codesync

meta-codesync Bot commented Oct 14, 2026

Copy link
Copy Markdown

This pull request has been merged in 43c9b88.

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. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant