Skip to content

Commit eeaa7cd

Browse files
committed
fix(android): use window display metrics for dp <-> px conversion in PixelUtil
PixelUtil is the dp <-> px conversion the layout engine uses. Reading the screen display metrics returns the primary display's density, which is incorrect when the activity is on a secondary display (Samsung DeX, desktop windowing, virtual displays via am start --display N). The resulting density mismatch makes Fabric lay out content at the wrong scale, leaving the visible region clipped to a fraction of the activity window and rendering text at sub-pixel positions. Reverts the four call sites changed in #53523 back to getWindowDisplayMetrics, restoring 0.81 behaviour on secondary displays. Single-display behaviour is unchanged because window and screen metrics match in that case. Fixes #56894 (relates to #55659). Changelog: [ANDROID] [FIXED] - Use window display metrics in PixelUtil so layout scales correctly on secondary displays / desktop mode / freeform windows.
1 parent f5bd86c commit eeaa7cd

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/PixelUtil.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public object PixelUtil {
2222
return TypedValue.applyDimension(
2323
TypedValue.COMPLEX_UNIT_DIP,
2424
value,
25-
DisplayMetricsHolder.getScreenDisplayMetrics(),
25+
DisplayMetricsHolder.getWindowDisplayMetrics(),
2626
)
2727
}
2828

@@ -40,7 +40,7 @@ public object PixelUtil {
4040
return Float.NaN
4141
}
4242

43-
val displayMetrics = DisplayMetricsHolder.getScreenDisplayMetrics()
43+
val displayMetrics = DisplayMetricsHolder.getWindowDisplayMetrics()
4444
val scaledValue = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, value, displayMetrics)
4545

4646
if (maxFontScale >= 1) {
@@ -63,13 +63,13 @@ public object PixelUtil {
6363
return Float.NaN
6464
}
6565

66-
return value / DisplayMetricsHolder.getScreenDisplayMetrics().density
66+
return value / DisplayMetricsHolder.getWindowDisplayMetrics().density
6767
}
6868

6969
/** @return [Float] that represents the density of the display metrics for device screen. */
7070
@JvmStatic
7171
public fun getDisplayMetricDensity(): Float =
72-
DisplayMetricsHolder.getScreenDisplayMetrics().density
72+
DisplayMetricsHolder.getWindowDisplayMetrics().density
7373

7474
/* Kotlin extensions */
7575
public fun Int.dpToPx(): Float = toPixelFromDIP(this.toFloat())

0 commit comments

Comments
 (0)