From 8567239be4520fdf48fc56da4090ee356b243acc Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 17:38:51 +0000 Subject: [PATCH 1/3] fix(mobile): Android terminal moves up with the keyboard instead of snapping AI-assisted; verified with the tests and tools listed above. --- .../terminal/ThreadTerminalRouteScreen.tsx | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx index 90fac17f8004a..f5cd6c62d060c 100644 --- a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx +++ b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx @@ -27,7 +27,9 @@ import { KeyboardController, KeyboardStickyView, useKeyboardState, + useReanimatedKeyboardAnimation, } from "react-native-keyboard-controller"; +import Animated, { useAnimatedStyle } from "react-native-reanimated"; import { ComposerToolbarButton, @@ -585,6 +587,14 @@ function ThreadTerminal(props: { : !SHOWCASE_ENABLED; const terminalBottomInset = (isKeyboardVisible ? keyboardHeight : 0) + (isAccessoryVisible ? TERMINAL_ACCESSORY_HEIGHT : 0); + // Android's keyboard state lands after the IME starts moving, so the inset follows the + // keyboard's UI-thread animation instead of stepping to its final height. + const keyboardAnimation = useReanimatedKeyboardAnimation(); + const accessoryInset = isAccessoryVisible ? TERMINAL_ACCESSORY_HEIGHT : 0; + const androidTerminalInsetStyle = useAnimatedStyle(() => ({ + paddingBottom: + -keyboardAnimation.height.value + keyboardAnimation.progress.value * accessoryInset, + })); const terminalMenuSessions: ReadonlyArray = buildTerminalMenuSessions({ knownSessions: knownSessions ?? [], @@ -897,11 +907,13 @@ function ThreadTerminal(props: { ) : ( <> - - + {Platform.OS === "android" && !isKeyboardVisible ? ( From 45f6c1b563513ebdb9cd331b37a3f9f325f93907 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 17:59:46 +0000 Subject: [PATCH 2/3] fix(mobile): Android terminal reserves the full toolbar and resizes once per keyboard move AI-assisted; verified with the tests and tools listed above. --- .../terminal/ThreadTerminalRouteScreen.tsx | 19 +++++++++--- .../terminal/terminalKeyboardShowing.test.ts | 23 +++++++++++++- .../terminal/terminalKeyboardShowing.ts | 30 +++++++++++++++++-- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx index f5cd6c62d060c..36c5dccd93fb8 100644 --- a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx +++ b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx @@ -91,7 +91,11 @@ import { } from "./terminalInput"; import { createTerminalPasteSession } from "./terminalPaste"; import { cacheTerminalGridSize, getCachedTerminalGridSize } from "./terminalUiState"; -import { getKeyboardShowEpoch, subscribeKeyboardShowing } from "./terminalKeyboardShowing"; +import { + getKeyboardShowEpoch, + runWhenKeyboardSettles, + subscribeKeyboardShowing, +} from "./terminalKeyboardShowing"; function TerminalHeader(props: { readonly subtitle: string; @@ -592,8 +596,7 @@ function ThreadTerminal(props: { const keyboardAnimation = useReanimatedKeyboardAnimation(); const accessoryInset = isAccessoryVisible ? TERMINAL_ACCESSORY_HEIGHT : 0; const androidTerminalInsetStyle = useAnimatedStyle(() => ({ - paddingBottom: - -keyboardAnimation.height.value + keyboardAnimation.progress.value * accessoryInset, + paddingBottom: -keyboardAnimation.height.value + accessoryInset, })); const terminalMenuSessions: ReadonlyArray = buildTerminalMenuSessions({ @@ -676,7 +679,15 @@ function ThreadTerminal(props: { size, ); } - terminalSessionDriver.reportGridSize(size); + // The view shrinks locally on every frame of the Android keyboard animation; the PTY + // only needs the size it settles at. + if (Platform.OS === "android") { + runWhenKeyboardSettles(terminalSessionDriver, () => + terminalSessionDriver.reportGridSize(size), + ); + } else { + terminalSessionDriver.reportGridSize(size); + } }; const handleSelectTerminal = (nextTerminalId: string) => { diff --git a/apps/mobile/src/features/terminal/terminalKeyboardShowing.test.ts b/apps/mobile/src/features/terminal/terminalKeyboardShowing.test.ts index 2d5272d351096..b795ac48c1b5e 100644 --- a/apps/mobile/src/features/terminal/terminalKeyboardShowing.test.ts +++ b/apps/mobile/src/features/terminal/terminalKeyboardShowing.test.ts @@ -14,7 +14,11 @@ vi.mock("react-native-keyboard-controller", () => ({ }, })); -import { getKeyboardShowEpoch, subscribeKeyboardShowing } from "./terminalKeyboardShowing"; +import { + getKeyboardShowEpoch, + runWhenKeyboardSettles, + subscribeKeyboardShowing, +} from "./terminalKeyboardShowing"; function emit(name: string) { for (const listener of listeners.get(name) ?? []) listener(); @@ -64,3 +68,20 @@ it("keeps the accessory through Android's did-only repair and starts a new show }); for (const unsubscribe of unsubscribes) unsubscribe(); }); + +it("runs only the latest deferred call once the keyboard stops moving", () => { + emit("keyboardDidHide"); + const owner = {}; + const reported: number[] = []; + runWhenKeyboardSettles(owner, () => reported.push(1)); + emit("keyboardWillShow"); + for (const rows of [40, 35, 30]) runWhenKeyboardSettles(owner, () => reported.push(rows)); + const whileOpening = [...reported]; + emit("keyboardDidShow"); + emit("keyboardWillHide"); + runWhenKeyboardSettles(owner, () => reported.push(45)); + emit("keyboardDidHide"); + emit("keyboardDidHide"); + + expect({ whileOpening, reported }).toEqual({ whileOpening: [1], reported: [1, 30, 45] }); +}); diff --git a/apps/mobile/src/features/terminal/terminalKeyboardShowing.ts b/apps/mobile/src/features/terminal/terminalKeyboardShowing.ts index 7f3c745c6f1ab..d2e1a247ffc33 100644 --- a/apps/mobile/src/features/terminal/terminalKeyboardShowing.ts +++ b/apps/mobile/src/features/terminal/terminalKeyboardShowing.ts @@ -8,27 +8,53 @@ const subscribers = new Set<() => void>(); let showEpoch = 1; let keyboardShowing = KeyboardController.isVisible(); let hiddenSinceShow = !keyboardShowing; +let keyboardMoving = false; +const settleRuns = new Map void>(); const notify = () => { for (const subscriber of subscribers) subscriber(); }; +const settle = () => { + keyboardMoving = false; + const runs = [...settleRuns.values()]; + settleRuns.clear(); + for (const run of runs) run(); +}; const show = () => { if (hiddenSinceShow) showEpoch += 1; hiddenSinceShow = false; keyboardShowing = true; notify(); }; -KeyboardEvents.addListener("keyboardWillShow", show); -KeyboardEvents.addListener("keyboardDidShow", show); +KeyboardEvents.addListener("keyboardWillShow", () => { + keyboardMoving = true; + show(); +}); +KeyboardEvents.addListener("keyboardDidShow", () => { + show(); + settle(); +}); KeyboardEvents.addListener("keyboardWillHide", () => { + keyboardMoving = true; keyboardShowing = false; hiddenSinceShow = true; notify(); }); KeyboardEvents.addListener("keyboardDidHide", () => { hiddenSinceShow = true; + settle(); }); +// Runs now, or once the keyboard stops moving; a later call for the same owner replaces it. +export function runWhenKeyboardSettles(owner: object, run: () => void) { + if (!keyboardMoving) { + settleRuns.delete(owner); + run(); + return; + } + settleRuns.set(owner, run); +} + export function subscribeKeyboardShowing(onChange: () => void) { subscribers.add(onChange); return () => { From 08b77a1e39c09db563de83aaa3de9ec81c3edfa7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 19:15:14 +0000 Subject: [PATCH 3/3] fix(mobile): Android terminal toolbar and bottom bar follow the keyboard instead of the late JS state AI-assisted; verified with the tests and tools listed above. --- .../terminal/ThreadTerminalRouteScreen.tsx | 96 +++++++++++++------ 1 file changed, 69 insertions(+), 27 deletions(-) diff --git a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx index 36c5dccd93fb8..d0c9314bc3541 100644 --- a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx +++ b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx @@ -26,10 +26,15 @@ import { AsyncResult } from "effect/reactivity"; import { KeyboardController, KeyboardStickyView, + useGenericKeyboardHandler, useKeyboardState, useReanimatedKeyboardAnimation, } from "react-native-keyboard-controller"; -import Animated, { useAnimatedStyle } from "react-native-reanimated"; +import Animated, { + useAnimatedStyle, + useDerivedValue, + useSharedValue, +} from "react-native-reanimated"; import { ComposerToolbarButton, @@ -591,12 +596,41 @@ function ThreadTerminal(props: { : !SHOWCASE_ENABLED; const terminalBottomInset = (isKeyboardVisible ? keyboardHeight : 0) + (isAccessoryVisible ? TERMINAL_ACCESSORY_HEIGHT : 0); - // Android's keyboard state lands after the IME starts moving, so the inset follows the - // keyboard's UI-thread animation instead of stepping to its final height. + // Android's keyboard state lands after the IME finishes moving, so the terminal inset, the + // accessory and the bar below the terminal all follow the keyboard on the UI thread instead. const keyboardAnimation = useReanimatedKeyboardAnimation(); - const accessoryInset = isAccessoryVisible ? TERMINAL_ACCESSORY_HEIGHT : 0; + const keyboardOpening = useSharedValue(0); + useGenericKeyboardHandler( + { + onStart: (event) => { + "worklet"; + keyboardOpening.set(event.height > 0 ? 1 : 0); + }, + }, + [], + ); + const [androidBarHeight, setAndroidBarHeight] = useState(0); + const accessoryAllowed = canOperateTerminal ? 1 : 0; + // Did-only IME repairs never start an animation, so the JS state still shows the accessory. + const accessoryShownByState = isAccessoryVisible ? 1 : 0; + const androidAccessoryReserve = useDerivedValue( + () => + TERMINAL_ACCESSORY_HEIGHT * + accessoryAllowed * + Math.max(keyboardOpening.value, accessoryShownByState) * + keyboardAnimation.progress.value, + ); + // The bar stays laid out under the keyboard, so the terminal only needs what exceeds it. const androidTerminalInsetStyle = useAnimatedStyle(() => ({ - paddingBottom: -keyboardAnimation.height.value + accessoryInset, + paddingBottom: Math.max( + 0, + -keyboardAnimation.height.value + androidAccessoryReserve.value - androidBarHeight, + ), + })); + // The accessory rises from under the keyboard's top edge by the height reserved for it. + const androidAccessoryStyle = useAnimatedStyle(() => ({ + opacity: androidAccessoryReserve.value > 0 ? 1 : 0, + transform: [{ translateY: TERMINAL_ACCESSORY_HEIGHT - androidAccessoryReserve.value }], })); const terminalMenuSessions: ReadonlyArray = buildTerminalMenuSessions({ @@ -862,7 +896,6 @@ function ThreadTerminal(props: { : terminalTheme.background, // Measured top reservation is zero when UIKit already inset the body or moved the bar. paddingTop: contentTopInset, - paddingBottom: Platform.OS === "android" && !isKeyboardVisible ? insets.bottom : 0, }} > {!isEnvironmentReady ? ( @@ -960,20 +993,26 @@ function ThreadTerminal(props: { /> - {Platform.OS === "android" && !isKeyboardVisible ? ( - - {hasNativeTerminalSurface() ? ( -