Skip to content
TypeScript

fix(mobile): the question card uses the whole screen while the keyboard is closed (#24363)

shivamd0e621e9f9db
diff --git a/apps/mobile/src/features/threads/PendingUserInputCard.tsx b/apps/mobile/src/features/threads/PendingUserInputCard.tsx
index 6be28f295d6..1086422789a 100644
--- a/apps/mobile/src/features/threads/PendingUserInputCard.tsx
+++ b/apps/mobile/src/features/threads/PendingUserInputCard.tsx
@@ -8,10 +8,9 @@ import Animated, {
Easing,
FadeInUp,
FadeOutDown,
- LinearTransition,
useAnimatedStyle,
useSharedValue,
- withTiming,
+ type DerivedValue,
type SharedValue,
} from "react-native-reanimated";
@@ -33,7 +32,7 @@ import {
export interface PendingUserInputCardProps {
readonly canOperateThread: boolean;
readonly pendingUserInput: PendingUserInput;
- readonly maxHeight: number;
+ readonly maxHeight: DerivedValue<number>;
readonly collapsed: boolean;
readonly onToggleCollapsed: () => void;
readonly onStopThread?: () => void;
@@ -64,8 +63,6 @@ export interface PendingUserInputCardProps {
*/
const EXPANDED_CARD_IS_OVERLAY = Platform.OS === "ios";
-const CARD_LAYOUT_TRANSITION = LinearTransition.duration(200);
-
function QuestionText(props: { readonly markdown: string }) {
const styles = useMarkdownPreviewStyles();
const openLink = useOpenPullRequest();
@@ -92,18 +89,9 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
if (!cardCoverage) {
return;
}
- const coverage = Math.max(0, cardHeightRef.current - barHeightRef.current);
- if (coverage === cardCoverage.value) {
- return;
- }
- if (cardCoverage.value === 0) {
- cardCoverage.value = coverage;
- return;
- }
- cardCoverage.value = withTiming(coverage, {
- duration: USER_INPUT_TOGGLE_DURATION_MS,
- easing: Easing.out(Easing.cubic),
- });
+ // The card resizes with the keyboard every frame, so easing each sample would leave the
+ // feed inset and floating controls trailing it.
+ cardCoverage.value = Math.max(0, cardHeightRef.current - barHeightRef.current);
}, [cardCoverage]);
const handleBarLayout = useCallback(
(event: LayoutChangeEvent) => {
@@ -121,12 +109,16 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
[cardHeight, notifyCoverage],
);
const cardProgress = props.cardProgress;
+ const maxHeight = props.maxHeight;
const cardAnimatedStyle = useAnimatedStyle(() => {
const progress = cardProgress === undefined ? 1 : cardProgress.value;
return {
+ maxHeight: maxHeight.value,
transform: [{ translateY: (1 - progress) * cardHeight.value }],
};
});
+ const cardMaxHeightStyle = useAnimatedStyle(() => ({ maxHeight: maxHeight.value }));
+ const overlayHeightStyle = useAnimatedStyle(() => ({ height: maxHeight.value }));
// On iOS the card stays MOUNTED while collapsed (hidden via the animated
// style): expanding animates existing views on the UI thread the same
@@ -192,13 +184,8 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
? undefined
: FadeOutDown.duration(USER_INPUT_TOGGLE_DURATION_MS).easing(Easing.out(Easing.cubic))
}
- layout={CARD_LAYOUT_TRANSITION}
className="overflow-hidden gap-2.5 rounded-[20px] border border-border bg-card-alt p-4"
- style={
- EXPANDED_CARD_IS_OVERLAY
- ? [{ maxHeight: props.maxHeight }, cardAnimatedStyle]
- : { maxHeight: props.maxHeight }
- }
+ style={EXPANDED_CARD_IS_OVERLAY ? cardAnimatedStyle : cardMaxHeightStyle}
>
<Pressable
accessibilityRole="button"
@@ -330,13 +317,13 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
<View className="relative">
{bar}
{EXPANDED_CARD_IS_OVERLAY ? (
- <View
+ <Animated.View
pointerEvents={props.collapsed ? "none" : "box-none"}
className="absolute inset-x-0 bottom-0 justify-end overflow-hidden"
- style={{ height: props.maxHeight }}
+ style={overlayHeightStyle}
>
{card}
- </View>
+ </Animated.View>
) : (
card
)}
diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
index 70d7949d035..3a8cb765b6e 100644
--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
@@ -99,6 +99,7 @@ import {
KeyboardController,
KeyboardStickyView,
useKeyboardState,
+ useReanimatedKeyboardAnimation,
} from "react-native-keyboard-controller";
import Animated, {
Easing,
@@ -956,10 +957,8 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
);
const userInputCollapsed =
activeUserInputRequestId !== null && collapsedUserInputRequestId === activeUserInputRequestId;
- // The card's height RESERVES keyboard space at all times instead of tracking the keyboard:
- // transforms (the sticky translation) apply same-frame on the UI thread while layout props lag
- // a Yoga pass behind, so any height that follows the keyboard flashes the card over the nav
- // header on the way up.
+ // A height React sets from keyboard state lags the sticky translation by a Yoga pass and
+ // flashes over the nav header on the way up, so the usage panel reserves the keyboard instead.
const [lastKnownKeyboardHeight, setLastKnownKeyboardHeight] = useState(0);
useEffect(() => {
if (liveKeyboardHeight > 0 && liveKeyboardHeight !== lastKnownKeyboardHeight) {
@@ -968,12 +967,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
}, [lastKnownKeyboardHeight, liveKeyboardHeight]);
const reservedKeyboardHeight =
lastKnownKeyboardHeight > 0 ? lastKnownKeyboardHeight : ESTIMATED_KEYBOARD_HEIGHT;
- const pendingUserInputMaxHeight = derivePendingUserInputMaxHeight({
- windowHeight,
- keyboardHeight: reservedKeyboardHeight,
- navigationHeaderHeight,
- composerOverlapHeight: composerBottomInset,
- });
+ // Waiting for a visibility render misses the first keyboard frames.
+ const keyboardStickyEnabled =
+ Platform.OS === "ios"
+ ? deviceType !== "duo-unfolded" || (composerOwnsKeyboard && !sidebarSearchActive)
+ : !keyboardStateSuspect;
const estimatedOverlayHeight = composerOverlapHeight;
// The overlay's measured height includes the home-indicator inset (the
// composer pads it), but contentInsetAdjustmentBehavior="automatic" makes
@@ -1000,6 +998,18 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
setScreenHeight(event.nativeEvent.layout.height);
}, []);
const screenAreaHeight = screenHeight ?? windowHeight;
+ // The question card reads the keyboard frame on the UI thread, in the same frame the sticky
+ // view translates, so it gets the full height while the keyboard is closed and never crosses
+ // the header while the keyboard moves.
+ const { height: keyboardTranslation } = useReanimatedKeyboardAnimation();
+ const pendingUserInputMaxHeight = useDerivedValue(() =>
+ derivePendingUserInputMaxHeight({
+ windowHeight: screenAreaHeight,
+ keyboardHeight: keyboardStickyEnabled ? -keyboardTranslation.value : 0,
+ navigationHeaderHeight,
+ composerOverlapHeight: composerBottomInset,
+ }),
+ );
// 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.
@@ -1024,9 +1034,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
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.
+ // 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(
@@ -1536,12 +1544,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
{showContent ? (
<KeyboardStickyView
- // Waiting for a visibility render misses the first keyboard frames.
- enabled={
- Platform.OS === "ios"
- ? deviceType !== "duo-unfolded" || (composerOwnsKeyboard && !sidebarSearchActive)
- : !keyboardStateSuspect
- }
+ enabled={keyboardStickyEnabled}
pointerEvents="box-none"
style={{ position: "absolute", bottom: 0, left: 0, right: 0, top: 0 }}
offset={{ closed: 0, opened: composerKeyboardOffset }}
diff --git a/apps/mobile/src/features/threads/pendingUserInputLayout.ts b/apps/mobile/src/features/threads/pendingUserInputLayout.ts
index 312161f46a9..cda395e2da3 100644
--- a/apps/mobile/src/features/threads/pendingUserInputLayout.ts
+++ b/apps/mobile/src/features/threads/pendingUserInputLayout.ts
@@ -16,6 +16,7 @@ export function derivePendingUserInputMaxHeight(input: {
readonly navigationHeaderHeight: number;
readonly composerOverlapHeight: number;
}): number {
+ "worklet";
const availableHeight =
input.windowHeight -
Math.max(0, input.keyboardHeight) -