Skip to content

fix(mobile): keep Android layout intact in Samsung DeX / external-display windows - #16018

Open
phs2131 wants to merge 3 commits into
stablyai:mainfrom
phs2131:fix/mobile-android-dex-layout
Open

phs2131 wants to merge 3 commits into
stablyai:mainfrom
phs2131:fix/mobile-android-dex-layout

Conversation

@phs2131

@phs2131 phs2131 commented Aug 23, 2026 •

Copy link
Copy Markdown

ELI5

On a Galaxy phone in Samsung DeX the Orca app only painted a phone-sized box in the top-left corner of its window, and "restarted" whenever the window was resized or DeX was toggled. The app now fills the window, survives resizes, and works with a hardware keyboard.

What Changed

All under mobile/:

  • plugins/android-desktop-mode.js (new, registered in app.json): manifest attributes (resizeableActivity, full configChanges incl. density|smallestScreenSize, Samsung keepalive.density / multidisplay.keep_process_alive meta-data) and a withMainActivity hook that points DisplayMetricsHolder at the Activity's display on create / configuration change / resume, requests a decor relayout, and emits the RN didUpdateDimensions event. Pure, idempotent transforms with unit tests.
  • src/layout/window-bounds*.ts(x): WindowBoundsProvider measures the real root bounds (Android useWindowDimensions reports the display, not the freeform window); responsive layout uses window class with ±24 dp hysteresis; drawers, bottom sheets, onboarding pager and file preview size from measured bounds.
  • Terminal WebView: injected viewport observer refits on width/height/DPR changes; text-scale no longer resizes xterm to innerWidth; refit triggers centralised.
  • Hardware keyboard: Esc no longer leaves the session once a hardware keyboard is detected; focus/keyboard-avoidance no longer assumes an IME.
  • docs/dex-mode-layout-design.md: investigation notes, mechanism with file/line evidence, emulator reproduction recipe.

No version bump; app.json only gains the plugin entry.

Why

Linked Issue

Fixes #8592

Visual Proof

Stock API 35 emulator (pixel_7, 420 dpi) with a 1920x1080/160 overlay display, app maximized on that display:

ReactSurfaceView ScreenContentWrapper (what the user sees)
Before 1920×1080 731×411 at (0,0) — phone-sized block, rest is root background
After 1920×1080 1920×1080

Before/after screenshots of that exact setup are attached in a comment below (not committed, per template). Also confirmed on a real Galaxy device in DeX (maximized window fills the monitor; DeX enter/exit no longer restarts the app).

Testing

  • Emulator: before → top-left block; after → fullscreen 1920×1080, freeform 412×732, live resize 1000×700 and maximize all fill the window; phone display (1080×2400) unchanged. Recipe in docs/dex-mode-layout-design.md §A.4/§A.7.

  • Real Galaxy device in Samsung DeX: fixed.

  • pnpm test 3701 passed / 3 skipped, pnpm typecheck, oxlint, oxfmt --check clean (mobile/).

  • Platforms touched: Android only (config plugin is android-scoped; JS changes are platform-neutral and covered by vitest).

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Investigation, implementation and emulator verification were done with Claude (Claude Code, Fable 5) and OpenAI Codex, supervised and verified on a real device by the author.

Review

CodeRabbit round 1: 5 of 8 findings fixed in ebf8d903 with regression tests; 3 rejected with rationale in the threads.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: no new permissions; meta-data/attributes only affect windowing.
  • Cross-platform: Android-only native change; iOS/web untouched. Mobile is the target.
  • Backwards compatibility: configChanges additions mean the Activity is no longer recreated on density/size changes — the new onConfigurationChanged hook plus the existing JS Dimensions listeners cover that path; phone behaviour verified unchanged on the emulator's built-in display.
  • Performance: one extra requestLayout per configuration change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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)

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The mobile app adds Android desktop-mode configuration and Activity display-metrics synchronization. It measures freeform window bounds and uses stable responsive window classes. Terminal WebViews now synchronize dimensions and device pixel ratio with native layout state. Session input handling detects hardware keyboards, routes Escape on back presses, and adjusts keyboard avoidance. Tests cover plugin transforms, layout behavior, viewport updates, and keyboard handling.

Merge Risk: 🟡 Moderate · up to 09716

