From ee5c3e985bfa7433e758122ca02e4c2ecff1f21f Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Sun, 18 Oct 2026 21:50:39 -0500 Subject: [PATCH 1/5] fix(mobile): animate Android terminal insets with the keyboard --- .../terminal/ThreadTerminalRouteScreen.tsx | 78 +++++++++++++------ .../terminal/useTerminalGridSync.test.ts | 37 +++++++++ .../features/terminal/useTerminalGridSync.ts | 38 ++++++--- 3 files changed, 118 insertions(+), 35 deletions(-) diff --git a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx index 239fbeda7d390..e5b5470f53828 100644 --- a/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx +++ b/apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx @@ -14,6 +14,7 @@ import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { Platform, Pressable, View } from "react-native"; +import Animated, { useAnimatedStyle } from "react-native-reanimated"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { AppText as Text } from "../../components/ui/AppText"; import { TerminalContextSheet } from "./TerminalContextSheet"; @@ -25,6 +26,7 @@ import { KeyboardEvents, KeyboardStickyView, useKeyboardState, + useReanimatedKeyboardAnimation, } from "react-native-keyboard-controller"; import { @@ -481,6 +483,7 @@ export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps) terminal, size: lastGridSize, resize: resizeTerminal, + settleDelayMs: Platform.OS === "android" ? 120 : 0, }); const bufferReplayKey = useMemo( () => getTerminalBufferReplayKey({ terminalKey, fontSize }), @@ -606,14 +609,30 @@ export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps) const terminalBottomInset = (keyboardState.isVisible ? keyboardState.height : 0) + (isAccessoryVisible ? TERMINAL_ACCESSORY_HEIGHT : 0); + const { height: keyboardHeight, progress: keyboardProgress } = useReanimatedKeyboardAnimation(); + const androidViewportStyle = useAnimatedStyle(() => ({ + paddingBottom: + -keyboardHeight.value + + keyboardProgress.value * (canOperateTerminal ? TERMINAL_ACCESSORY_HEIGHT : 0) + + (1 - keyboardProgress.value) * (56 + insets.bottom), + })); + const androidBottomBarStyle = useAnimatedStyle(() => ({ + opacity: 1 - keyboardProgress.value, + })); + const androidAccessoryStyle = useAnimatedStyle(() => ({ + opacity: keyboardProgress.value, + })); useEffect(() => { const keyboardWillShow = KeyboardEvents.addListener("keyboardWillShow", () => { setIsAccessoryDismissed(false); }); - const keyboardWillHide = KeyboardEvents.addListener("keyboardWillHide", () => { - setIsAccessoryDismissed(true); - }); + const keyboardWillHide = KeyboardEvents.addListener( + Platform.OS === "android" ? "keyboardDidHide" : "keyboardWillHide", + () => { + setIsAccessoryDismissed(true); + }, + ); return () => { keyboardWillShow.remove(); @@ -1205,8 +1224,6 @@ export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps) // reservation is zero when UIKit has already inset the body or moved the bar. paddingTop: Platform.OS === "ios" ? (nativeColumnMetrics?.safeArea.top ?? insets.top) : 0, - paddingBottom: - Platform.OS === "android" && !keyboardState.isVisible ? insets.bottom : 0, }} > {!isEnvironmentReady ? ( @@ -1256,11 +1273,13 @@ export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps) ) : ( <> - - - - {Platform.OS === "android" && !keyboardState.isVisible ? ( - + + + {Platform.OS === "android" ? ( + {selectedThread && hasNativeTerminalSurface() ? (