Skip to content

Commit d0e621e

Browse files
shivamhwpclaude
andauthored
fix(mobile): the question card uses the whole screen while the keyboard is closed (#24363)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 6e79211 commit d0e621e

3 files changed

Lines changed: 36 additions & 45 deletions

File tree

‎apps/mobile/src/features/threads/PendingUserInputCard.tsx‎

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import Animated, {
88
Easing,
99
FadeInUp,
1010
FadeOutDown,
11-
LinearTransition,
1211
useAnimatedStyle,
1312
useSharedValue,
14-
withTiming,
13+
type DerivedValue,
1514
type SharedValue,
1615
} from "react-native-reanimated";
1716

@@ -33,7 +32,7 @@ import {
3332
export interface PendingUserInputCardProps {
3433
readonly canOperateThread: boolean;
3534
readonly pendingUserInput: PendingUserInput;
36-
readonly maxHeight: number;
35+
readonly maxHeight: DerivedValue<number>;
3736
readonly collapsed: boolean;
3837
readonly onToggleCollapsed: () => void;
3938
readonly onStopThread?: () => void;
@@ -64,8 +63,6 @@ export interface PendingUserInputCardProps {
6463
*/
6564
const EXPANDED_CARD_IS_OVERLAY = Platform.OS === "ios";
6665

67-
const CARD_LAYOUT_TRANSITION = LinearTransition.duration(200);
68-
6966
function QuestionText(props: { readonly markdown: string }) {
7067
const styles = useMarkdownPreviewStyles();
7168
const openLink = useOpenPullRequest();
@@ -92,18 +89,9 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
9289
if (!cardCoverage) {
9390
return;
9491
}
95-
const coverage = Math.max(0, cardHeightRef.current - barHeightRef.current);
96-
if (coverage === cardCoverage.value) {
97-
return;
98-
}
99-
if (cardCoverage.value === 0) {
100-
cardCoverage.value = coverage;
101-
return;
102-
}
103-
cardCoverage.value = withTiming(coverage, {
104-
duration: USER_INPUT_TOGGLE_DURATION_MS,
105-
easing: Easing.out(Easing.cubic),
106-
});
92+
// The card resizes with the keyboard every frame, so easing each sample would leave the
93+
// feed inset and floating controls trailing it.
94+
cardCoverage.value = Math.max(0, cardHeightRef.current - barHeightRef.current);
10795
}, [cardCoverage]);
10896
const handleBarLayout = useCallback(
10997
(event: LayoutChangeEvent) => {
@@ -121,12 +109,16 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
121109
[cardHeight, notifyCoverage],
122110
);
123111
const cardProgress = props.cardProgress;
112+
const maxHeight = props.maxHeight;
124113
const cardAnimatedStyle = useAnimatedStyle(() => {
125114
const progress = cardProgress === undefined ? 1 : cardProgress.value;
126115
return {
116+
maxHeight: maxHeight.value,
127117
transform: [{ translateY: (1 - progress) * cardHeight.value }],
128118
};
129119
});
120+
const cardMaxHeightStyle = useAnimatedStyle(() => ({ maxHeight: maxHeight.value }));
121+
const overlayHeightStyle = useAnimatedStyle(() => ({ height: maxHeight.value }));
130122

131123
// On iOS the card stays MOUNTED while collapsed (hidden via the animated
132124
// style): expanding animates existing views on the UI thread the same
@@ -192,13 +184,8 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
192184
? undefined
193185
: FadeOutDown.duration(USER_INPUT_TOGGLE_DURATION_MS).easing(Easing.out(Easing.cubic))
194186
}
195-
layout={CARD_LAYOUT_TRANSITION}
196187
className="overflow-hidden gap-2.5 rounded-[20px] border border-border bg-card-alt p-4"
197-
style={
198-
EXPANDED_CARD_IS_OVERLAY
199-
? [{ maxHeight: props.maxHeight }, cardAnimatedStyle]
200-
: { maxHeight: props.maxHeight }
201-
}
188+
style={EXPANDED_CARD_IS_OVERLAY ? cardAnimatedStyle : cardMaxHeightStyle}
202189
>
203190
<Pressable
204191
accessibilityRole="button"
@@ -330,13 +317,13 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
330317
<View className="relative">
331318
{bar}
332319
{EXPANDED_CARD_IS_OVERLAY ? (
333-
<View
320+
<Animated.View
334321
pointerEvents={props.collapsed ? "none" : "box-none"}
335322
className="absolute inset-x-0 bottom-0 justify-end overflow-hidden"
336-
style={{ height: props.maxHeight }}
323+
style={overlayHeightStyle}
337324
>
338325
{card}
339-
</View>
326+
</Animated.View>
340327
) : (
341328
card
342329
)}

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ import {
9999
KeyboardController,
100100
KeyboardStickyView,
101101
useKeyboardState,
102+
useReanimatedKeyboardAnimation,
102103
} from "react-native-keyboard-controller";
103104
import Animated, {
104105
Easing,
@@ -956,10 +957,8 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
956957
);
957958
const userInputCollapsed =
958959
activeUserInputRequestId !== null && collapsedUserInputRequestId === activeUserInputRequestId;
959-
// The card's height RESERVES keyboard space at all times instead of tracking the keyboard:
960-
// transforms (the sticky translation) apply same-frame on the UI thread while layout props lag
961-
// a Yoga pass behind, so any height that follows the keyboard flashes the card over the nav
962-
// header on the way up.
960+
// A height React sets from keyboard state lags the sticky translation by a Yoga pass and
961+
// flashes over the nav header on the way up, so the usage panel reserves the keyboard instead.
963962
const [lastKnownKeyboardHeight, setLastKnownKeyboardHeight] = useState(0);
964963
useEffect(() => {
965964
if (liveKeyboardHeight > 0 && liveKeyboardHeight !== lastKnownKeyboardHeight) {
@@ -968,12 +967,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
968967
}, [lastKnownKeyboardHeight, liveKeyboardHeight]);
969968
const reservedKeyboardHeight =
970969
lastKnownKeyboardHeight > 0 ? lastKnownKeyboardHeight : ESTIMATED_KEYBOARD_HEIGHT;
971-
const pendingUserInputMaxHeight = derivePendingUserInputMaxHeight({
972-
windowHeight,
973-
keyboardHeight: reservedKeyboardHeight,
974-
navigationHeaderHeight,
975-
composerOverlapHeight: composerBottomInset,
976-
});
970+
// Waiting for a visibility render misses the first keyboard frames.
971+
const keyboardStickyEnabled =
972+
Platform.OS === "ios"
973+
? deviceType !== "duo-unfolded" || (composerOwnsKeyboard && !sidebarSearchActive)
974+
: !keyboardStateSuspect;
977975
const estimatedOverlayHeight = composerOverlapHeight;
978976
// The overlay's measured height includes the home-indicator inset (the
979977
// composer pads it), but contentInsetAdjustmentBehavior="automatic" makes
@@ -1000,6 +998,18 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
1000998
setScreenHeight(event.nativeEvent.layout.height);
1001999
}, []);
10021000
const screenAreaHeight = screenHeight ?? windowHeight;
1001+
// The question card reads the keyboard frame on the UI thread, in the same frame the sticky
1002+
// view translates, so it gets the full height while the keyboard is closed and never crosses
1003+
// the header while the keyboard moves.
1004+
const { height: keyboardTranslation } = useReanimatedKeyboardAnimation();
1005+
const pendingUserInputMaxHeight = useDerivedValue(() =>
1006+
derivePendingUserInputMaxHeight({
1007+
windowHeight: screenAreaHeight,
1008+
keyboardHeight: keyboardStickyEnabled ? -keyboardTranslation.value : 0,
1009+
navigationHeaderHeight,
1010+
composerOverlapHeight: composerBottomInset,
1011+
}),
1012+
);
10031013
// The usage panel stacks with the composer and any approval card, so it gets
10041014
// whatever room they leave below the header. Measured only while it is open
10051015
// so typing in the composer does not re-render the screen.
@@ -1024,9 +1034,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
10241034
usageLimitsLayout.overlay > 0
10251035
? usageLimitsLayout.overlay - usageLimitsLayout.panel
10261036
: composerOverlapHeight;
1027-
// The keyboard is reserved even while closed, like the question card, so the
1028-
// panel never grows over the header while the keyboard animates. The floor
1029-
// keeps the close row on screen when the stack below leaves no room at all.
1037+
// The floor keeps the close row on screen when the stack below leaves no room at all.
10301038
const usageLimitsMaxHeight = Math.max(
10311039
USAGE_LIMITS_PANEL_MIN_HEIGHT,
10321040
Math.min(
@@ -1536,12 +1544,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
15361544

15371545
{showContent ? (
15381546
<KeyboardStickyView
1539-
// Waiting for a visibility render misses the first keyboard frames.
1540-
enabled={
1541-
Platform.OS === "ios"
1542-
? deviceType !== "duo-unfolded" || (composerOwnsKeyboard && !sidebarSearchActive)
1543-
: !keyboardStateSuspect
1544-
}
1547+
enabled={keyboardStickyEnabled}
15451548
pointerEvents="box-none"
15461549
style={{ position: "absolute", bottom: 0, left: 0, right: 0, top: 0 }}
15471550
offset={{ closed: 0, opened: composerKeyboardOffset }}

‎apps/mobile/src/features/threads/pendingUserInputLayout.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function derivePendingUserInputMaxHeight(input: {
1616
readonly navigationHeaderHeight: number;
1717
readonly composerOverlapHeight: number;
1818
}): number {
19+
"worklet";
1920
const availableHeight =
2021
input.windowHeight -
2122
Math.max(0, input.keyboardHeight) -

0 commit comments

Comments
 (0)