Skip to content

Commit ae73857

Browse files
committed
fix: broken message bubble component
1 parent eccab67 commit ae73857

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

package/src/components/Message/MessageSimple/MessageBubble.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo, useState } from 'react';
1+
import React, { SetStateAction, useMemo, useState } from 'react';
22
import { StyleSheet, View } from 'react-native';
33
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
44

@@ -16,6 +16,7 @@ import { ReactionListTopProps } from './ReactionList/ReactionListTop';
1616

1717
import { MessagesContextValue, useTheme } from '../../../contexts';
1818

19+
import { useStableCallback } from '../../../hooks';
1920
import { NativeHandlers } from '../../../native';
2021

2122
export 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

Comments
 (0)