Repository navigation
fix(mobile): keep the app's state and layout when entering split screen on Android - #36977
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
…he app One UI gives a split-screen pane its own density. Android recreated MainActivity on that change, and React Native seeds its display metrics from the application context, which keeps the full-screen density, so the pane was laid out at the wrong scale. A config plugin declares density in configChanges and re-seeds the metrics from the activity.
…raws A one-shot listener added on configuration change missed a cold start or a 180-degree flip at a non-zero rotation, where React Native's root view re-seeds from the application context without a configuration change.
Text measurement reads the holder off the UI thread, so build the pane-density screen metrics before publishing them.
2b7f52f to
94c04dc
Compare
ELI5
On Samsung foldables, putting Orca Mobile in split screen next to another app restarted the app's screen, so the open session closed and photo attach broke. When the restart was stopped, the app was drawn at the wrong scale: an empty band at the edge and cut-off button labels ("Canc", "Sav"). Now the app stays put when you enter or leave split screen and fills its half of the screen properly.
What Changed
densitywas missing fromMainActivity'sconfigChanges, so Android relaunched the activity on every enter and leave. Even after a relaunch, React Native laid the pane out at the wrong scale. ItsDisplayMetricsHolder(whichPixelUtiluses for text measurement andDimensionsevents) is always seeded from the application context, and that context keeps the full-screen density. React Native re-seeds it from there at three points: when it creates the root view, inonConfigurationChanged, and in the root view's layout listener whenever the rotation changes.mobile/plugins/android-window-density.js, addsdensitytoconfigChangesand patches the generatedMainActivity.kt:onResumeandonConfigurationChangedre-seed the holder from the activity's own resources after React Native has, so the next measure uses the pane's density. Screen metrics keep the real display size and take the window's density. On a normal full-screen phone the two densities match, so nothing changes there.ios-scene-lifecycle.js), the plugin fails prebuild if Expo'sMainActivitytemplate changes, rather than shipping a half-patched activity.Why
densityalone stops the restart, but it leaves the squeezed layout described in the issue's table. Re-seeding is needed as well.onResume/onConfigurationChangedre-seeds and adds the pre-draw check only for the re-seed React Native does after measuring.ReactHostImpl.onConfigurationChangedis handed the activity but reads the application context. React Native's Android code ships prebuilt, so it can't be patched frompatches/. Upstreammainstill does the same thing, so the generated activity is the layer we own.densityonly. fix(mobile): render correctly in Android multi-window density mismatch #20853 re-seeds on create, resume and configuration change, and sets the screen metrics to the window size. This PR also covers React Native's rotation re-seed (a cold start or rotation inside a split pane), and it keepsDimensions.get('screen')the physical screen.Linked Issue
Fixes #36305
Visual Proof
Android 15 emulator. Orca runs on a secondary display, and the script changes only that display's density, from 420 to 375 dpi. The process and application density stay put, which is the same mismatch One UI creates. The script types a draft, taps a button twice, enters the pane density, rotates, rotates back and leaves. The
mountid shows whether the screen was remounted.Before (main): entering the split density relaunches the activity. The mount id changes, the draft and tap count are lost, and the remounted pane has an empty band and clipped labels.
split-36305-before.mp4
After: same mount id, draft and taps through every step. The pane fills the window and labels are whole at the pane density, while rotated, and back at full size.
split-36305-after.mp4
Cold start already rotated into the split density, before (left) and after (right):
Testing
expo prebuild --clean --platform androidand./gradlew assembleDebugon main and on this branch. I checked the generatedMainActivity.ktand theconfigChangesbit in the APK manifest (0x2fb4→0x3fb4). PR CI does not build Android, so this local build is the compile check.Emulator (Android 15, debug dev client, temporary probe route that isn't committed): I entered and left the pane density, rotated inside it, cold-started at the pane density at rotation 0 and 1, and opened the real Settings screen at the pane density. Main relaunched and squeezed in every case; this branch kept state and filled the pane.
wm_on_destroy_calledshows no relaunch on this branch.check:code-quality:changedandcheck:react-doctor:changedpass;test-dependents.shlists no affected tests.Not tested on a real Samsung device; the reporter's Fold7 numbers in the issue match what the emulator shows.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
No unit test: the plugin's output is Kotlin text. A test of the string would only restate it, and the real check is that prebuild output compiles and behaves, which the steps above cover.
AI Disclosure
Review
Two review rounds (Codex and Claude); round 2 came back clean. Accepted and fixed:
Not fixed, both in React Native's prebuilt code:
TextInput's padding when its dp value changes. A mounted input keeps its old pixel padding (1–2 px at 360 → 321 dpi) until it remounts.Modalrecomputes its bounds only when its pixel size changes. Entering or leaving split always changes the size.Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)