@@ -10,17 +10,12 @@ import { |
10 | 10 | import { useRef } from "react"; |
11 | 11 | import { Platform, Pressable, ScrollView, View, type LayoutChangeEvent } from "react-native"; |
12 | 12 | import Animated, { |
13 | | - Easing, |
14 | | - FadeInUp, |
15 | | - FadeOutDown, |
16 | 13 | useAnimatedStyle, |
17 | 14 | useSharedValue, |
18 | 15 | type DerivedValue, |
19 | 16 | type SharedValue, |
20 | 17 | } from "react-native-reanimated"; |
21 | 18 |
|
22 | | -import { USER_INPUT_TOGGLE_DURATION_MS } from "./pendingUserInputLayout"; |
23 | | - |
24 | 19 | import { SymbolView } from "../../components/ui/AppSymbol"; |
25 | 20 | import { AppText as Text } from "../../components/ui/AppText"; |
26 | 21 | import { ControlPill } from "../../components/ui/ControlPill"; |
@@ -43,8 +38,8 @@ export interface PendingUserInputCardProps { |
43 | 38 | readonly collapsed: boolean; |
44 | 39 | readonly onToggleCollapsed: () => void; |
45 | 40 | readonly onStopThread?: () => void; |
46 | | - readonly cardProgress?: SharedValue<number>; |
47 | | - readonly cardCoverage?: SharedValue<number>; |
| 41 | + readonly cardProgress: SharedValue<number>; |
| 42 | + readonly cardCoverage: SharedValue<number>; |
48 | 43 | readonly onInputFocusChange?: (focused: boolean) => void; |
49 | 44 | readonly drafts: Record<string, PendingUserInputDraftAnswer>; |
50 | 45 | readonly answers: Record<string, string | ReadonlyArray<string>> | null; |
@@ -63,9 +58,6 @@ export interface PendingUserInputCardProps { |
63 | 58 | readonly onDismiss: () => Promise<unknown>; |
64 | 59 | } |
65 | 60 |
|
66 | | -/** Android cannot hit-test overlays beyond their parent's bounds; render its expanded card in-flow. */ |
67 | | -const EXPANDED_CARD_IS_OVERLAY = Platform.OS === "ios"; |
68 | | - |
69 | 61 | function proseDirectionStyle(text: string, setDirection: TextDirection | undefined) { |
70 | 62 | const direction = textDirection(text); |
71 | 63 | return { |
@@ -111,14 +103,11 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) { |
111 | 103 | .join(" "), |
112 | 104 | ); |
113 | 105 |
|
114 | | - const cardCoverage = props.cardCoverage; |
| 106 | + const { cardCoverage, cardProgress, maxHeight } = props; |
115 | 107 | const barHeightRef = useRef(0); |
116 | 108 | const cardHeightRef = useRef(0); |
117 | 109 | const cardHeight = useSharedValue(0); |
118 | 110 | const notifyCoverage = () => { |
119 | | - if (!cardCoverage) { |
120 | | - return; |
121 | | - } |
122 | 111 | // The card resizes with the keyboard every frame, so easing each sample would leave the |
123 | 112 | // feed inset and floating controls trailing it. |
124 | 113 | cardCoverage.set(Math.max(0, cardHeightRef.current - barHeightRef.current)); |
@@ -132,22 +121,25 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) { |
132 | 121 | cardHeight.set(event.nativeEvent.layout.height); |
133 | 122 | notifyCoverage(); |
134 | 123 | }; |
135 | | - const cardProgress = props.cardProgress; |
136 | | - const maxHeight = props.maxHeight; |
137 | 124 | const cardAnimatedStyle = useAnimatedStyle(() => { |
138 | | - const progress = cardProgress === undefined ? 1 : cardProgress.value; |
| 125 | + const progress = cardProgress.value; |
| 126 | + const travel = Platform.OS === "android" ? cardCoverage.value : cardHeight.value; |
139 | 127 | return { |
140 | 128 | maxHeight: maxHeight.value, |
141 | | - transform: [{ translateY: (1 - progress) * cardHeight.value }], |
| 129 | + opacity: |
| 130 | + Platform.OS === "android" |
| 131 | + ? Math.min(1, (progress * cardHeight.value) / Math.max(1, cardHeight.value - travel)) |
| 132 | + : 1, |
| 133 | + transform: [{ translateY: (1 - progress) * travel }], |
142 | 134 | }; |
143 | 135 | }); |
144 | | - const cardMaxHeightStyle = useAnimatedStyle(() => ({ maxHeight: maxHeight.value })); |
| 136 | + // Android hit-tests inside the parent; its height is also the space the card takes below the feed. |
| 137 | + const androidBoundsStyle = useAnimatedStyle(() => ({ |
| 138 | + paddingTop: cardCoverage.value * cardProgress.value, |
| 139 | + })); |
145 | 140 | const overlayHeightStyle = useAnimatedStyle(() => ({ height: maxHeight.value })); |
146 | 141 |
|
147 | | - // Keep the iOS card mounted so expansion starts on the UI thread without waiting for React layout. |
148 | | - const renderCard = EXPANDED_CARD_IS_OVERLAY || !props.collapsed; |
149 | | - const showBar = props.collapsed || EXPANDED_CARD_IS_OVERLAY; |
150 | | - const bar = showBar ? ( |
| 142 | + const bar = ( |
151 | 143 | <View |
152 | 144 | onLayout={handleBarLayout} |
153 | 145 | pointerEvents={props.collapsed ? "auto" : "none"} |
@@ -188,25 +180,15 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) { |
188 | 180 | /> |
189 | 181 | ) : null} |
190 | 182 | </View> |
191 | | - ) : null; |
192 | | - const card = renderCard ? ( |
| 183 | + ); |
| 184 | + const card = ( |
193 | 185 | <Animated.View |
194 | 186 | onLayout={handleCardLayout} |
195 | 187 | pointerEvents={props.collapsed ? "none" : "auto"} |
196 | 188 | accessibilityElementsHidden={props.collapsed} |
197 | 189 | importantForAccessibility={props.collapsed ? "no-hide-descendants" : "auto"} |
198 | | - entering={ |
199 | | - EXPANDED_CARD_IS_OVERLAY |
200 | | - ? undefined |
201 | | - : FadeInUp.duration(USER_INPUT_TOGGLE_DURATION_MS).easing(Easing.out(Easing.cubic)) |
202 | | - } |
203 | | - exiting={ |
204 | | - EXPANDED_CARD_IS_OVERLAY |
205 | | - ? undefined |
206 | | - : FadeOutDown.duration(USER_INPUT_TOGGLE_DURATION_MS).easing(Easing.out(Easing.cubic)) |
207 | | - } |
208 | 190 | className="overflow-hidden gap-2.5 rounded-[20px] border border-border bg-card-alt p-4" |
209 | | - style={EXPANDED_CARD_IS_OVERLAY ? cardAnimatedStyle : cardMaxHeightStyle} |
| 191 | + style={cardAnimatedStyle} |
210 | 192 | > |
211 | 193 | <Pressable |
212 | 194 | accessibilityRole="button" |
@@ -345,21 +327,20 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) { |
345 | 327 | </Text> |
346 | 328 | ) : null} |
347 | 329 | </Animated.View> |
348 | | - ) : null; |
| 330 | + ); |
349 | 331 | return ( |
350 | | - <View className="relative"> |
| 332 | + <Animated.View |
| 333 | + className="relative" |
| 334 | + style={Platform.OS === "android" ? androidBoundsStyle : undefined} |
| 335 | + > |
351 | 336 | {bar} |
352 | | - {EXPANDED_CARD_IS_OVERLAY ? ( |
353 | | - <Animated.View |
354 | | - pointerEvents={props.collapsed ? "none" : "box-none"} |
355 | | - className="absolute inset-x-0 bottom-0 justify-end overflow-hidden" |
356 | | - style={overlayHeightStyle} |
357 | | - > |
358 | | - {card} |
359 | | - </Animated.View> |
360 | | - ) : ( |
361 | | - card |
362 | | - )} |
363 | | - </View> |
| 337 | + <Animated.View |
| 338 | + pointerEvents={props.collapsed ? "none" : "box-none"} |
| 339 | + className="absolute inset-x-0 bottom-0 justify-end overflow-hidden" |
| 340 | + style={overlayHeightStyle} |
| 341 | + > |
| 342 | + {card} |
| 343 | + </Animated.View> |
| 344 | + </Animated.View> |
364 | 345 | ); |
365 | 346 | } |