Skip to content
TypeScript

fix(mobile): /usage-limits panel no longer hides its close button under the header when the keyboard is open (#20910)

shivam0b72c07870ac
diff --git a/apps/mobile/src/features/threads/ComposerUsageLimits.tsx b/apps/mobile/src/features/threads/ComposerUsageLimits.tsx
index 994e98402d2..7044a8d70a3 100644
--- a/apps/mobile/src/features/threads/ComposerUsageLimits.tsx
+++ b/apps/mobile/src/features/threads/ComposerUsageLimits.tsx
@@ -1,5 +1,5 @@
import type { EnvironmentId, UsageLimitsReport } from "@t3tools/contracts";
-import { Pressable, ScrollView, useWindowDimensions, View } from "react-native";
+import { Pressable, ScrollView, View } from "react-native";
import { SymbolView } from "../../components/ui/AppSymbol";
import { AppText as Text } from "../../components/ui/AppText";
@@ -10,14 +10,15 @@ const DRIVER_LABEL: Partial<Record<string, string>> = { codex: "Codex", claudeAg
export function ComposerUsageLimits({
report,
environmentId,
+ maxHeight,
onClose,
}: {
readonly report: UsageLimitsReport;
readonly environmentId: EnvironmentId;
+ readonly maxHeight: number;
readonly onClose: () => void;
}) {
const now = Date.parse(report.createdAt);
- const { height } = useWindowDimensions();
const close = (
<Pressable
accessibilityLabel="Dismiss usage limits"
@@ -31,11 +32,7 @@ export function ComposerUsageLimits({
);
return (
<View className="overflow-hidden rounded-[20px] border-continuous bg-card">
- <ScrollView
- bounces={false}
- showsVerticalScrollIndicator={false}
- style={{ maxHeight: Math.round(height * 0.4) }}
- >
+ <ScrollView bounces={false} showsVerticalScrollIndicator={false} style={{ maxHeight }}>
{report.accounts.map((account, index) => {
const resetCreditInput =
account.resetCreditInput ??
diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
index 500abb7575a..6d354e57c50 100644
--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
@@ -66,6 +66,7 @@ import {
useWindowDimensions,
View,
type GestureResponderEvent,
+ type LayoutChangeEvent,
type ViewInstance,
} from "react-native";
import {
@@ -319,6 +320,9 @@ function useStreamingHaptics(threadId: ThreadId, feed: ReadonlyArray<ThreadFeedE
}, [threadId, feed]);
}
+const USAGE_LIMITS_PANEL_GAP = 12;
+const USAGE_LIMITS_PANEL_MIN_HEIGHT = 44;
+
const USER_INPUT_TOGGLE_TIMING = {
duration: USER_INPUT_TOGGLE_DURATION_MS,
easing: Easing.out(Easing.cubic),
@@ -668,10 +672,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
setLastKnownKeyboardHeight(liveKeyboardHeight);
}
}, [lastKnownKeyboardHeight, liveKeyboardHeight]);
+ const reservedKeyboardHeight =
+ lastKnownKeyboardHeight > 0 ? lastKnownKeyboardHeight : ESTIMATED_KEYBOARD_HEIGHT;
const pendingUserInputMaxHeight = derivePendingUserInputMaxHeight({
windowHeight,
- keyboardHeight:
- lastKnownKeyboardHeight > 0 ? lastKnownKeyboardHeight : ESTIMATED_KEYBOARD_HEIGHT,
+ keyboardHeight: reservedKeyboardHeight,
navigationHeaderHeight,
composerOverlapHeight: composerBottomInset,
});
@@ -692,6 +697,51 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
-nativeInsetOvercount,
Platform.OS === "ios" ? COMPOSER_TRANSITION_DURATION_MS : 0,
);
+ // Android lays the screen out below its opaque header and reports a zero
+ // header height, so the window height overstates the room by the header.
+ const [screenHeight, setScreenHeight] = useState<number | null>(null);
+ const handleScreenLayout = useCallback((event: LayoutChangeEvent) => {
+ setScreenHeight(event.nativeEvent.layout.height);
+ }, []);
+ const screenAreaHeight = screenHeight ?? windowHeight;
+ // The usage panel stacks with the composer and any approval card, so it gets
+ // whatever room they leave below the header. Measured only while it is open
+ // so typing in the composer does not re-render the screen.
+ const usageLimitsOpen = usageLimitsReport !== null && activeUserInputRequestId === null;
+ const [usageLimitsLayout, setUsageLimitsLayout] = useState({ overlay: 0, panel: 0 });
+ const handleComposerOverlayLayout = useCallback(
+ (event: LayoutChangeEvent) => {
+ onComposerLayout(event);
+ if (!usageLimitsOpen) return;
+ const overlay = event.nativeEvent.layout.height;
+ setUsageLimitsLayout((current) =>
+ current.overlay === overlay ? current : { ...current, overlay },
+ );
+ },
+ [onComposerLayout, usageLimitsOpen],
+ );
+ const handleUsageLimitsLayout = useCallback((event: LayoutChangeEvent) => {
+ const panel = event.nativeEvent.layout.height;
+ setUsageLimitsLayout((current) => (current.panel === panel ? current : { ...current, panel }));
+ }, []);
+ const overlayBesideUsageLimits =
+ usageLimitsLayout.overlay > 0
+ ? usageLimitsLayout.overlay - usageLimitsLayout.panel
+ : composerOverlapHeight;
+ // The keyboard is reserved even while closed, like the question card, so the
+ // panel never grows over the header while the keyboard animates. The floor
+ // keeps the close row on screen when the stack below leaves no room at all.
+ const usageLimitsMaxHeight = Math.max(
+ USAGE_LIMITS_PANEL_MIN_HEIGHT,
+ Math.min(
+ Math.round(screenAreaHeight * 0.4),
+ screenAreaHeight -
+ navigationHeaderHeight -
+ reservedKeyboardHeight -
+ overlayBesideUsageLimits -
+ USAGE_LIMITS_PANEL_GAP * 2,
+ ),
+ );
const userInputCardProgress = useSharedValue(1);
const userInputInsetProgress = useSharedValue(1);
const userInputCardCoverage = useSharedValue(0);
@@ -1037,7 +1087,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
};
return (
- <View className="flex-1">
+ <View className="flex-1" onLayout={handleScreenLayout}>
{!usesNativeWorkspaceColumns ? <NativeLayoutObserver onChange={setScreenMetrics} /> : null}
<ThreadVisitWatermark
environmentId={props.environmentId}
@@ -1157,7 +1207,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
{/* No paddingTop here: the overlay's measured height becomes the
list's bottom inset, so any padding above the pill/composer
pushes the resting content floor up by the same amount. */}
- <View ref={composerOverlayRef} onLayout={onComposerLayout} className="w-full">
+ <View
+ ref={composerOverlayRef}
+ onLayout={handleComposerOverlayLayout}
+ className="w-full"
+ >
<FloatingWorkingControl
colorScheme={isDarkMode ? "dark" : "light"}
status={floatingStatus}
@@ -1233,13 +1287,16 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
) : null}
{usageLimitsReport && activeUserInputRequestId === null ? (
<Animated.View
- className="shrink-0 px-4 pb-3"
+ className="shrink-0 px-4"
+ style={{ paddingBottom: USAGE_LIMITS_PANEL_GAP }}
+ onLayout={handleUsageLimitsLayout}
entering={FadeInDown.duration(220)}
exiting={FadeOut.duration(140)}
>
<ComposerUsageLimits
report={usageLimitsReport}
environmentId={props.environmentId}
+ maxHeight={usageLimitsMaxHeight}
onClose={dismissUsageLimits}
/>
</Animated.View>