Skip to content

Commit 15e87df

Browse files
SawyerHoodclaude
andauthored
Replace the native mobile UI with a WebView shell around the PWA (#2515)
## Human comments <!-- Agents: Do not fill in this section. This is for human users to fill in. --> ## What was wrong `apps/mobile` carried about 112,000 lines of native UI duplicating what `apps/app` already renders, so every product feature needed two implementations. The plan (Docs `plans/mobile-webview-shell.md`) replaces the native screens with one WebView over the page, keeping native only what a web page cannot do on a phone. ## What changed Five commits, in order: 1. **`@bb/mobile-bridge`** — one versioned contract both sides import: the handshake the shell installs, page-to-shell messages, shell-to-page events, and the injected script itself, so the `window.bb.native` global cannot drift. `compareBridgeVersions(remoteVersion, localVersion)` is symmetric; capabilities are declared in the handshake rather than inferred from the version, so a shell can withdraw one without a bump. 2. **The shell** — `ProfileWebViewScreen`, pure logic in `src/lib/shell` tested under node, native error states (re-pair / retry / content-process reload), and deep links that resolve to one shell route carrying a *web* path. The session is not re-implemented: the existing connector already mints and renews the connect cookie. 3. **The page side** — `src/lib/native-shell` with `shellHaptic`, `shellSetBadge`, `shellOpenExternal`, `shellShare`, `shellOpenNative`, each falling back to web behaviour. The app surface header is now `mobile` inside the shell. Two fixes come from the Phase 0 measurements: the bottom safe-area inset collapses while the keyboard is open, and voice input names the real reason it is unavailable on a plain-HTTP origin. 4. **End-to-end coverage** — the mobile e2e harness serves a built `apps/app` when `BB_MOBILE_E2E_SERVE_APP=1`, because the shell has no page otherwise. 5. **The delete** — 620 files, 95,754 deletions. `apps/mobile` falls to about 24,000 lines. 24 dependencies, three Expo config plugins, the committed terminal page and its builder go with it. A native `/settings/device` screen holds what the phone owns and is the shell's escape hatch. Three entry points reach it — a row in the page's Settings over the bridge, the shell's load-failure screen, and a Home Screen quick action — and only the first needs a live page. That matters: after the delete there is no native UI to fall back to. No wire change: `HOST_DAEMON_PROTOCOL_VERSION` is untouched. `mobile` was already in `REQUEST_APP_SURFACE_VALUES`. ## How you verified Automated: 0 lint errors, typecheck clean, and 23 + 286 + 3,437 tests across `@bb/mobile-bridge`, `@bb/mobile`, and `@bb/app` after rebasing onto `main`. On an iPhone 17 Pro simulator (iOS 26.3), the four CI flows pass against the e2e harness on a build made after the dependency prune: `shell-launch`, `shell-deep-link`, `shell-send` (send a message, assert the provider's echo), and `shell-unreachable-server`. On a physical iPhone 15 Pro (iOS 26.6), a Release build installs and runs, and the Home Screen quick action reaches device settings — the one entry point simulator automation could not exercise. Phase 0 measured the risky parts on device before any of this was built; the numbers and verdicts are in section 11 of the plan. The keyboard fix moved the composer-to-keyboard gap from 60 CSS px to 26, against about 15 for the old native composer. Three bugs the tests caught before they shipped: `z.string().url()` accepts `javascript:` and `data:`, and `open-external` reaches the system link opener; first run behind the shell spun forever with no server paired; and the shell preference survived a state wipe because it cached its value. EAP codename scan over `origin/main..HEAD`: clean (working tree, tracked at HEAD, added lines, commit messages all 0). ### Known gaps - **`navigator.serviceWorker` does not exist in WKWebView** on any origin bb needs. It requires app-bound domains, which would both break Direct mode and disable JavaScript injection for any web view that does not opt in — killing the bridge. The service worker is therefore dropped from the plan, not deferred. Measured cold start is 142 ms (LAN) to 2.1 s (a shaped 3G link), which is acceptable without it. - **Camera capture is unverified.** The WKWebView file chooser offers it and the photo-library path is proven end to end, but the simulator has no camera and I did not exercise it on the device. - `shell-unreachable-server` covers the add-server probe refusing a dead URL, not the shell's own load-failure screen. That path is hand-verified; automating it needs a harness that can stop answering mid-flow. - About 5,800 lines of `src/lib/query`, `src/lib/realtime`, and the connection layer survive. They are reachable only through the session-cookie path the WebView needs, so removing them is a refactor of the connector rather than a delete, and it would cost the native chrome its server palette. > AGENT GENERATED --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent d080ce0 commit 15e87df

673 files changed

Lines changed: 5499 additions & 95499 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/mobile-e2e.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,14 @@ jobs:
248248
# seeded project + threads) on the port the flows expect. Turbo builds
249249
# its prerequisites (plugin SDK, native modules) first; the script
250250
# prints one JSON line when it is ready and keeps running.
251+
# Every flow drives the WebView shell, so the harness has to serve a
252+
# built apps/app the way a bb server does.
253+
- name: Build the web app the shell renders
254+
run: pnpm exec turbo run build --filter=@bb/app
255+
251256
- name: Start the e2e backend
257+
env:
258+
BB_MOBILE_E2E_SERVE_APP: "1"
252259
run: |
253260
set -x
254261
mkdir -p e2e-artifacts

‎apps/app/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@bb/domain": "workspace:*",
2626
"@bb/fuzzy-match": "workspace:*",
2727
"@bb/host-daemon-contract": "workspace:*",
28-
"@get-bb/plugin-sdk": "workspace:*",
28+
"@bb/mobile-bridge": "workspace:*",
2929
"@bb/sdk": "workspace:*",
3030
"@bb/server-contract": "workspace:*",
3131
"@bb/shared-ui": "workspace:*",
@@ -35,6 +35,7 @@
3535
"@dnd-kit/sortable": "^10.0.0",
3636
"@dnd-kit/utilities": "^3.2.2",
3737
"@fontsource-variable/inter": "^5.2.8",
38+
"@get-bb/plugin-sdk": "workspace:*",
3839
"@hookform/resolvers": "^5.4.0",
3940
"@hugeicons/core-free-icons": "^4.1.3",
4041
"@hugeicons/react": "^1.1.6",

‎apps/app/src/App.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AuthCallbackView } from "./views/AuthCallbackView";
1111
import { QuickCreateProjectProvider } from "./hooks/useQuickCreateProject";
1212
import { RouteNavigationProvider } from "./components/ui/app-route-anchor";
1313
import { AppNavigationUrlHost } from "./lib/url-open-routing";
14+
import { NativeShellReporter } from "./lib/native-shell";
1415
import { AppFileExternalNavigationHost } from "./components/plugin/AppFileExternalNavigationHost";
1516
import { useAppTheme } from "./hooks/useAppTheme";
1617
import { useFaviconColorSync } from "./lib/favicon-color-preference";
@@ -375,6 +376,7 @@ export function App() {
375376
<AppNavigationUrlHost>
376377
<AppFileExternalNavigationHost>
377378
<HashNavigationScroll />
379+
<NativeShellReporter />
378380
<Routes>
379381
<Route
380382
path={AUTH_CALLBACK_ROUTE_PATH}

‎apps/app/src/components/layout/AppLayout.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ export function AppLayout({ children }: AppLayoutProps) {
820820
<div
821821
ref={contentShellRef}
822822
data-testid="app-layout-content-shell"
823-
className="relative flex h-full min-h-0 min-w-0 w-full flex-col pt-[env(safe-area-inset-top)] pr-[env(safe-area-inset-right)] pb-[env(safe-area-inset-bottom)] pl-[env(safe-area-inset-left)]"
823+
className="relative flex h-full min-h-0 min-w-0 w-full flex-col pt-[env(safe-area-inset-top)] pr-[env(safe-area-inset-right)] pb-[var(--bb-safe-area-bottom,env(safe-area-inset-bottom))] pl-[env(safe-area-inset-left)]"
824824
>
825825
{showHeader ? (
826826
<AppHeader

‎apps/app/src/components/layout/useMobileVisualViewportHeight.test.tsx‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { act, cleanup, render, screen, waitFor } from "@testing-library/react";
44
import { useRef } from "react";
55
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
66
import {
7+
KEYBOARD_OPEN_MIN_SHRINK_PX,
8+
SHELL_SAFE_AREA_BOTTOM_PROPERTY,
79
shouldRestoreIOSViewportOnKeyboardDismissal,
810
useMobileVisualViewportHeight,
911
} from "./useMobileVisualViewportHeight";
@@ -305,6 +307,80 @@ describe("useMobileVisualViewportHeight", () => {
305307
});
306308
});
307309

310+
311+
it("collapses the bottom safe-area inset while the keyboard is open", async () => {
312+
// iOS keeps env(safe-area-inset-bottom) at its full value with the
313+
// keyboard up, even though the keyboard covers the home indicator. That
314+
// leaves a dead band between the composer and the keys (plan 11.4).
315+
const visualViewport = new FakeVisualViewport();
316+
visualViewport.offsetTop = 0;
317+
await withFakeVisualViewport(visualViewport, async () => {
318+
render(<VisualViewportShell enabled />);
319+
const shellHeightRoot = screen.getByTestId("shell-height-root");
320+
const editor = screen.getByTestId("editor");
321+
expect(
322+
shellHeightRoot.style.getPropertyValue(
323+
SHELL_SAFE_AREA_BOTTOM_PROPERTY,
324+
),
325+
).toBe("");
326+
327+
act(() => {
328+
editor.focus();
329+
});
330+
await flushScheduledViewportPass();
331+
// Focus alone is not the keyboard; a hardware keyboard shrinks nothing.
332+
expect(
333+
shellHeightRoot.style.getPropertyValue(
334+
SHELL_SAFE_AREA_BOTTOM_PROPERTY,
335+
),
336+
).toBe("");
337+
338+
act(() => {
339+
visualViewport.height = 500 - KEYBOARD_OPEN_MIN_SHRINK_PX;
340+
visualViewport.dispatchEvent(new Event("resize"));
341+
});
342+
await flushScheduledViewportPass();
343+
expect(
344+
shellHeightRoot.style.getPropertyValue(
345+
SHELL_SAFE_AREA_BOTTOM_PROPERTY,
346+
),
347+
).toBe("0px");
348+
349+
act(() => {
350+
editor.blur();
351+
});
352+
await flushScheduledViewportPass();
353+
expect(
354+
shellHeightRoot.style.getPropertyValue(
355+
SHELL_SAFE_AREA_BOTTOM_PROPERTY,
356+
),
357+
).toBe("");
358+
});
359+
});
360+
361+
it("does not collapse the inset for a URL bar that only shrinks a little", async () => {
362+
const visualViewport = new FakeVisualViewport();
363+
visualViewport.offsetTop = 0;
364+
await withFakeVisualViewport(visualViewport, async () => {
365+
render(<VisualViewportShell enabled />);
366+
const shellHeightRoot = screen.getByTestId("shell-height-root");
367+
act(() => {
368+
screen.getByTestId("editor").focus();
369+
});
370+
await flushScheduledViewportPass();
371+
act(() => {
372+
visualViewport.height = 500 - (KEYBOARD_OPEN_MIN_SHRINK_PX - 1);
373+
visualViewport.dispatchEvent(new Event("resize"));
374+
});
375+
await flushScheduledViewportPass();
376+
expect(
377+
shellHeightRoot.style.getPropertyValue(
378+
SHELL_SAFE_AREA_BOTTOM_PROPERTY,
379+
),
380+
).toBe("");
381+
});
382+
});
383+
308384
it("leaves pinch-zoom pans alone", async () => {
309385
const visualViewport = new FakeVisualViewport();
310386
visualViewport.offsetTop = 0;

‎apps/app/src/components/layout/useMobileVisualViewportHeight.ts‎

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ export function shouldRestoreIOSViewportOnKeyboardDismissal({
1818
return isAppleWebKit && isIOSDevice;
1919
}
2020

21+
/**
22+
* The bottom padding the app shell applies. It normally follows
23+
* `env(safe-area-inset-bottom)`, but iOS keeps that inset at its full value
24+
* while the soft keyboard is open, even though the keyboard already covers
25+
* the home indicator. The result is a dead band between the composer and the
26+
* keys — measured at about 45 CSS px on an iPhone 17 Pro (plan section 11.4).
27+
*/
28+
export const SHELL_SAFE_AREA_BOTTOM_PROPERTY = "--bb-safe-area-bottom";
29+
30+
/**
31+
* How much shorter the visual viewport must get before a focused editor
32+
* counts as "the keyboard is open". Well above a URL-bar collapse, well below
33+
* the shortest soft keyboard.
34+
*/
35+
export const KEYBOARD_OPEN_MIN_SHRINK_PX = 80;
36+
2137
function getVisualViewportPageTop(visualViewport: VisualViewport) {
2238
return Math.round(window.scrollY + visualViewport.offsetTop);
2339
}
@@ -68,6 +84,36 @@ export function useMobileVisualViewportHeight(
6884
// only the visual viewport.
6985
let shellContainingBlockHeight = 0;
7086
let shellContainingBlockHeightStale = true;
87+
// The visual-viewport height captured when an editor took focus, and
88+
// whether the keyboard is currently judged open. Both drive only the
89+
// bottom-inset override, never the height override.
90+
let viewportHeightBeforeKeyboard: number | null = null;
91+
let appliedKeyboardInset = false;
92+
const setKeyboardInset = (open: boolean) => {
93+
if (open === appliedKeyboardInset) return;
94+
appliedKeyboardInset = open;
95+
if (open) {
96+
shellHeightRoot.style.setProperty(
97+
SHELL_SAFE_AREA_BOTTOM_PROPERTY,
98+
"0px",
99+
);
100+
} else {
101+
shellHeightRoot.style.removeProperty(SHELL_SAFE_AREA_BOTTOM_PROPERTY);
102+
}
103+
};
104+
const updateKeyboardInset = () => {
105+
if (
106+
viewportHeightBeforeKeyboard === null ||
107+
!isKeyboardFocusTarget(document.activeElement)
108+
) {
109+
setKeyboardInset(false);
110+
return;
111+
}
112+
setKeyboardInset(
113+
viewportHeightBeforeKeyboard - visualViewport.height >=
114+
KEYBOARD_OPEN_MIN_SHRINK_PX,
115+
);
116+
};
71117
const clearViewportOverride = () => {
72118
if (appliedOverride === null) return;
73119
appliedOverride = null;
@@ -77,6 +123,7 @@ export function useMobileVisualViewportHeight(
77123
};
78124
const updateHeight = () => {
79125
animationFrame = null;
126+
updateKeyboardInset();
80127
if (visualViewport.scale !== 1) {
81128
clearViewportOverride();
82129
return;
@@ -165,6 +212,11 @@ export function useMobileVisualViewportHeight(
165212
const handleFocusOut = (event: FocusEvent) => {
166213
if (!isKeyboardFocusTarget(event.target)) return;
167214
if (isKeyboardFocusTarget(event.relatedTarget)) return;
215+
viewportHeightBeforeKeyboard = null;
216+
setKeyboardInset(false);
217+
// Clearing the height override on focus loss is the iOS-only behaviour
218+
// described above; the bottom inset resets on every platform.
219+
if (!restoreImmediatelyOnKeyboardDismissal) return;
168220
if (animationFrame !== null) {
169221
window.cancelAnimationFrame(animationFrame);
170222
animationFrame = null;
@@ -173,6 +225,10 @@ export function useMobileVisualViewportHeight(
173225
};
174226
const handleFocusIn = (event: FocusEvent) => {
175227
if (!isKeyboardFocusTarget(event.target)) return;
228+
// Remember the height before the keyboard animates in; the shrink from
229+
// this value is the only reliable signal that it opened, because iOS may
230+
// resize the layout viewport too and hide the difference.
231+
viewportHeightBeforeKeyboard ??= visualViewport.height;
176232
// Programmatic focus (composer autofocus) can be the only trigger for a
177233
// keyboard, so this must always schedule a full, freshly measured pass.
178234
scheduleContainingBlockUpdate();
@@ -183,10 +239,10 @@ export function useMobileVisualViewportHeight(
183239
visualViewport.addEventListener("scroll", handleVisualViewportScroll);
184240
window.addEventListener("resize", scheduleContainingBlockUpdate);
185241
window.addEventListener("orientationchange", scheduleContainingBlockUpdate);
186-
if (restoreImmediatelyOnKeyboardDismissal) {
187-
document.addEventListener("focusout", handleFocusOut);
188-
document.addEventListener("focusin", handleFocusIn);
189-
}
242+
// The focus listeners drive the bottom-inset override on every platform,
243+
// so they are no longer gated on the iOS keyboard-dismissal behaviour.
244+
document.addEventListener("focusout", handleFocusOut);
245+
document.addEventListener("focusin", handleFocusIn);
190246

191247
return () => {
192248
visualViewport.removeEventListener("resize", scheduleUpdate);
@@ -196,13 +252,12 @@ export function useMobileVisualViewportHeight(
196252
"orientationchange",
197253
scheduleContainingBlockUpdate,
198254
);
199-
if (restoreImmediatelyOnKeyboardDismissal) {
200-
document.removeEventListener("focusout", handleFocusOut);
201-
document.removeEventListener("focusin", handleFocusIn);
202-
}
255+
document.removeEventListener("focusout", handleFocusOut);
256+
document.removeEventListener("focusin", handleFocusIn);
203257
if (animationFrame !== null) {
204258
window.cancelAnimationFrame(animationFrame);
205259
}
260+
setKeyboardInset(false);
206261
clearViewportOverride();
207262
};
208263
}, [

‎apps/app/src/components/promptbox/PromptBoxInternal.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ import {
4141
useAppCommandShortcut,
4242
} from "@/components/commands/AppCommandProvider";
4343
import { canLoadMoreCommandResults } from "@/components/promptbox/mentions/mention-menu-scroll";
44+
import {
45+
voiceUnsupportedMessage,
46+
type VoiceUnsupportedReason,
47+
} from "@/hooks/voice-input-support";
4448
import { Button } from "@bb/shared-ui/button";
4549
import { Icon } from "@bb/shared-ui/icon";
4650
import {
@@ -377,6 +381,8 @@ type PromptVoiceState = "idle" | "recording" | "transcribing" | "error";
377381
export interface PromptVoiceConfig {
378382
state: PromptVoiceState;
379383
isSupported: boolean;
384+
/** Why voice is unavailable; absent when it is supported. */
385+
unsupportedReason?: VoiceUnsupportedReason | null;
380386
stream: MediaStream | null;
381387
start: () => void | Promise<void>;
382388
stop: () => void;
@@ -3397,7 +3403,9 @@ export function PromptBoxInternal({
33973403
variant="ghost"
33983404
aria-label={
33993405
!voice.isSupported
3400-
? "Voice input is not supported in this browser"
3406+
? voiceUnsupportedMessage(
3407+
voice.unsupportedReason ?? null,
3408+
)
34013409
: "Start voice input"
34023410
}
34033411
disabled={!canStartVoiceInput}

‎apps/app/src/components/promptbox/usePromptVoice.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ vi.mock("@/hooks/useVoiceInput", () => ({
1818
const voiceInput = {
1919
state: "transcribing" as const,
2020
isSupported: true,
21+
unsupportedReason: null,
2122
stream: null,
2223
start: vi.fn(),
2324
stop: vi.fn(),

‎apps/app/src/components/settings/SettingsSidebar.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import {
44
SectionSidebar,
55
SectionSidebarIcon,
66
SectionSidebarLabel,
7+
SectionSidebarActionRow,
78
SectionSidebarRow,
89
} from "@/components/sidebar/SectionSidebar";
10+
import { canOpenNativeScreen, shellOpenNative } from "@/lib/native-shell";
911
import {
1012
SETTINGS_ROUTE_PATH,
1113
getPluginConfigurationRoutePath,
@@ -101,6 +103,22 @@ export function SettingsSidebarContent({
101103
</div>
102104
</>
103105
) : null}
106+
{canOpenNativeScreen() ? (
107+
<>
108+
<div className="mt-4">
109+
<SectionSidebarLabel>This phone</SectionSidebarLabel>
110+
</div>
111+
<div className="mt-1 space-y-0.5">
112+
<SectionSidebarActionRow
113+
label="This device"
114+
testId="settings-nav-native-device"
115+
onClick={() => shellOpenNative("device-settings")}
116+
>
117+
<SectionSidebarIcon name="Smartphone" />
118+
</SectionSidebarActionRow>
119+
</div>
120+
</>
121+
) : null}
104122
{sections.some((section) => section.id === "archived") ? (
105123
<>
106124
<div className="mt-4">

‎apps/app/src/components/sidebar/SectionSidebar.tsx‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,39 @@ export function SectionSidebarRow({
6464
);
6565
}
6666

67+
/**
68+
* A sidebar row that runs an action instead of navigating. The mobile shell
69+
* uses it to reach a native screen the page cannot render itself.
70+
*/
71+
export function SectionSidebarActionRow({
72+
children,
73+
label,
74+
onClick,
75+
testId,
76+
}: {
77+
children: ReactNode;
78+
label: string;
79+
onClick: () => void;
80+
testId?: string;
81+
}) {
82+
const closeOnMobile = useCloseMobileSidebar();
83+
return (
84+
<Button
85+
size="sm"
86+
variant="ghost"
87+
data-testid={testId}
88+
className={cn(PROJECT_LIST_ACTION_BUTTON_CLASS, "w-full")}
89+
onClick={() => {
90+
closeOnMobile();
91+
onClick();
92+
}}
93+
>
94+
{children}
95+
<span className="min-w-0 flex-1 truncate text-left">{label}</span>
96+
</Button>
97+
);
98+
}
99+
67100
export function SectionSidebarLabel({ children }: { children: ReactNode }) {
68101
return (
69102
<div

0 commit comments

Comments
 (0)