1- import React , { useMemo , useState } from 'react' ;
1+ import React , { SetStateAction , useMemo , useState } from 'react' ;
22import { StyleSheet , View } from 'react-native' ;
33import { Gesture , GestureDetector } from 'react-native-gesture-handler' ;
44
@@ -16,6 +16,7 @@ import { ReactionListTopProps } from './ReactionList/ReactionListTop';
1616
1717import { MessagesContextValue , useTheme } from '../../../contexts' ;
1818
19+ import { useStableCallback } from '../../../hooks' ;
1920import { NativeHandlers } from '../../../native' ;
2021
2122export type MessageBubbleProps = Pick <
@@ -104,6 +105,14 @@ export const SwipableMessageBubble = React.memo(
104105
105106 const triggerHaptic = NativeHandlers . triggerHaptic ;
106107
108+ const setMessageContentWidth = useStableCallback ( ( valueOrCallback : SetStateAction < number > ) => {
109+ if ( typeof valueOrCallback === 'number' ) {
110+ props . setMessageContentWidth ( Math . round ( valueOrCallback ) ) ;
111+ return ;
112+ }
113+ props . setMessageContentWidth ( valueOrCallback ) ;
114+ } ) ;
115+
107116 const swipeGesture = useMemo (
108117 ( ) =>
109118 Gesture . Pan ( )
@@ -188,7 +197,11 @@ export const SwipableMessageBubble = React.memo(
188197 < GestureDetector gesture = { swipeGesture } >
189198 < View
190199 hitSlop = { messageSwipeToReplyHitSlop }
191- style = { [ styles . contentWrapper , contentWrapper , { width : props . messageContentWidth } ] }
200+ style = { [
201+ styles . contentWrapper ,
202+ contentWrapper ,
203+ props . messageContentWidth > 0 ? { width : props . messageContentWidth } : { } ,
204+ ] }
192205 >
193206 { shouldRenderAnimatedWrapper ? (
194207 < AnimatedWrapper
@@ -201,7 +214,7 @@ export const SwipableMessageBubble = React.memo(
201214 { MessageSwipeContent ? < MessageSwipeContent /> : null }
202215 </ AnimatedWrapper >
203216 ) : null }
204- < MessageBubble { ...messageBubbleProps } />
217+ < MessageBubble { ...messageBubbleProps } setMessageContentWidth = { setMessageContentWidth } />
205218 </ View >
206219 </ GestureDetector >
207220 ) ;
@@ -212,7 +225,7 @@ const styles = StyleSheet.create({
212225 contentWrapper : {
213226 alignItems : 'center' ,
214227 flexDirection : 'row' ,
215- width : 200 ,
228+ // width: 200,
216229 } ,
217230 swipeContentContainer : {
218231 flexShrink : 0 ,
0 commit comments