Skip to content

Commit c231df4

Browse files
committed
feat: add custom swipe action handler
1 parent bb61233 commit c231df4

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
304304
| 'CardCover'
305305
| 'CardFooter'
306306
| 'CardHeader'
307+
| 'customMessageSwipeAction'
307308
| 'DateHeader'
308309
| 'deletedMessagesVisibilityType'
309310
| 'disableTypingIndicator'
@@ -550,6 +551,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
550551
compressImageQuality,
551552
CooldownTimer = CooldownTimerDefault,
552553
CreatePollContent,
554+
customMessageSwipeAction,
553555
DateHeader = DateHeaderDefault,
554556
deletedMessagesVisibilityType = 'always',
555557
disableKeyboardCompatibleView = false,
@@ -1814,6 +1816,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
18141816
CardFooter,
18151817
CardHeader,
18161818
channelId,
1819+
customMessageSwipeAction,
18171820
DateHeader,
18181821
deletedMessagesVisibilityType,
18191822
deleteMessage,

package/src/components/Channel/hooks/useCreateMessagesContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const useCreateMessagesContext = ({
1212
CardFooter,
1313
CardHeader,
1414
channelId,
15+
customMessageSwipeAction,
1516
DateHeader,
1617
deletedMessagesVisibilityType,
1718
deleteMessage,
@@ -128,6 +129,7 @@ export const useCreateMessagesContext = ({
128129
CardCover,
129130
CardFooter,
130131
CardHeader,
132+
customMessageSwipeAction,
131133
DateHeader,
132134
deletedMessagesVisibilityType,
133135
deleteMessage,

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export type MessageSimplePropsWithContext = Pick<
7474
> &
7575
Pick<
7676
MessagesContextValue,
77+
| 'customMessageSwipeAction'
7778
| 'enableMessageGroupingByUser'
7879
| 'enableSwipeToReply'
7980
| 'myMessageTheme'
@@ -106,6 +107,8 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
106107
const { width } = Dimensions.get('screen');
107108
const {
108109
alignment,
110+
channel,
111+
customMessageSwipeAction,
109112
enableMessageGroupingByUser,
110113
enableSwipeToReply,
111114
groupStyles,
@@ -215,9 +218,13 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
215218
shouldRenderSwipeableWrapper,
216219
);
217220

218-
const onSwipeToReply = useCallback(() => {
221+
const onSwipeActionHandler = useCallback(() => {
222+
if (customMessageSwipeAction) {
223+
customMessageSwipeAction({ channel, message });
224+
return;
225+
}
219226
setQuotedMessage(message);
220-
}, [setQuotedMessage, message]);
227+
}, [channel, customMessageSwipeAction, message, setQuotedMessage]);
221228

222229
const THRESHOLD = 25;
223230

@@ -260,7 +267,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
260267
})
261268
.onEnd(() => {
262269
if (translateX.value >= THRESHOLD) {
263-
runOnJS(onSwipeToReply)();
270+
runOnJS(onSwipeActionHandler)();
264271
if (triggerHaptic) {
265272
runOnJS(triggerHaptic)('impactMedium');
266273
}
@@ -284,7 +291,7 @@ const MessageSimpleWithContext = (props: MessageSimplePropsWithContext) => {
284291
[
285292
isSwiping,
286293
messageSwipeToReplyHitSlop,
287-
onSwipeToReply,
294+
onSwipeActionHandler,
288295
touchStart,
289296
translateX,
290297
triggerHaptic,
@@ -603,6 +610,7 @@ export const MessageSimple = (props: MessageSimpleProps) => {
603610
setQuotedMessage,
604611
} = useMessageContext();
605612
const {
613+
customMessageSwipeAction,
606614
enableMessageGroupingByUser,
607615
enableSwipeToReply,
608616
MessageAvatar,
@@ -631,6 +639,7 @@ export const MessageSimple = (props: MessageSimpleProps) => {
631639
{...{
632640
alignment,
633641
channel,
642+
customMessageSwipeAction,
634643
enableMessageGroupingByUser,
635644
enableSwipeToReply,
636645
groupStyles,

package/src/contexts/messagesContext/MessagesContext.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PressableProps, ViewProps } from 'react-native';
44

55
import type {
66
Attachment,
7+
Channel,
78
ChannelState,
89
CommandSuggestion,
910
LocalMessage,
@@ -362,6 +363,14 @@ export type MessagesContextValue = Pick<MessageContextValue, 'isMessageAIGenerat
362363
*/
363364
CardHeader?: React.ComponentType<CardProps>;
364365

366+
customMessageSwipeAction?: ({
367+
channel,
368+
message,
369+
}: {
370+
channel: Channel;
371+
message: LocalMessage;
372+
}) => void;
373+
365374
/**
366375
* Full override of the delete message button in the Message Actions
367376
*

0 commit comments

Comments
 (0)