[Android] Dimensions.get('screen').scale reports primary display density on secondary displays, breaking Fabric layout
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C++
- Star
- 127k
- Fork
- 25.3k
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 4
Mô tả
Description
On Android, when a React Native activity runs on a secondary display (Samsung DeX, external monitor via desktop mode, ChromeOS desktop windowing, virtual/emulator display via am start --display N), the activity renders at the wrong scale. Content is laid out as if the surface were larger than the activity window, the visible region is a fraction of the window with the rest left black, and text rendering is sub-pixel-blurry.
Dimensions.get('window') and useWindowDimensions() report the activity's actual display correctly. Only Dimensions.get('screen').scale is wrong: it reports the device's primary-display density regardless of which display the activity is on.
window: { width: 1600, height: 720, scale: 1.5 } ← matches the activity's display
screen: { width: 800, height: 360, scale: 3 } ← primary display's scale
Steps to reproduce
- Boot a phone-form-factor AVD (verified on Pixel 9 Pro, API 36).
- Attach a virtual secondary display at a different density than the primary (Pixel 9 Pro is 3.0×, 240dpi on the secondary is enough):
adb emu multidisplay add 1 2400 1080 240 0 - Install the reproducer, start Metro, launch onto the secondary display:
cd ReproducerApp && npm install && npm run android && npm start & adb shell am force-stop com.reproducerapp adb shell am start -n com.reproducerapp/.MainActivity --display 3
Expected: screen.scale === window.scale when the activity is on a single display.
Actual: screen.scale is the primary's density; the React surface lays out at the primary's scale into a window that doesn't have that scale.
React Native Version
0.85.3
Affected Platforms
Runtime - Android
Areas
Fabric - The New Renderer, Bridgeless - The New Initialization Flow
Output of npx @react-native-community/cli info
System:
OS: macOS 26.3.1
CPU: (14) arm64 Apple M4 Pro
Memory: 506.70 MB / 48.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 24.13.0
path: /Users/douwe/.nvm/versions/node/v24.13.0/bin/node
Yarn:
version: 1.22.22
path: /opt/homebrew/bin/yarn
npm:
version: 11.6.2
path: /Users/douwe/.nvm/versions/node/v24.13.0/bin/npm
Watchman:
version: 2025.05.26.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.16.2
path: /opt/homebrew/bin/pod
SDKs:
Android SDK:
API Levels:
- "31"
- "32"
- "33"
- "34"
- "35"
- "36"
Build Tools:
- 30.0.3
- 34.0.0
- 35.0.0
- 36.0.0
- 36.1.0
Android NDK: Not Found
IDEs:
Android Studio: 2025.3 AI-253.29346.138.2531.14876573
Languages:
Java:
version: 21.0.10
path: /usr/bin/javac
npmPackages:
"@react-native-community/cli":
installed: 20.1.0
wanted: 20.1.0
react:
installed: 19.2.3
wanted: 19.2.3
react-native:
installed: 0.85.3
wanted: 0.85.3
Android:
hermesEnabled: true
newArchEnabled: true
Stacktrace or Logs
adb logcat from the reproducer on the secondary display (2400x1080 @ 240dpi):
ReactNativeJS: '[repro] Dimensions.initial', '{"window":{"width":1600,"height":720,"scale":1.5,"fontScale":1},"screen":{"width":800,"height":360,"scale":3,"fontScale":1}}'
MANDATORY Reproducer
https://github.com/DouweBos/rn-secondary-display-repro
Screenshots and Videos
2400×1080 @ 240dpi secondary — cut off text, surface laid out at the wrong density:

Same with an app-side workaround that overwrites DisplayMetricsHolder with the activity's actual metrics — screen.scale matches window.scale, text renders crisply:

Related: #55659.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với rn-secondary-display-repro bắt buộc và tái hiện sự không khớp bằng các lệnh adb emu và am start được liệt kê. Theo dõi đường đi Android điền dữ liệu cho DisplayMetricsHolder và so sánh các metric của nó với metric display của activity. Hoàn thành khi Dimensions.get('screen').scale khớp với window.scale trên một display phụ duy nhất và surface Fabric được render ở mật độ chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- android, react-native
- Lĩnh vực
- mobile
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 55/100