@@ -10,17 +10,12 @@ import {
1010import { useRef } from "react" ;
1111import { Platform , Pressable , ScrollView , View , type LayoutChangeEvent } from "react-native" ;
1212import Animated , {
13- Easing ,
14- FadeInUp ,
15- FadeOutDown ,
1613 useAnimatedStyle ,
1714 useSharedValue ,
1815 type DerivedValue ,
1916 type SharedValue ,
2017} from "react-native-reanimated" ;
2118
22- import { USER_INPUT_TOGGLE_DURATION_MS } from "./pendingUserInputLayout" ;
23-
2419import { SymbolView } from "../../components/ui/AppSymbol" ;
2520import { AppText as Text } from "../../components/ui/AppText" ;
2621import { ControlPill } from "../../components/ui/ControlPill" ;
@@ -43,8 +38,8 @@ export interface PendingUserInputCardProps {
4338 readonly collapsed : boolean ;
4439 readonly onToggleCollapsed : ( ) => void ;
4540 readonly onStopThread ?: ( ) => void ;
46- readonly cardProgress ? : SharedValue < number > ;
47- readonly cardCoverage ? : SharedValue < number > ;
41+ readonly cardProgress : SharedValue < number > ;
42+ readonly cardCoverage : SharedValue < number > ;
4843 readonly onInputFocusChange ?: ( focused : boolean ) => void ;
4944 readonly drafts : Record < string , PendingUserInputDraftAnswer > ;
5045 readonly answers : Record < string , string | ReadonlyArray < string > > | null ;
@@ -63,9 +58,6 @@ export interface PendingUserInputCardProps {
6358 readonly onDismiss : ( ) => Promise < unknown > ;
6459}
6560
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-
6961function proseDirectionStyle ( text : string , setDirection : TextDirection | undefined ) {
7062 const direction = textDirection ( text ) ;
7163 return {
@@ -111,14 +103,11 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
111103 . join ( " " ) ,
112104 ) ;
113105
114- const cardCoverage = props . cardCoverage ;
106+ const { cardCoverage, cardProgress , maxHeight } = props ;
115107 const barHeightRef = useRef ( 0 ) ;
116108 const cardHeightRef = useRef ( 0 ) ;
117109 const cardHeight = useSharedValue ( 0 ) ;
118110 const notifyCoverage = ( ) => {
119- if ( ! cardCoverage ) {
120- return ;
121- }
122111 // The card resizes with the keyboard every frame, so easing each sample would leave the
123112 // feed inset and floating controls trailing it.
124113 cardCoverage . set ( Math . max ( 0 , cardHeightRef . current - barHeightRef . current ) ) ;
@@ -132,22 +121,25 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
132121 cardHeight . set ( event . nativeEvent . layout . height ) ;
133122 notifyCoverage ( ) ;
134123 } ;
135- const cardProgress = props . cardProgress ;
136- const maxHeight = props . maxHeight ;
137124 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 ;
139127 return {
140128 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 } ] ,
142134 } ;
143135 } ) ;
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+ } ) ) ;
145140 const overlayHeightStyle = useAnimatedStyle ( ( ) => ( { height : maxHeight . value } ) ) ;
146141
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 = (
151143 < View
152144 onLayout = { handleBarLayout }
153145 pointerEvents = { props . collapsed ? "auto" : "none" }
@@ -188,25 +180,15 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
188180 />
189181 ) : null }
190182 </ View >
191- ) : null ;
192- const card = renderCard ? (
183+ ) ;
184+ const card = (
193185 < Animated . View
194186 onLayout = { handleCardLayout }
195187 pointerEvents = { props . collapsed ? "none" : "auto" }
196188 accessibilityElementsHidden = { props . collapsed }
197189 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- }
208190 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 }
210192 >
211193 < Pressable
212194 accessibilityRole = "button"
@@ -345,21 +327,20 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
345327 </ Text >
346328 ) : null }
347329 </ Animated . View >
348- ) : null ;
330+ ) ;
349331 return (
350- < View className = "relative" >
332+ < Animated . View
333+ className = "relative"
334+ style = { Platform . OS === "android" ? androidBoundsStyle : undefined }
335+ >
351336 { 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 >
364345 ) ;
365346}
0 commit comments