Commit aa34674
committed
fix(android): use the context's display for display metrics, not the device default
DisplayMetricsHolder.initDisplayMetrics populated screenDisplayMetrics by
calling getRealMetrics on WindowManager.defaultDisplay, which is always
the device's primary display regardless of which display the activity is
running on. On a secondary display (Samsung DeX, desktop mode, external
monitor, freeform window) that reports the primary display's density and
dimensions, so PixelUtil's dp <-> px conversion — and therefore Fabric's
layout — scales content for the wrong display. The visible region ends
up clipped to a fraction of the activity window and text renders at
sub-pixel positions.
Use Context.getDisplay() (API 30+) so the metrics come from the display
the context is actually associated with, falling back to defaultDisplay
on older API levels. Also pass the view's own context (not the
application context) from ReactRootView, so the context is associated
with the activity's display.
Fixes #56894 (also tracked in #55659).
Changelog: [ANDROID] [FIXED] - Display metrics now reflect the activity's display instead of the device's default display, fixing layout scaling on secondary displays / desktop mode / freeform windows.1 parent 60d8b28 commit aa34674
2 files changed
Lines changed: 17 additions & 5 deletions
File tree
- packages/react-native/ReactAndroid/src/main/java/com/facebook/react
- uimanager
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
932 | 932 | | |
933 | 933 | | |
934 | 934 | | |
935 | | - | |
| 935 | + | |
936 | 936 | | |
937 | 937 | | |
938 | 938 | | |
| |||
1007 | 1007 | | |
1008 | 1008 | | |
1009 | 1009 | | |
1010 | | - | |
| 1010 | + | |
1011 | 1011 | | |
1012 | 1012 | | |
1013 | 1013 | | |
| |||
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
57 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
58 | 70 | | |
59 | | - | |
| 71 | + | |
60 | 72 | | |
61 | 73 | | |
62 | 74 | | |
| |||
0 commit comments