1- import React , { useCallback , useMemo , useState } from 'react' ;
1+ import React , { useMemo , useState } from 'react' ;
22import { Dimensions , LayoutChangeEvent , StyleSheet , View } from 'react-native' ;
33
44import { Gesture , GestureDetector } from 'react-native-gesture-handler' ;
@@ -24,6 +24,7 @@ import {
2424} from '../../../contexts/messagesContext/MessagesContext' ;
2525import { useTheme } from '../../../contexts/themeContext/ThemeContext' ;
2626
27+ import { useStableCallback } from '../../../hooks/useStableCallback' ;
2728import { NativeHandlers } from '../../../native' ;
2829
2930import { checkMessageEquality , checkQuotedMessageEquality } from '../../../utils/utils' ;
@@ -74,6 +75,7 @@ export type MessageSimplePropsWithContext = Pick<
7475> &
7576 Pick <
7677 MessagesContextValue ,
78+ | 'customMessageSwipeAction'
7779 | 'enableMessageGroupingByUser'
7880 | 'enableSwipeToReply'
7981 | 'myMessageTheme'
@@ -106,6 +108,8 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
106108 const { width } = Dimensions . get ( 'screen' ) ;
107109 const {
108110 alignment,
111+ channel,
112+ customMessageSwipeAction,
109113 enableMessageGroupingByUser,
110114 enableSwipeToReply,
111115 groupStyles,
@@ -215,9 +219,13 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
215219 shouldRenderSwipeableWrapper ,
216220 ) ;
217221
218- const onSwipeToReply = useCallback ( ( ) => {
222+ const onSwipeActionHandler = useStableCallback ( ( ) => {
223+ if ( customMessageSwipeAction ) {
224+ customMessageSwipeAction ( { channel, message } ) ;
225+ return ;
226+ }
219227 setQuotedMessage ( message ) ;
220- } , [ setQuotedMessage , message ] ) ;
228+ } ) ;
221229
222230 const THRESHOLD = 25 ;
223231
@@ -260,7 +268,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
260268 } )
261269 . onEnd ( ( ) => {
262270 if ( translateX . value >= THRESHOLD ) {
263- runOnJS ( onSwipeToReply ) ( ) ;
271+ runOnJS ( onSwipeActionHandler ) ( ) ;
264272 if ( triggerHaptic ) {
265273 runOnJS ( triggerHaptic ) ( 'impactMedium' ) ;
266274 }
@@ -284,7 +292,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
284292 [
285293 isSwiping ,
286294 messageSwipeToReplyHitSlop ,
287- onSwipeToReply ,
295+ onSwipeActionHandler ,
288296 touchStart ,
289297 translateX ,
290298 triggerHaptic ,
@@ -603,6 +611,7 @@ export const MessageSimple = (props: MessageSimpleProps) => {
603611 setQuotedMessage,
604612 } = useMessageContext ( ) ;
605613 const {
614+ customMessageSwipeAction,
606615 enableMessageGroupingByUser,
607616 enableSwipeToReply,
608617 MessageAvatar,
@@ -631,6 +640,7 @@ export const MessageSimple = (props: MessageSimpleProps) => {
631640 { ...{
632641 alignment,
633642 channel,
643+ customMessageSwipeAction,
634644 enableMessageGroupingByUser,
635645 enableSwipeToReply,
636646 groupStyles,
0 commit comments