@@ -90,7 +90,16 @@ export type MessageSimplePropsWithContext = Pick<
9090 | 'reactionListPosition'
9191 | 'ReactionListTop'
9292 | 'setQuotedMessageState'
93- > & { shouldRenderSwipeableWrapper : boolean } ;
93+ > & {
94+ /**
95+ * Will determine whether the swipeable wrapper is always rendered for each
96+ * message. If set to false, the animated wrapper will be rendered only when
97+ * a swiping gesture is active and not otherwise.
98+ * Since stateful components would lose their state if we remount them while
99+ * an animation is happening, this should always be set to true in those instances.
100+ */
101+ shouldRenderSwipeableWrapper : boolean ;
102+ } ;
94103
95104const MessageSimpleWithContext = ( props : MessageSimplePropsWithContext ) => {
96105 const [ messageContentWidth , setMessageContentWidth ] = useState ( 0 ) ;
@@ -203,7 +212,9 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
203212 const translateX = useSharedValue ( 0 ) ;
204213 const touchStart = useSharedValue < { x : number ; y : number } | null > ( null ) ;
205214 const isSwiping = useSharedValue < boolean > ( false ) ;
206- const [ isBeingSwiped , setIsBeingSwiped ] = useState < boolean > ( shouldRenderSwipeableWrapper ) ;
215+ const [ shouldRenderAnimatedWrapper , setShouldRenderAnimatedWrapper ] = useState < boolean > (
216+ shouldRenderSwipeableWrapper ,
217+ ) ;
207218
208219 const onSwipeToReply = useCallback ( ( ) => {
209220 clearQuotedMessageState ( ) ;
@@ -235,7 +246,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
235246 state . activate ( ) ;
236247 isSwiping . value = true ;
237248 if ( ! shouldRenderSwipeableWrapper ) {
238- runOnJS ( setIsBeingSwiped ) ( isSwiping . value ) ;
249+ runOnJS ( setShouldRenderAnimatedWrapper ) ( isSwiping . value ) ;
239250 }
240251 } else {
241252 state . fail ( ) ;
@@ -267,7 +278,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
267278 } ,
268279 ( ) => {
269280 if ( ! shouldRenderSwipeableWrapper ) {
270- runOnJS ( setIsBeingSwiped ) ( isSwiping . value ) ;
281+ runOnJS ( setShouldRenderAnimatedWrapper ) ( isSwiping . value ) ;
271282 }
272283 } ,
273284 ) ;
@@ -339,7 +350,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
339350 ( ) => (
340351 < GestureDetector gesture = { swipeGesture } >
341352 < View hitSlop = { messageSwipeToReplyHitSlop } style = { [ styles . contentWrapper , contentWrapper ] } >
342- { isBeingSwiped ? (
353+ { shouldRenderAnimatedWrapper ? (
343354 < >
344355 < AnimatedWrapper
345356 style = { [
@@ -363,7 +374,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
363374 [
364375 MessageSwipeContent ,
365376 contentWrapper ,
366- isBeingSwiped ,
377+ shouldRenderAnimatedWrapper ,
367378 messageBubbleAnimatedStyle ,
368379 messageSwipeToReplyHitSlop ,
369380 renderMessageBubble ,
0 commit comments