Skip to content

fix(mobile): keep the app's state and layout when entering split screen on Android - #36977

Merged
AmoabaKelvin merged 3 commits into
mainfrom
android-split-screen-36305
Nov 1, 2026
Merged

AmoabaKelvin merged 3 commits into
mainfrom
android-split-screen-36305

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 0 0 0 0
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​104 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​104

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

  • Before: One UI gives a split-screen pane its own density (360 → 321 dpi on a Z Fold7). density was missing from MainActivity's configChanges, so Android relaunched the activity on every enter and leave. Even after a relaunch, React Native laid the pane out at the wrong scale. Its DisplayMetricsHolder (which PixelUtil uses for text measurement and Dimensions events) 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, in onConfigurationChanged, and in the root view's layout listener whenever the rotation changes.
  • After: a new Expo config plugin, mobile/plugins/android-window-density.js, adds density to configChanges and patches the generated MainActivity.kt:
    • onResume and onConfigurationChanged re-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.
    • A pre-draw check re-seeds again and requests a layout if React Native's rotation listener has put the application density back. Pre-draw runs after every layout listener, so it works whatever order the listeners were added in.
  • Like the repo's other template patches (ios-scene-lifecycle.js), the plugin fails prebuild if Expo's MainActivity template changes, rather than shipping a half-patched activity.

Why

  • Declaring density alone stops the restart, but it leaves the squeezed layout described in the issue's table. Re-seeding is needed as well.
  • The re-seed has to happen before React Native measures. A version that only corrected at pre-draw was tested and still clipped labels after a rotation: Fabric measures text right after React Native's own configuration-change re-seed and caches the result. That's why the fix keeps the onResume/onConfigurationChanged re-seeds and adds the pre-draw check only for the re-seed React Native does after measuring.
  • The real fix belongs in React Native: ReactHostImpl.onConfigurationChanged is handed the activity but reads the application context. React Native's Android code ships prebuilt, so it can't be patched from patches/. Upstream main still does the same thing, so the generated activity is the layer we own.
  • Compared with the open plugin approaches: fix(android): enable split-screen/multi-window for Samsung devices #9190 adds density only. 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 keeps Dimensions.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 mount id 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):

split-36305-cold-start-rotated.png

Testing

  • expo prebuild --clean --platform android and ./gradlew assembleDebug on main and on this branch. I checked the generated MainActivity.kt and the configChanges bit 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_called shows no relaunch on this branch.

  • check:code-quality:changed and check:react-doctor:changed pass; test-dependents.sh lists 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:

  • The first version's one-shot rotation listener missed a cold start or a 180° flip at a non-zero rotation. It's now the pre-draw check.
  • The re-seeded metrics are now built before they're published, since text measurement reads them off the UI thread.

Not fixed, both in React Native's prebuilt code:

  • Fabric only re-sends a 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.
  • A Modal recomputes its bounds only when its pixel size changes. Entering or leaving split always changes the size.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 797ad4e6-2438-4111-8e59-f3803d847b63
Commits

Reviewing files that changed from the base of the PR and between 2b7f52f and 94c04dc.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d07fa78e-25f1-430c-8ae4-cf52d3d21e94
Commits

Reviewing files that changed from the base of the PR and between 321574a and 2b7f52f.

Files selected for processing: 2
  • mobile/app.json
  • mobile/plugins/android-window-density.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

The Expo configuration now registers an Android window-density plugin. The plugin adds density to the activity’s android:configChanges when it is absent and patches Kotlin MainActivity code to update React Native display metrics on resume and configuration changes. A pre-draw check refreshes held metrics when their density differs from the activity’s and requests layout. The plugin skips an already-marked activity and reports errors for unsupported or unexpected activity templates.

Severity of issue fixed: Medium

Merge Risk: Minimal · previous review 2b7f5

No confirmed issue blocks merging. The effect of a density change without a pixel-size change remains unverified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preserving Android app state and layout during split-screen transitions.
Description check Passed The description covers the required sections, including the user impact, technical changes, rationale, linked issue, visual proof, testing, limitations, and compatibility considerations.
Linked Issues check Passed Issue #36305 requires preventing the activity restart when the split-pane density changes and correcting the pane layout. The PR registers ./plugins/android-window-density.js in mobile/app.json. T…
Out of Scope Changes check Passed The PR changes only the Android app plugin list and adds one Android window-density config plugin. These changes directly implement issue #36305. The plugin's template guards and metric handling suppo…
Full details: Linked Issues check

Explanation

Issue #36305 requires preventing the activity restart when the split-pane density changes and correcting the pane layout. The PR registers ./plugins/android-window-density.js in mobile/app.json. The plugin adds density to android:configChanges. It patches MainActivity.kt to reseed DisplayMetricsHolder from activity resources in onResume and onConfigurationChanged, and after React Native rotation reseeds during pre-draw. It preserves physical display dimensions for screen metrics. The reported prebuild, APK manifest, build, and emulator checks cover the implementation. No unit test is required for the generated Kotlin text because the PR documents compile and behavior checks.

Full details: Out of Scope Changes check

Explanation

The PR changes only the Android app plugin list and adds one Android window-density config plugin. These changes directly implement issue #36305. The plugin's template guards and metric handling support reliable application of the fix. No unrelated product, platform, remote/SSH, or workspace changes are present in the reviewed diff.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Android split screen on One UI restarts Orca Mobile, or squeezes it once the restart is prevented

1 participant