The Android windowing and layout changes improve DeX sizing and lifecycle continuity, but the current head still has edge cases that can preserve an incorrect layout, remount the app during supported transitions, or accidentally leave a session on the first hardware Escape; narrow medium windows may also render an unusable split view. Merge should wait for these fixes or explicit owner acceptance.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 44 functions across 50 files. (4 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: preserving Android layout behavior in Samsung DeX and external-display windows.
Description check ✅ Passed The description covers all required template sections, including the problem, changes, rationale, linked issue, visual proof, testing, AI disclosure, review notes, compatibility considerations, and ch…
Linked Issues check ✅ Passed The changes directly address the linked issue [#8592] by adding DeX window and density handling, responsive layout updates, resize and repaint support, terminal viewport synchronization, and hardware-…
Out of Scope Changes check ✅ Passed The plugin, layout changes, terminal updates, keyboard handling, documentation, and tests all support the Samsung DeX and external-display objectives in [#8592]. No unrelated code changes are identifi…
Full details: Description check

Explanation

The description covers all required template sections, including the problem, changes, rationale, linked issue, visual proof, testing, AI disclosure, review notes, compatibility considerations, and checklist status.

Full details: Linked Issues check

Explanation

The changes directly address the linked issue [#8592] by adding DeX window and density handling, responsive layout updates, resize and repaint support, terminal viewport synchronization, and hardware-keyboard behavior. The description also reports emulator and real-device verification for compact, maximized, and resized windows.

Full details: Out of Scope Changes check

Explanation

The plugin, layout changes, terminal updates, keyboard handling, documentation, and tests all support the Samsung DeX and external-display objectives in [#8592]. No unrelated code changes are identified.

Full details: Docstring Coverage

Explanation

Docstring coverage is 4.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 44 functions across 50 files. (4 skipped: 3 unsupported, 1 over the file limit.)

  • Fix all pre-merge checks with AI

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (3)
mobile/plugins/android-desktop-mode.js (1)

162-176: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Fail loudly when the super.onCreate(null) anchor is absent.

applyActivityDisplayMetrics throws when the anchor is missing. This hook does not. If a future Expo template changes the onCreate body, String.prototype.replace returns the source unchanged, the plugin writes the same bytes back, and desktop orientation silently stops working. The ORCA_DESKTOP_ORIENTATION marker is also never written, so every prebuild repeats the no-op.

Add the same guard used in applyActivityDisplayMetrics.

♻️ Proposed guard
       let source = await fs.promises.readFile(mainActivityPath, 'utf8')
       if (source.includes('ORCA_DESKTOP_ORIENTATION')) {
         return cfg
       }
+      if (!source.includes('super.onCreate(null)')) {
+        throw new Error('MainActivity.kt is missing the expected super.onCreate(null) call')
+      }
       source = source.replace(

Consider also moving this transform into a pure exported function applied through withMainActivity, like the display-metrics transform. That removes the direct filesystem read and write, makes the ordering explicit against the other MainActivity.kt mod, and makes the branch unit-testable.

mobile/src/terminal/terminal-webview-viewport.test.ts (1)

52-59: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Change the device pixel ratio before firing the listener.

The harness sets devicePixelRatio: 1 and the test never changes it. The assertion dpr: 1 therefore passes even if the injected script reported a hardcoded or stale ratio. Density change is the exact condition this PR targets, so mutate the value first and assert the new one.

💚 Proposed test change
   it('re-fits and reports viewport state when DPR changes', () => {
     const harness = createViewportHarness()
+    harness.setDpr(2)
     harness.fireDprChange()
     expect(harness.applyFitScale).toHaveBeenCalledWith('dpr')
     expect(harness.notify).toHaveBeenCalledWith(
-      expect.objectContaining({ type: 'viewport-changed', dpr: 1 })
+      expect.objectContaining({ type: 'viewport-changed', dpr: 2 })
     )
   })

Expose the setter from the harness:

   return {
     applyFitScale,
     fireDprChange: () => mediaListener(),
+    setDpr: (value: number) => {
+      context.window.devicePixelRatio = value
+    },
     getHeight: (context as { getHeight: () => number }).getHeight,
mobile/src/terminal/use-terminal-layout-refit-triggers.ts (1)

40-56: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Clarify the height-only resize guard. After the no-change return, previous.width === windowWidth means only windowHeight changed. Add a concise comment. Width-originated refits intentionally remain unguarded while the keyboard is visible.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e112bec2-e97b-41a9-b2ba-48e1646da427

📥 Commits

Reviewing files that changed from the base of the PR and between 063b804 and b0f5587a305568bff16f3d1caf619a5bed97f968.

⛔ Files ignored due to path filters (1)
  • mobile/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (54)
  • mobile/README.md
  • mobile/app.json
  • mobile/app/_layout.tsx
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/app/h/_layout.tsx
  • mobile/app/mobile-onboarding.tsx
  • mobile/docs/dex-mode-layout-design.md
  • mobile/plugins/android-desktop-mode.js
  • mobile/plugins/android-desktop-mode.test.js
  • mobile/src/browser/MobileBrowserPane.tsx
  • mobile/src/browser/browser-screencast-request.test.ts
  • mobile/src/browser/mobile-browser-frameless-stream.test.tsx
  • mobile/src/components/RightDrawer.tsx
  • mobile/src/components/bottom-drawer-fill-height.test.ts
  • mobile/src/components/mounted-bottom-drawer.tsx
  • mobile/src/components/right-drawer-panel-width.test.ts
  • mobile/src/files/MobileFilePreviewScreen.tsx
  • mobile/src/layout/responsive-layout-metrics.test.ts
  • mobile/src/layout/responsive-layout-metrics.ts
  • mobile/src/layout/responsive-layout.ts
  • mobile/src/layout/window-bounds-state.test.ts
  • mobile/src/layout/window-bounds-state.ts
  • mobile/src/layout/window-bounds.tsx
  • mobile/src/platform/hardware-keyboard.test.ts
  • mobile/src/platform/hardware-keyboard.ts
  • mobile/src/platform/use-pixel-ratio.ts
  • mobile/src/session/TerminalPaneView.tsx
  • mobile/src/session/session-back-press.test.ts
  • mobile/src/session/session-back-press.ts
  • mobile/src/session/use-terminal-frame-layout.ts
  • mobile/src/terminal/TerminalWebView.tsx
  • mobile/src/terminal/terminal-keyboard-avoidance-webview.test.ts
  • mobile/src/terminal/terminal-live-input.test.ts
  • mobile/src/terminal/terminal-live-input.ts
  • mobile/src/terminal/terminal-viewport-refit-state.ts
  • mobile/src/terminal/terminal-viewport-refit.test.ts
  • mobile/src/terminal/terminal-viewport-refit.ts
  • mobile/src/terminal/terminal-webview-contract.test.ts
  • mobile/src/terminal/terminal-webview-contract.ts
  • mobile/src/terminal/terminal-webview-handle.ts
  • mobile/src/terminal/terminal-webview-html.ts
  • mobile/src/terminal/terminal-webview-messages.ts
  • mobile/src/terminal/terminal-webview-notification-dispatch.test.ts
  • mobile/src/terminal/terminal-webview-notification-dispatch.ts
  • mobile/src/terminal/terminal-webview-reflow.test.ts
  • mobile/src/terminal/terminal-webview-scroll-routing.test.ts
  • mobile/src/terminal/terminal-webview-text-zoom.test.ts
  • mobile/src/terminal/terminal-webview-viewport-injected.ts
  • mobile/src/terminal/terminal-webview-viewport.test.ts
  • mobile/src/terminal/terminal-write-coalescer-boundaries.test.ts
  • mobile/src/terminal/use-terminal-layout-refit-triggers.ts
  • mobile/src/terminal/use-terminal-live-input-commit.ts
  • mobile/src/terminal/use-terminal-live-input-focus.ts
  • mobile/vitest.config.ts
💤 Files with no reviewable changes (1)
  • mobile/src/terminal/terminal-keyboard-avoidance-webview.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread mobile/app/h/_layout.tsx Resolved
Comment thread mobile/docs/dex-mode-layout-design.md Resolved
@phs2131

phs2131 commented Aug 23, 2026

Copy link
Copy Markdown
Author

Nitpicks from the review summary (not inline threads), all addressed in ebf8d903:

  • mobile/plugins/android-desktop-mode.js — Done: the hook is now a pure applyDesktopUnspecifiedOrientation(source) applied through withMainActivity (same pattern as applyActivityDisplayMetrics), throws when super.onCreate(null) is absent, and the withDangerousMod/fs read-write is gone. Covered by 'adds the desktop orientation hook idempotently after the activity metrics hook' and 'fails loudly when the onCreate anchor is missing' in mobile/plugins/android-desktop-mode.test.js.
  • mobile/src/terminal/terminal-webview-viewport.test.ts — Done: the harness in terminal-webview-viewport.test.ts exposes setDpr(), and 're-fits and reports viewport state when DPR changes' now sets 2 before firing the listener and asserts dpr: 2.
  • mobile/src/terminal/use-terminal-layout-refit-triggers.ts — Added a one-line comment above the guard in use-terminal-layout-refit-triggers.ts: a height-only change while the IME is up is the keyboard itself; width changes always refit.

Before/after emulator screenshots (1920×1080/160 dpi overlay display, app maximized) follow in the next comment.

@phs2131

phs2131 commented Aug 23, 2026

Copy link
Copy Markdown
Author
download download

@adelin-b

adelin-b commented Aug 30, 2026 •

Copy link
Copy Markdown

I prepared a rebased and verified version of this PR on current main:

I retried updating the PR source branch with an exact force-with-lease, but GitHub rejected the push because the current identity (adelin-b) has read-only access to stablyai/orca and no push access to phs2131/orca (HTTP 403). The other configured GitHub identity also has read-only access.

The prepared branch:

  • rebases all three commits onto current main;
  • keeps the newer browser-stream module split and bottom-drawer window-handback behavior from main;
  • applies reactive DPR/window-bound handling in the current owning modules;
  • extracts and tests session back handling instead of bypassing the max-lines rule;
  • keeps the current lockfile unchanged;
  • has all 5 review threads resolved.

Latest local verification passed:

  • pnpm --dir mobile lint
  • pnpm --dir mobile format:check
  • pnpm --dir mobile typecheck
  • pnpm --dir mobile test — 486 files passed; 3,928 tests passed; 3 skipped
  • ./node_modules/.bin/tsc --noEmit -p config/tsconfig.node.json

To update this PR safely from an account with access to phs2131/orca:

git fetch https://github.com/adelin-b/orca.git pr-16018-rebased-20260830
git push \
  --force-with-lease=refs/heads/fix/mobile-android-dex-layout:ebf8d903e7d12bedb32dbff89ff4d618decbc548 \
  https://github.com/phs2131/orca.git \
  FETCH_HEAD:refs/heads/fix/mobile-android-dex-layout

The lease pins the current PR head, so the push will fail rather than overwrite any newer author changes. PR CI will start after the source branch is updated.

phs2131 and others added 3 commits August 30, 2026 11:23
…play windows

On Galaxy DeX (and any Android freeform/desktop window on a display whose
density differs from the phone panel) the app rendered as a phone-sized block
in the top-left corner of the window, and entering/leaving DeX or resizing the
window recreated the Activity.

Root causes
- RN 0.83 regression (react/react-native#55659): `PixelUtil.toDIPFromPixel`
  now divides by `DisplayMetricsHolder.getScreenDisplayMetrics().density`, the
  default (phone) display read through the Application context, while the root
  surface and mount path use the Activity's display density. react-native-screens'
  `Screen` reports its size through that helper, so the Stack content is forced
  to `window * (d_window / d_phone)` at (0,0).
- `MainActivity` lacked `resizeableActivity` and `density|smallestScreenSize`
  in `configChanges`, and the Samsung keep-alive metadata, so DeX transitions
  and window drags recreated the Activity (full React remount).
- `useWindowDimensions` reports the display, not the freeform window, on
  Android; xterm WebView fit used `window.innerWidth` and never observed DPR
  changes; hardware-keyboard Esc mapped to hardwareBackPress.

Changes
- New `plugins/android-desktop-mode.js` config plugin: manifest attributes +
  Samsung meta-data, and a `withMainActivity` hook that points
  `DisplayMetricsHolder` at the Activity's display on create / configuration
  change / resume, requests a decor relayout, and emits the RN dimensions
  update event. Idempotent, with tests.
- `WindowBoundsProvider` / `useWindowBounds` measure the real root bounds;
  responsive layout uses window class + hysteresis; drawers/sheets/onboarding
  size from measured bounds.
- Terminal WebView refits on width/height/DPR changes via injected viewport
  observer; text-scale no longer resizes to innerWidth.
- Hardware keyboard handling: Esc no longer leaves the session; focus helper
  no longer assumes keyboardHeight 0 means IME dismissed.
- Design/investigation notes in `mobile/docs/dex-mode-layout-design.md`.

Verified on a stock API 35 emulator with a 160 dpi overlay display (phone
420 dpi): fullscreen 1920x1080, freeform 412x732, live resize 1000x700 and
maximize all fill the window; phone display unchanged. Confirmed on a Galaxy
device in DeX. `pnpm test` (3697 passed), `typecheck`, `lint`, `oxfmt` clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- windowClass now carries the same ±24 dp hysteresis as isWideLayout so the
  host sidebar does not toggle on every pixel around 600/840 dp
- notifyHardwareKeyboard routes through the frame-height reducer so a refit
  deferred behind the IME flushes instead of stranding `pending`
- desktop-orientation hook is a pure withMainActivity transform that fails
  loudly when the super.onCreate(null) anchor is missing
- viewport DPR test mutates devicePixelRatio before firing the listener
- design doc: 800x600 keeps the sidebar (280+320 fits); document the
  first-Escape limitation of the hardware-keyboard heuristic

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@phs2131
phs2131 force-pushed the fix/mobile-android-dex-layout branch from ebf8d90 to 09716af Compare August 30, 2026 12:29
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds Android DeX lifecycle and display-metrics handling, introduces measured window bounds for responsive mobile layouts, and updates terminal sizing and hardware-keyboard behavior.

  • Registers an Android config plugin for resizable activities and display-density changes.
  • Sizes drawers, previews, onboarding, browser streams, and responsive navigation from measured root bounds.
  • Adds a terminal viewport bridge and centralized refit triggers for window, frame, DPR, and text-scale changes.
  • Adjusts session Back behavior and IME avoidance when a hardware keyboard is detected.

Confidence Score: 4/5

The terminal viewport notification mismatch should be fixed before merging because it can leave PTY dimensions stale in the external-display scenario this PR targets.

The WebView adopts measured RN bounds but reports raw inner dimensions to a refit controller that aborts whenever those dimensions differ, preventing terminal reflow after affected DeX window changes.

Files Needing Attention: mobile/src/terminal/terminal-webview-viewport-injected.ts, mobile/src/terminal/use-terminal-layout-refit-triggers.ts, mobile/src/terminal/terminal-viewport-refit.ts

Important Files Changed

Filename Overview
mobile/plugins/android-desktop-mode.js Adds manifest and MainActivity transforms for DeX resizing, configuration changes, and activity-display metrics.
mobile/src/layout/window-bounds.tsx Provides measured root bounds to layout consumers while retaining display dimensions as a pre-layout fallback.
mobile/src/layout/responsive-layout-metrics.ts Adds width-class and wide-layout hysteresis for freeform-window resizing.
mobile/src/terminal/terminal-webview-viewport-injected.ts Adds RN viewport and DPR observation, but reports raw browser dimensions that can permanently block refitting when they differ from RN bounds.
mobile/src/terminal/terminal-viewport-refit.ts Centralizes debounced terminal refitting and guards it on WebView/frame width alignment.
mobile/src/platform/hardware-keyboard.ts Infers hardware-keyboard attachment from key and IME visibility events.
mobile/src/session/use-session-back-handler.ts Routes Android Back to terminal Escape when hardware input is detected and preserves dirty-draft leave confirmation.

Sequence Diagram

sequenceDiagram
  participant RN as React Native frame
  participant WV as Terminal WebView
  participant RF as Refit controller
  participant Host as Host PTY
  RN->>WV: setViewport(measured width, height)
  WV->>WV: Store rnViewport and recompute fit
  WV-->>RN: viewport-changed(width, height, DPR)
  RN->>RF: Compare WebView and frame widths
  RF->>WV: measureFitDimensions(frame bounds)
  RF->>Host: terminal.updateViewport(cols, rows)
  Host-->>WV: Updated terminal layout
Loading

Reviews (1): Last reviewed commit: "fix(mobile): adapt DeX layout changes to..." | Re-trigger Greptile

Comment on lines +14 to +21
function notifyViewportChanged() {
notify({
type: 'viewport-changed',
innerWidth: window.innerWidth,
innerHeight: window.innerHeight,
dpr: window.devicePixelRatio || 1
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 When a DeX window's browser dimensions differ from the measured terminal frame, viewport-changed reports the raw window.innerWidth instead of the effective RN viewport. The refit controller stores that value and rejects subsequent width-misaligned refits, leaving the host PTY incorrectly wrapped or clipped after resizing.

Suggested change
function notifyViewportChanged() {
notify({
type: 'viewport-changed',
innerWidth: window.innerWidth,
innerHeight: window.innerHeight,
dpr: window.devicePixelRatio || 1
});
}
function notifyViewportChanged() {
notify({
type: 'viewport-changed',
innerWidth: getViewportWidth(),
innerHeight: getViewportHeight(),
dpr: window.devicePixelRatio || 1
});
}

Knowledge Base Used: Mobile sessions and terminal interaction

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 75aba6cf-5b5b-4e5c-b0c5-522f06846bc8

📥 Commits

Reviewing files that changed from the base of the PR and between d607a63 and 09716af.

📒 Files selected for processing (55)
  • mobile/README.md
  • mobile/app.json
  • mobile/app/_layout.tsx
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/app/h/_layout.tsx
  • mobile/app/mobile-onboarding.tsx
  • mobile/docs/dex-mode-layout-design.md
  • mobile/plugins/android-desktop-mode.js
  • mobile/plugins/android-desktop-mode.test.js
  • mobile/src/browser/browser-screencast-request.test.ts
  • mobile/src/browser/mobile-browser-frameless-stream.test.tsx
  • mobile/src/browser/use-mobile-browser-stream.ts
  • mobile/src/components/RightDrawer.tsx
  • mobile/src/components/bottom-drawer-fill-height.test.ts
  • mobile/src/components/mounted-bottom-drawer.tsx
  • mobile/src/components/right-drawer-panel-width.test.ts
  • mobile/src/files/MobileFilePreviewScreen.tsx
  • mobile/src/layout/responsive-layout-metrics.test.ts
  • mobile/src/layout/responsive-layout-metrics.ts
  • mobile/src/layout/responsive-layout.ts
  • mobile/src/layout/window-bounds-state.test.ts
  • mobile/src/layout/window-bounds-state.ts
  • mobile/src/layout/window-bounds.tsx
  • mobile/src/platform/hardware-keyboard.test.ts
  • mobile/src/platform/hardware-keyboard.ts
  • mobile/src/platform/use-pixel-ratio.ts
  • mobile/src/session/TerminalPaneView.tsx
  • mobile/src/session/session-back-press.test.ts
  • mobile/src/session/session-back-press.ts
  • mobile/src/session/use-session-back-handler.ts
  • mobile/src/session/use-terminal-frame-layout.ts
  • mobile/src/terminal/TerminalWebView.tsx
  • mobile/src/terminal/terminal-keyboard-avoidance-webview.test.ts
  • mobile/src/terminal/terminal-live-input.test.ts
  • mobile/src/terminal/terminal-live-input.ts
  • mobile/src/terminal/terminal-viewport-refit-state.ts
  • mobile/src/terminal/terminal-viewport-refit.test.ts
  • mobile/src/terminal/terminal-viewport-refit.ts
  • mobile/src/terminal/terminal-webview-contract.test.ts
  • mobile/src/terminal/terminal-webview-contract.ts
  • mobile/src/terminal/terminal-webview-handle.ts
  • mobile/src/terminal/terminal-webview-html.ts
  • mobile/src/terminal/terminal-webview-messages.ts
  • mobile/src/terminal/terminal-webview-notification-dispatch.test.ts
  • mobile/src/terminal/terminal-webview-notification-dispatch.ts
  • mobile/src/terminal/terminal-webview-reflow.test.ts
  • mobile/src/terminal/terminal-webview-scroll-routing.test.ts
  • mobile/src/terminal/terminal-webview-text-zoom.test.ts
  • mobile/src/terminal/terminal-webview-viewport-injected.ts
  • mobile/src/terminal/terminal-webview-viewport.test.ts
  • mobile/src/terminal/terminal-write-coalescer-boundaries.test.ts
  • mobile/src/terminal/use-terminal-layout-refit-triggers.ts
  • mobile/src/terminal/use-terminal-live-input-commit.ts
  • mobile/src/terminal/use-terminal-live-input-focus.ts
  • mobile/vitest.config.ts
💤 Files with no reviewable changes (1)
  • mobile/src/terminal/terminal-keyboard-avoidance-webview.test.ts
🚧 Files skipped from review as they are similar to previous changes (48)
  • mobile/src/platform/use-pixel-ratio.ts
  • mobile/vitest.config.ts
  • mobile/src/layout/window-bounds-state.test.ts
  • mobile/app/_layout.tsx
  • mobile/src/terminal/terminal-webview-messages.ts
  • mobile/app.json
  • mobile/src/browser/mobile-browser-frameless-stream.test.tsx
  • mobile/src/session/use-terminal-frame-layout.ts
  • mobile/src/layout/responsive-layout.ts
  • mobile/src/components/right-drawer-panel-width.test.ts
  • mobile/src/components/mounted-bottom-drawer.tsx
  • mobile/src/files/MobileFilePreviewScreen.tsx
  • mobile/src/browser/browser-screencast-request.test.ts
  • mobile/src/terminal/use-terminal-live-input-commit.ts
  • mobile/src/terminal/terminal-webview-reflow.test.ts
  • mobile/src/terminal/terminal-webview-contract.ts
  • mobile/src/terminal/terminal-viewport-refit-state.ts
  • mobile/src/terminal/use-terminal-live-input-focus.ts
  • mobile/src/terminal/terminal-webview-contract.test.ts
  • mobile/src/terminal/terminal-webview-scroll-routing.test.ts
  • mobile/src/components/RightDrawer.tsx
  • mobile/src/platform/hardware-keyboard.test.ts
  • mobile/src/terminal/terminal-webview-notification-dispatch.test.ts
  • mobile/app/mobile-onboarding.tsx
  • mobile/src/terminal/terminal-webview-handle.ts
  • mobile/src/components/bottom-drawer-fill-height.test.ts
  • mobile/README.md
  • mobile/src/terminal/terminal-webview-viewport.test.ts
  • mobile/src/terminal/TerminalWebView.tsx
  • mobile/src/terminal/use-terminal-layout-refit-triggers.ts
  • mobile/src/layout/window-bounds-state.ts
  • mobile/src/platform/hardware-keyboard.ts
  • mobile/src/layout/window-bounds.tsx
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/terminal/terminal-write-coalescer-boundaries.test.ts
  • mobile/src/terminal/terminal-live-input.test.ts
  • mobile/src/terminal/terminal-webview-viewport-injected.ts
  • mobile/src/terminal/terminal-live-input.ts
  • mobile/src/terminal/terminal-viewport-refit.test.ts
  • mobile/src/layout/responsive-layout-metrics.test.ts
  • mobile/src/layout/responsive-layout-metrics.ts
  • mobile/src/session/TerminalPaneView.tsx
  • mobile/plugins/android-desktop-mode.js
  • mobile/src/terminal/terminal-webview-text-zoom.test.ts
  • mobile/plugins/android-desktop-mode.test.js
  • mobile/src/terminal/terminal-viewport-refit.ts
  • mobile/src/terminal/terminal-webview-notification-dispatch.ts
  • mobile/src/terminal/terminal-webview-html.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment on lines +157 to +158
physical `Escape` key to `KEYCODE_ESCAPE`, which the framework delivers as a
back press when no view consumes it. `RightDrawer.tsx:114-122` does the same.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- repository knowledge scopes ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- target document context ---'
sed -n '130,175p' mobile/docs/dex-mode-layout-design.md
printf '%s\n' '--- scoped convention and architecture excerpts ---'
for f in /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/{conventions,architecture,learnings}/*.md; do
  [ -f "$f" ] || continue
  case "$f" in
    *mobile*|*dex*|*layout*|*input*|*keyboard*|*hardware*) printf '\n--- %s ---\n' "$f"; cat "$f";;
  esac
done

Repository: stablyai/orca

Length of output: 8537


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- relevant source locations ---'
for name in '[worktreeId].tsx' RightDrawer.tsx terminal-live-input.ts use-terminal-live-input-commit.ts terminal-webview-html.ts; do
  fd -i -t f "$name" mobile src 2>/dev/null || true
done
printf '%s\n' '--- Escape/back and hardware-event references ---'
rg -n -C 5 'hasReceivedHardwareKeyEvent|BackHandler|KEYCODE_ESCAPE|hardwareBackPress|onKeyPress|handleLiveInputKeyPress' mobile src --glob '*.{ts,tsx,md,java,kt}' 2>/dev/null || true
printf '%s\n' '--- session handler context ---'
sed -n '2135,2180p' mobile/app/h/[hostId]/session/[worktreeId].tsx
printf '%s\n' '--- drawer handler context ---'
drawer=$(fd -i -t f 'RightDrawer.tsx' mobile src | head -1); [ -n "$drawer" ] && sed -n '95,135p' "$drawer"

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- exact symbol matches ---'
rg -n -C 6 'hasReceivedHardwareKeyEvent|BackHandler|hardwareBackPress|onKeyPress|handleLiveInputKeyPress|KEYCODE_ESCAPE' \
  'mobile/app/h/[hostId]/session/[worktreeId].tsx' \
  mobile/src/components/RightDrawer.tsx \
  mobile/src/terminal/terminal-live-input.ts \
  mobile/src/terminal/use-terminal-live-input-commit.ts 2>/dev/null || true
printf '%s\n' '--- session back-handler context ---'
sed -n '2135,2180p' 'mobile/app/h/[hostId]/session/[worktreeId].tsx'
printf '%s\n' '--- drawer back-handler context ---'
sed -n '95,135p' mobile/src/components/RightDrawer.tsx
printf '%s\n' '--- live-input key handling ---'
sed -n '1,70p' mobile/src/terminal/terminal-live-input.ts
sed -n '135,185p' mobile/src/terminal/use-terminal-live-input-commit.ts

Repository: stablyai/orca

Length of output: 20544


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- session-back-handler implementation ---'
fd -t f 'use-session-back-handler' src mobile
handler=$(fd -t f 'use-session-back-handler' src mobile | head -1)
[ -n "$handler" ] && { sed -n '1,260p' "$handler"; }
printf '%s\n' '--- back-press resolver and hardware-key state ---'
rg -n -C 8 'resolveSessionBackPress|notifyHardwareKeyEvent|hasReceivedHardwareKeyEvent|hardwareKeyboard' \
  mobile/src mobile/app/h/[hostId]/session src/session src/platform 2>/dev/null | head -300
printf '%s\n' '--- document lines ---'
sed -n '145,165p' mobile/docs/dex-mode-layout-design.md

Repository: stablyai/orca

Length of output: 28402


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- session back-press contract ---'
sed -n '1,180p' mobile/src/session/session-back-press.ts
printf '%s\n' '--- all native/platform input implementation files ---'
git ls-files mobile | rg '(^|/)(android|ios)/|\.java$|\.kt$|hardware|key' | head -120
printf '%s\n' '--- BackHandler and key-event references outside the reviewed files ---'
rg -n -C 4 'BackHandler|hardwareBackPress|dispatchKeyEvent|onKeyDown|KEYCODE_ESCAPE|KEYCODE_BACK|KeyEvent' mobile --glob '*.{ts,tsx,java,kt,json}' | head -240
printf '%s\n' '--- package versions ---'
rg -n -C 2 '"react-native"|"expo"' mobile/package.json package.json 2>/dev/null | head -80

Repository: stablyai/orca

Length of output: 23069


🌐 Web query:

Android KeyEvent KEYCODE_ESCAPE KEYCODE_BACK React Native BackHandler hardwareBackPress official documentation

💡 Result:

In Android development, KEYCODE_BACK (4) and KEYCODE_ESCAPE (111) are distinct key codes [1][2][3]. While both often signify a desire to dismiss or navigate back, they are handled differently by the Android OS and React Native [4][5]. React Native's BackHandler API is specifically designed to detect and manage hardware back button presses on Android via the 'hardwareBackPress' event [6][7][8]. It does not natively provide a separate event listener for 'hardwareEscapePress' [6][8]. Key points regarding their interaction in React Native: 1. BackHandler Scope: The BackHandler API exclusively tracks the system back action [6][8]. Historically, pressing the ESC key on a hardware keyboard did not trigger the same JS-level 'hardwareBackPress' event, which often led to inconsistencies where Modals would dismiss without firing the expected 'onRequestClose' callback [5][9]. 2. Recent Improvements: React Native has updated its internal handling of the ESC key, particularly for Modals [5]. The framework now routes KEYCODE_ESCAPE events through the Android onBackPressedDispatcher [5]. This ensures that when a user presses ESC on a hardware keyboard, it triggers the same underlying mechanism as the hardware back button, causing it to correctly invoke the 'onRequestClose' callback in React Native [5]. 3. Development Considerations: Because BackHandler only listens for 'hardwareBackPress', developers cannot directly register a listener for ESCAPE using that specific API [6][8]. If your application requires handling ESCAPE events distinctly from the back button (for instance, to perform a different action), you would typically need to implement a native module or use a library that exposes Android's onKeyUp or onKeyDown events to the JavaScript layer [10]. In summary, while you cannot use BackHandler to listen for ESCAPE, modern versions of React Native automatically align the behavior of the hardware ESC key with the hardware back button for components like Modals to ensure consistent application state management [5].

Citations:


🌐 Web query:

site:github.com/facebook/react-native/pull/56631 Escape key onBackPressedDispatcher React Native version

💡 Result:

In React Native, the handling of the hardware Escape key (common on external keyboards or Android emulators) via the onBackPressedDispatcher is primarily a concern for Android platform integration. Recent improvements to React Native have specifically targeted the alignment of the hardware Escape key with the standard back-button behavior for Modal components [1]. Previously, pressing the hardware Escape key on an open Modal did not consistently trigger the JavaScript onRequestClose callback, even though the hardware Back button did [1]. Key points regarding this behavior: 1. Integration with BackHandler: To manage back navigation in React Native on Android, developers typically use the BackHandler API, which hooks into the onBackPressedDispatcher under the hood. 2. Modal Behavior: As of recent updates, the hardware Escape key (mapped to KEYCODE_ESCAPE) is now routed through the onBackPressedDispatcher in ReactModalDialog [1]. This ensures that when a user presses the Escape key while a modal is open, the onRequestClose callback is triggered, consistent with the behavior of the hardware back button [1]. 3. Debugging/Testing: You can simulate this behavior using the Android Debug Bridge (ADB) with the following command to verify if your application correctly handles the event: adb shell input keyevent 111 [1] If you are implementing custom back navigation, ensure you are utilizing the BackHandler API, which remains the standard interface for handling back events in React Native applications, allowing you to register listeners that respond to both the standard back button and, effectively, the Escape key when routed through the dispatcher [1].

Citations:

  • 1: GitHub pull request 56631 in facebook/react-native (link omitted to avoid creating a cross-reference)

🌐 Web query:

site:github.com/facebook/react-native React Native 0.83 BackHandler KEYCODE_ESCAPE Android source

💡 Result:

In React Native, the Android hardware ESC key (KEYCODE_ESCAPE) is intended to be handled similarly to the hardware BACK button, particularly within the Modal component, to ensure that the JS onRequestClose callback is triggered [1][2]. In versions like 0.83, the handling of hardware keys within Modals on Android has been undergoing significant architectural changes to support Android's newer Predictive Back system and the deprecation of Activity.onBackPressed [3][4]. Key points regarding the implementation: 1. Mechanism: Historically, handling for KEYCODE_ESCAPE was added to ensure that pressing ESC on a physical keyboard would properly trigger the modal's close callback, preventing the React state from becoming desynchronized [2][5]. 2. Evolution: Recent changes have moved away from direct keycode monitoring toward using the AndroidX OnBackPressedDispatcher and OnBackPressedCallback [3][4]. This ensures that both the back gesture/button and the ESC key follow the same dispatch path [1]. 3. Current Status: While there have been ongoing refinements, issues have been reported (such as in version 0.84+) where the ESC key may occasionally fail to trigger the expected callbacks, indicating that while the architecture exists to support it, it remains a subject of active maintenance and bug fixes [1][6]. If you are investigating the source code, you can find relevant logic in the React Native Android repository under the Modal host view implementation: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.kt [3] This file manages the lifecycle of the modal and integrates the key handling events into the Android activity dispatch system [1][3].

Citations:

  • 1: GitHub pull request 56631 in facebook/react-native (link omitted to avoid creating a cross-reference)
  • 2: react/react-native@f51773ecded
  • 3: react/react-native@5b630d2
  • 4: GitHub pull request 51096 in facebook/react-native (link omitted to avoid creating a cross-reference)
  • 5: GitHub pull request 31564 in facebook/react-native (link omitted to avoid creating a cross-reference)
  • 6: GitHub issue 56411 in facebook/react-native (link omitted to avoid creating a cross-reference)

🌐 Web query:

site:android.googlesource.com/platform/frameworks/base KEYCODE_ESCAPE onBackPressedDispatcher Activity dispatchKeyEvent escape back

💡 Result:

In Android, KEYCODE_ESCAPE (111) [1] is distinct from the back navigation system and does not automatically trigger the OnBackInvokedDispatcher [2][3]. Handling of these inputs differs significantly: 1. KEYCODE_BACK: This is the standard back navigation event. When the Predictive Back gesture/system is enabled, this event is intercepted by the WindowOnBackInvokedDispatcher [3][4] and routed to registered OnBackInvokedCallback instances [2]. If Predictive Back is not enabled, the system uses legacy behavior, dispatching the key event through the View tree or activity [5][6]. 2. KEYCODE_ESCAPE: This key code typically maps to the Escape key on physical keyboards. It is not intercepted by the OnBackInvokedDispatcher [3]. Instead, it is treated as a standard key event that passes through the View hierarchy's normal dispatch chain [7][8]. If you need to handle KEYCODE_ESCAPE in an Activity, you should override onKeyDown or onKeyUp [7][8]: @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ESCAPE) { // Handle Escape key action here return true; // Return true to indicate the event was consumed } return super.onKeyUp(keyCode, event); } The system Dialog class provides a reference implementation for handling both [9]. It treats KEYCODE_BACK as a navigation event (using the dispatcher when available) and explicitly monitors KEYCODE_ESCAPE to trigger dialog cancellation or dismissal [9]. If your goal is to make KEYCODE_ESCAPE behave exactly like a back navigation, you must manually invoke the logic you have assigned to your back callback when you detect KEYCODE_ESCAPE in your key event handlers [9].

Citations:


🌐 Web query:

site:github.com/facebook/react-native/blob/v0.83.10 BackHandler Android hardwareBackPress ReactActivity KEYCODE_ESCAPE

💡 Result:

In React Native v0.83.10:

  • ReactActivity does not reference KeyEvent.KEYCODE_ESCAPE; the search returns no match. (github.com)
  • Back handling enters through ReactActivity.onBackPressed(), which delegates to ReactActivityDelegate. (github.com)
  • The JS BackHandler event is emitted by DeviceEventManagerModule.emitHardwareBackPressed() as "hardwareBackPress". (github.com)

Relevant files:

  • ReactActivity.java
  • DeviceEventManagerModule.kt

So KEYCODE_ESCAPE is not the Android path for BackHandler; use the activity back-dispatch mechanism instead.

Citations:


Handle KEYCODE_ESCAPE natively. Android treats KEYCODE_ESCAPE and KEYCODE_BACK as separate events. React Native 0.83.10 BackHandler handles only the back-dispatch path; it does not convert KEYCODE_ESCAPE for this screen. Therefore, useSessionBackHandler may never receive Escape, and any mapped first event can select leave while hardwareKeyboard is still false. Add native KeyEvent handling or establish an equivalent Galaxy/DeX event path before relying on BackHandler.

Source: MCP tools


```xml
<activity android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|uiMode|density|locale|layoutDirection|fontScale|navigation|mcc|mnc"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
printf '%s\n' '--- applicable repository knowledge files ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- relevant convention and architecture excerpts ---'
for f in /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/{conventions,architecture,learnings}/*.md; do
  [ -f "$f" ] || continue
  case "$f" in
    *android*|*mobile*|*docs*|*general*|*global*) echo "### $f"; cat "$f";;
  esac
done
printf '%s\n' '--- target document context ---'
sed -n '220,270p' mobile/docs/dex-mode-layout-design.md
printf '%s\n' '--- references to the manifest/activity and configuration handling ---'
rg -n -C 3 'configChanges|MainActivity|touchscreen|screenSize|smallestScreenSize|uiMode|DeX|Dex' mobile --glob '!docs/dex-mode-layout-design.md'

Repository: stablyai/orca

Length of output: 50371


🌐 Web query:

site:developer.android.com/guide/topics/manifest/activity-element android:configChanges touchscreen configuration change display input device

💡 Result:

In Android development, the android:configChanges attribute is used in the activity manifest to specify configuration changes that an activity handles itself, rather than shutting down and restarting when a change occurs [1]. Specifically, the "touchscreen" value within android:configChanges indicates that the activity will handle changes to the touchscreen mode [1]. According to official Android documentation, this configuration change is triggered when the user performs actions such as connecting or disconnecting an input peripheral or moving the application between different displays [1]. When an activity includes "touchscreen" in its android:configChanges declaration, the activity remains running during these events, and the system calls the onConfigurationChanged method of the activity instead of destroying and recreating the activity instance [1]. Developers generally need to update resources or adjust the user interface within onConfigurationChanged when these changes occur [1].

Citations:


🌐 Web query:

site:developer.android.com/guide/topics/manifest/activity-element "touchscreen" "input peripheral" "different displays"

💡 Result:

When using a touchscreen input peripheral with multiple displays, the operating system must correctly map the touch coordinates from the physical touch surface to the specific display screen it controls [1]. Because operating systems identify a change in touchscreen mode when a peripheral is connected or when application windows are moved between different displays, the system must maintain an association between the input device and the intended output display [1]. In most modern operating systems, if the touch input is not mapped to the correct display by default, it requires manual configuration through the system's display or input settings. This process typically involves identifying the touchscreen peripheral and associating it with the specific monitor it covers to ensure that touch events on the physical glass translate to the correct coordinates on the corresponding screen [1]. If this mapping is not configured, touching one display might trigger input actions on a different, incorrect display.

Citations:


🌐 Web query:

site:developer.android.com/guide/topics/manifest/activity-element "\"touchscreen\"" "\"The touchscreen has changed\""

💡 Result:

In the context of software development, particularly within the Android operating system, the phrase "touchscreen" appearing in the context of "The touchscreen has changed" refers to a specific configuration change event [1]. In Android, this is documented as a system event that occurs when there is a change to the touchscreen mode, such as when a user connects or disconnects an input peripheral (like a mouse or stylus) or moves an application between different displays [1]. When an activity is configured to handle this change—often via the android:configChanges attribute in the manifest file—the system notifies the application of the change instead of automatically destroying and recreating the activity [1]. This allows developers to update their application's UI or logic dynamically in response to the altered input capabilities or display environment [1].

Citations:


Handle touchscreen configuration changes.

If a supported DeX transition changes the touchscreen configuration, line 246 omits that change and Android can recreate MainActivity, remounting the React tree. Add touchscreen or document that supported transitions cannot change it.

Source: MCP tools

<meta-data android:name="com.samsung.android.multidisplay.keep_process_alive" android:value="true" />
<!-- Android 12L+/16 large-screen compat opt-outs -->
<meta-data android:name="android.allow_multiple_resumed_activities" android:value="true" />
<property android:name="android.window.PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES" android:value="true" />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- knowledge scopes ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print | sort
printf '%s\n' '--- target context ---'
cat -n mobile/docs/dex-mode-layout-design.md | sed -n '255,280p'
printf '%s\n' '--- matching repository references ---'
rg -n -C 3 'PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES|resizab|resizeab|opt.?out|compat.*override' mobile/docs mobile 2>/dev/null | head -200

Repository: stablyai/orca

Length of output: 31371


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- mobile conventions ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/mobile.md
printf '%s\n' '--- repository conventions ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/repo-wide.md

Repository: stablyai/orca

Length of output: 1186


🌐 Web query:

Android WindowManager PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES true false opt out official documentation

💡 Result:

The PackageManager property PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES is an application-level tag used to opt out of device manufacturer compatibility overrides that force an app's resizability [1][2]. According to official Android documentation, the property behaves as follows: - Setting the value to false: This explicitly informs the system that the application must be opted out of these compatibility treatments, even if a device manufacturer has attempted to force them on the app [1][2]. - Setting the value to true or not setting the property at all: These have no effect [1][2]. To implement this, add the following to your AndroidManifest.xml file within the tag [1][2]: When these manufacturer overrides are active, they force packages to be either resizable or unresizable. Using this opt-out does not change whether an app can be put into multi-window mode, but it prevents the system from forcing resizability behavior (such as forcing an app to be resizable to avoid size-compatibility mode during window container changes like rotation or display size adjustments) [1][2].

Citations:


Set android.window.PROPERTY_COMPAT_ALLOW_RESIZEABLE_ACTIVITY_OVERRIDES to false.

true or unset has no effect. Set false in the design and in mobile/plugins/android-desktop-mode.js to implement the opt-out.

Source: MCP tools

Comment on lines +779 to +781
`window.decorView.requestLayout()`. For the maximize/restore/drag case the
px size changes anyway so `Screen.onLayout(changed=true)` fires and
`updateState` recomputes with the corrected density. The residual case is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- repository knowledge scopes ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print | sort
printf '%s\n' '--- relevant conventions and learnings ---'
for f in /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/{conventions,learnings,architecture}/*.md; do
  [ -f "$f" ] || continue
  case "$f" in
    *mobile*|*android*|*dex*|*layout*) printf '\n### %s\n' "$f"; cat "$f";;
  esac
done
printf '%s\n' '--- target document context ---'
sed -n '730,810p' mobile/docs/dex-mode-layout-design.md
printf '%s\n' '--- appendix A references ---'
rg -n -C 4 'Appendix A|frameSize|requestLayout|onLayout|density|display' mobile/docs/dex-mode-layout-design.md

Repository: stablyai/orca

Length of output: 50371


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- exact target lines ---'
sed -n '760,790p' mobile/docs/dex-mode-layout-design.md
printf '%s\n' '--- tracked react-native-screens and Android layout sources ---'
git ls-files | rg '(^|/)(Screen\.kt|FabricEnabledViewGroup\.kt|View\.java|ViewGroup\.java|react-native-screens|android-desktop-mode)' | head -80
printf '%s\n' '--- relevant design assertions ---'
rg -n -C 3 'onResume|requestLayout|density-only|same.*bounds|frameSize|changed == true' mobile/docs/dex-mode-layout-design.md

Repository: stablyai/orca

Length of output: 9591


🌐 Web query:

Android View onLayout changed parameter requestLayout same bounds official documentation source

💡 Result:

In the Android View framework, the boolean parameter changed in the onLayout(boolean changed, int left, int top, int right, int bottom) method indicates whether a new size or position was assigned to the view [1][2][3]. When you call requestLayout, you are notifying the Android UI framework that the view's layout bounds may need to be changed and that a re-measurement and re-layout pass is required [2][3]. Regarding the interaction between requestLayout and the changed parameter: 1. Significance of changed: The changed parameter is true if the view's layout bounds (left, top, right, bottom) have actually changed since the last layout pass [1][2]. It is false if the layout pass was triggered but the final calculated bounds for that specific view remain the same as they were previously [1]. 2. Triggering onLayout: Calling requestLayout does not guarantee that the view's bounds will change [4]. The framework initiates a layout pass, and the view's onLayout method will eventually be called as part of this process [2][3]. If the parent layout determines that the view's size and position remain unchanged—even after you requested a layout—onLayout may still be called with changed set to false [1][4]. 3. Common Misconceptions: Developers sometimes expect that every call to requestLayout will result in onLayout being called with changed = true. However, because requestLayout essentially signals a need for a potential update, the actual layout logic (often inside a ViewGroup) determines the final position [4]. If the new constraints result in the same bounds, changed will be false [1]. In summary, requestLayout is the request to perform the layout process, while the changed parameter in onLayout is a report on the result of that process, specifically indicating whether the view's physical boundaries were modified [1][2].

Citations:


Add an explicit state refresh for density-only display moves.

If pixel bounds stay unchanged, requestLayout() can reach Screen.onLayout(changed=false). FabricEnabledViewGroup.updateState then keeps the stale frameSize, preserving the top-left scaling error. Add an explicit react-native-screens state refresh or a regression test for this case.

Source: MCP tools

4. JS `Dimensions`/`PixelRatio` never update on Android bridgeless (A.3). In
the same `MainActivity` hook, after the metrics override, emit the RN
dimensions event so JS sees the new scale:
`(reactHost as? ReactHostImpl)?.currentReactContext?.getNativeModule(DeviceInfoModule::class.java)?.emitUpdateDimensionsEvent()`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- repository guidance ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- target document context ---'
sed -n '760,810p' mobile/docs/dex-mode-layout-design.md
printf '%s\n' '--- DeviceInfoModule references and generated activity context ---'
rg -n -C 4 'DeviceInfoModule|emitUpdateDimensionsEvent|ReactHostImpl|MainActivity' mobile . \
  -g '*.kt' -g '*.java' -g '*.md' | head -300

Repository: stablyai/orca

Length of output: 50371


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- mobile conventions ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/mobile.md
printf '%s\n' '--- relevant document sections ---'
sed -n '720,805p' mobile/docs/dex-mode-layout-design.md
printf '%s\n' '--- RN version and local patches ---'
rg -n -C 2 'react-native[^A-Za-z]|0\.83\.9|DeviceInfoModule' mobile/package.json mobile/pnpm-lock.yaml mobile/yarn.lock mobile/package-lock.json mobile/patches mobile/plugins 2>/dev/null || true
printf '%s\n' '--- tracked Android sources ---'
git ls-files mobile | rg '(^|/)(MainActivity|DeviceInfoModule|ReactHostImpl|DisplayMetricsHolder).*\\.(kt|java)$|patches/react-native'

Repository: stablyai/orca

Length of output: 50370


🌐 Web query:

React Native v0.83.9 DeviceInfoModule.kt internal class emitUpdateDimensionsEvent visibility ReactHostImpl currentReactContext

💡 Result:

In React Native v0.83.9, the DeviceInfoModule class is defined as internal [1][2]. This change was implemented to reduce the public API surface of the framework [2]. Regarding the requested components: 1. DeviceInfoModule.kt: This class is marked as internal [1][2]. It is responsible for providing device display metrics (such as screen and window dimensions) and system properties to the React Native runtime [1][3]. 2. emitUpdateDimensionsEvent: This function is a public member of the internal DeviceInfoModule class [1]. It is triggered by lifecycle events (e.g., onHostResume) when changes in font scale are detected [1][3]. The function checks if there is an active React instance, compares current display metrics against cached values, and emits a didUpdateDimensions event to JavaScript via the React bridge if a change has occurred [1]. 3. ReactHostImpl and currentReactContext: ReactHostImpl is a core component in the modern React Native architecture (often associated with the Bridgeless mode) that manages the React instance lifecycle [4][5]. While DeviceInfoModule interacts with the ReactApplicationContext to access the React instance for event emission [1], ReactHostImpl is involved in the broader orchestration of these instances [4][5]. In various versions, including v0.83.x, ReactHostImpl maintains state and configuration that influences how modules like DeviceInfoModule function, ensuring that events are correctly dispatched when the React context is active and initialized [1][5]. The visibility of DeviceInfoModule as internal signifies that it is intended for use by the framework itself rather than as a public-facing API for application developers [2]. Developers needing to handle dimension changes or device information should continue to use the standard React Native Dimensions API, which consumes these native events under the hood [6][7].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- exact React Native dependency and patch ---'
sed -n '45,62p' mobile/package.json
sed -n '1,220p' mobile/patches/react-native@0.83.10.patch
printf '%s\n' '--- all project references to the proposed call ---'
rg -n -C 3 'emitUpdateDimensionsEvent|DeviceInfoModule|currentReactContext|ReactHostImpl' mobile \
  -g '!pnpm-lock.yaml' -g '*.js' -g '*.ts' -g '*.tsx' -g '*.kt' -g '*.java' -g '*.md' | head -250

Repository: stablyai/orca

Length of output: 12887


🌐 Web query:

site:raw.githubusercontent.com/facebook/react-native/v0.83.10/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.kt

💡 Result:

The requested React Native v0.83.10 file is available here. It defines DeviceInfoModule, which exports display dimensions and the isEdgeToEdge flag, and emits didUpdateDimensions when metrics change. (raw.githubusercontent.com)

Citations:


🏁 Script executed:

#!/bin/bash
set -eu
printf '%s\n' '--- existing Android plugin implementation ---'
sed -n '1,180p' mobile/plugins/android-desktop-mode.js
printf '%s\n' '--- exact RN 0.83.10 DeviceInfoModule declaration ---'
curl -fsSL https://raw.githubusercontent.com/facebook/react-native/v0.83.10/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/deviceinfo/DeviceInfoModule.kt \
  | sed -n '1,120p'
printf '%s\n' '--- exact RN 0.83.10 ReactHostImpl context member ---'
curl -fsSL https://raw.githubusercontent.com/facebook/react-native/v0.83.10/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt \
  | rg -n -C 3 'currentReactContext|class ReactHostImpl'

Repository: stablyai/orca

Length of output: 12883


Update the snippet to use the existing public event path.

React Native 0.83.10 declares DeviceInfoModule as internal, so generated MainActivity.kt cannot reference DeviceInfoModule::class.java across the module boundary. The plugin already emits didUpdateDimensions through reactHost?.currentReactContext?.emitDeviceEvent(...); document that path instead.

Source: MCP tools

jetd1 pushed a commit to jetd1/orca that referenced this pull request Sep 16, 2026
On Samsung One UI, split-window panes are assigned a density different
from fullscreen (e.g. 321 vs 420 dpi). Three measurement paths in the
app convert with a density different from the one Fabric/the WebView
actually paint at:

1. react-native-screens FabricEnabledViewGroup.updateState converted
   the measured pane px back to dp with the process-global main-display
   density captured at process start, collapsing all ScreenStack
   content into a top-left box of pane*density-ratio (upstream
   software-mansion/react-native-screens#4159, fixed in 4.26.0). Pin
   react-native-screens to 4.26.2 - the first fix line that remains
   compatible with react-native 0.83 codegen (4.27+ needs newer
   codegen), plus a pnpm patch respelling one React.ComponentRef
   command argument that the 0.83.10 codegen parser rejects.
2. RN's process-global DisplayMetricsHolder stays frozen at process
   start (seeded once from the Application context, so activity
   recreation does not help). Text measurement (PixelUtil.pxToDp) and
   all other PixelUtil conversions then disagree with the mount density
   by exactly the mismatch ratio, so text is laid out into boxes that
   are the wrong fraction of the glyphs - clipped lines, cut
   descenders. Add an android-multiwindow-metrics config plugin that
   re-seeds BOTH holders from the windowed resources on
   create/resume/configurationChange, emits didUpdateDimensions,
   requests a decorView relayout, and adds density to configChanges so
   the switch reaches the hook without activity recreation. Unlike the
   DeX variant in stablyai#16018, the screen holder also takes windowed
   metrics, which the text pipeline requires.
3. The Android WebView pins its CSS-px-at-construction density to the
   display (Chrome-side; activity recreation does not change it), while
   the terminal fit protocol passes an RN-dp container height the web
   side consumed as CSS px. xterm then overallocated rows by the
   density ratio and its bottom rows sat below the visible viewport -
   the terminal could not scroll to the last lines in split view. Pass
   rnPixelRatio alongside containerHeight in the measure message and
   convert into the WebView's CSS px in measureFitDimensions; bump the
   terminal payload hash canary accordingly.

The plugin's exported transforms are unit-tested (idempotent
injection, hook ordering before super.onCreate(null), density append
without duplication, throw paths) under a new plugins/**/*.test.js
vitest include.

Verified on Samsung foldable hardware (One UI, Android 16): layout and
text fill the pane correctly in split panes and pop-up windows across
recreation-free fullscreen<->split transitions, and the terminal
viewport reaches its final buffer rows in split view.

Co-Authored-By: CCCha <cccha@jetd.one> via Claude Code

This branch has not been deployed

No deployments
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]: Orca Mobile is unusable in Samsung DeX (severe lag, stale rendering, non-responsive layout)

2 participants