Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 21 additions & 38 deletions package/src/components/Message/MessageSimple/MessageBubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { StyleSheet, View } from 'react-native';
import { Gesture, GestureDetector } from 'react-native-gesture-handler';

import Animated, {
Extrapolation,
interpolate,
runOnJS,
useAnimatedStyle,
Expand Down Expand Up @@ -138,7 +137,7 @@ export const SwipableMessageBubble = React.memo(
.onStart(() => {
translateX.value = 0;
})
.onChange(({ translationX }) => {
.onUpdate(({ translationX }) => {
if (translationX > 0) {
translateX.value = translationX;
}
Expand Down Expand Up @@ -177,51 +176,32 @@ export const SwipableMessageBubble = React.memo(
],
);

const messageBubbleAnimatedStyle = useAnimatedStyle(
() => ({
transform: [{ translateX: translateX.value }],
}),
[],
);

const swipeContentAnimatedStyle = useAnimatedStyle(
() => ({
opacity: interpolate(translateX.value, [0, SWIPABLE_THRESHOLD], [0, 1]),
transform: [
{
translateX: interpolate(
translateX.value,
[0, SWIPABLE_THRESHOLD],
[-SWIPABLE_THRESHOLD, 0],
Extrapolation.CLAMP,
),
},
],
width: translateX.value,
}),
[],
);

return (
<GestureDetector gesture={swipeGesture}>
<View hitSlop={messageSwipeToReplyHitSlop} style={[styles.contentWrapper, contentWrapper]}>
<View
hitSlop={messageSwipeToReplyHitSlop}
style={[styles.contentWrapper, contentWrapper, { width: props.messageContentWidth }]}
>
{shouldRenderAnimatedWrapper ? (
<>
<AnimatedWrapper
style={[
styles.swipeContentContainer,
swipeContentAnimatedStyle,
swipeContentContainer,
]}
>
{MessageSwipeContent ? <MessageSwipeContent /> : null}
</AnimatedWrapper>
<AnimatedWrapper pointerEvents='box-none' style={messageBubbleAnimatedStyle}>
<MessageBubble {...messageBubbleProps} />
</AnimatedWrapper>
</>
) : (
<MessageBubble {...messageBubbleProps} />
)}
<AnimatedWrapper
style={[
styles.swipeContentContainer,
swipeContentAnimatedStyle,
swipeContentContainer,
]}
>
{MessageSwipeContent ? <MessageSwipeContent /> : null}
</AnimatedWrapper>
) : null}
<MessageBubble {...messageBubbleProps} />
</View>
</GestureDetector>
);
Expand All @@ -232,8 +212,11 @@ const styles = StyleSheet.create({
contentWrapper: {
alignItems: 'center',
flexDirection: 'row',
width: 200,
},
swipeContentContainer: {
position: 'absolute',
flexShrink: 0,
overflow: 'hidden',
position: 'relative',
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,12 @@ exports[`Thread should match thread snapshot 1`] = `
{
"alignItems": "center",
"flexDirection": "row",
"width": 200,
},
{},
{
"width": 0,
},
]
}
>
Expand All @@ -389,6 +393,7 @@ exports[`Thread should match thread snapshot 1`] = `
{
"alignItems": "center",
"flexDirection": "row",
"width": 200,
},
{},
]
Expand Down Expand Up @@ -747,8 +752,12 @@ exports[`Thread should match thread snapshot 1`] = `
{
"alignItems": "center",
"flexDirection": "row",
"width": 200,
},
{},
{
"width": 0,
},
]
}
>
Expand All @@ -758,6 +767,7 @@ exports[`Thread should match thread snapshot 1`] = `
{
"alignItems": "center",
"flexDirection": "row",
"width": 200,
},
{},
]
Expand Down Expand Up @@ -1154,8 +1164,12 @@ exports[`Thread should match thread snapshot 1`] = `
{
"alignItems": "center",
"flexDirection": "row",
"width": 200,
},
{},
{
"width": 0,
},
]
}
>
Expand All @@ -1165,6 +1179,7 @@ exports[`Thread should match thread snapshot 1`] = `
{
"alignItems": "center",
"flexDirection": "row",
"width": 200,
},
{},
]
Expand Down Expand Up @@ -1527,8 +1542,12 @@ exports[`Thread should match thread snapshot 1`] = `
{
"alignItems": "center",
"flexDirection": "row",
"width": 200,
},
{},
{
"width": 0,
},
]
}
>
Expand All @@ -1538,6 +1557,7 @@ exports[`Thread should match thread snapshot 1`] = `
{
"alignItems": "center",
"flexDirection": "row",
"width": 200,
},
{},
]
Expand Down
Loading