Skip to content

Commit 68bda2f

Browse files
committed
feat: remove legacy image gallery viewer prop
1 parent f8c9b9a commit 68bda2f

File tree

6 files changed

+2
-171
lines changed

6 files changed

+2
-171
lines changed

package/src/components/Attachment/Gallery.tsx

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ export type GalleryPropsWithContext = Pick<
5151
| 'onPressIn'
5252
| 'preventPress'
5353
| 'threadList'
54+
| 'message'
5455
> &
5556
Pick<
5657
MessagesContextValue,
5758
| 'additionalPressableProps'
58-
| 'legacyImageViewerSwipeBehaviour'
5959
| 'VideoThumbnail'
6060
| 'ImageLoadingIndicator'
6161
| 'ImageLoadingFailedIndicator'
@@ -65,19 +65,6 @@ export type GalleryPropsWithContext = Pick<
6565
Pick<OverlayContextValue, 'setOverlay'> & {
6666
channelId: string | undefined;
6767
hasThreadReplies?: boolean;
68-
/**
69-
* `message` prop has been introduced here as part of `legacyImageViewerSwipeBehaviour` prop.
70-
* https://github.com/GetStream/stream-chat-react-native/commit/d5eac6193047916f140efe8e396a671675c9a63f
71-
* messageId and messageText may seem redundant now, but to avoid breaking change as part
72-
* of minor release, we are keeping those props.
73-
*
74-
* Also `message` type should ideally be imported from MessageContextValue and not be explicitely mentioned
75-
* here, but due to some circular dependencies within the SDK, it causes "excessive deep nesting" issue with
76-
* typescript within Channel component. We should take it as a mini-project and resolve all these circular imports.
77-
*
78-
* TODO: Fix circular dependencies of imports
79-
*/
80-
message?: LocalMessage;
8168
};
8269

8370
const GalleryWithContext = (props: GalleryPropsWithContext) => {
@@ -90,7 +77,6 @@ const GalleryWithContext = (props: GalleryPropsWithContext) => {
9077
ImageLoadingIndicator,
9178
ImageReloadIndicator,
9279
images,
93-
legacyImageViewerSwipeBehaviour,
9480
message,
9581
onLongPress,
9682
onPress,
@@ -210,7 +196,6 @@ const GalleryWithContext = (props: GalleryPropsWithContext) => {
210196
imagesAndVideos={imagesAndVideos}
211197
invertedDirections={invertedDirections || false}
212198
key={rowIndex}
213-
legacyImageViewerSwipeBehaviour={legacyImageViewerSwipeBehaviour}
214199
message={message}
215200
numOfColumns={numOfColumns}
216201
numOfRows={numOfRows}
@@ -252,7 +237,6 @@ type GalleryThumbnailProps = {
252237
} & Pick<
253238
MessagesContextValue,
254239
| 'additionalPressableProps'
255-
| 'legacyImageViewerSwipeBehaviour'
256240
| 'VideoThumbnail'
257241
| 'ImageLoadingIndicator'
258242
| 'ImageLoadingFailedIndicator'
@@ -271,7 +255,6 @@ const GalleryThumbnail = ({
271255
ImageReloadIndicator,
272256
imagesAndVideos,
273257
invertedDirections,
274-
legacyImageViewerSwipeBehaviour,
275258
message,
276259
numOfColumns,
277260
numOfRows,
@@ -304,16 +287,10 @@ const GalleryThumbnail = ({
304287
const { t } = useTranslationContext();
305288

306289
const openImageViewer = () => {
307-
if (!legacyImageViewerSwipeBehaviour && message) {
308-
// Added if-else to keep the logic readable, instead of DRY.
309-
// if - legacyImageViewerSwipeBehaviour is disabled
310-
// else - legacyImageViewerSwipeBehaviour is enabled
290+
if (message) {
311291
setMessages([message]);
312292
setSelectedMessage({ messageId: message.id, url: thumbnail.url });
313293
setOverlay('gallery');
314-
} else if (legacyImageViewerSwipeBehaviour) {
315-
setSelectedMessage({ messageId: message?.id, url: thumbnail.url });
316-
setOverlay('gallery');
317294
}
318295
};
319296

@@ -609,7 +586,6 @@ export const Gallery = (props: GalleryProps) => {
609586
ImageLoadingFailedIndicator: ContextImageLoadingFailedIndicator,
610587
ImageLoadingIndicator: ContextImageLoadingIndicator,
611588
ImageReloadIndicator: ContextImageReloadIndicator,
612-
legacyImageViewerSwipeBehaviour,
613589
myMessageTheme: contextMyMessageTheme,
614590
VideoThumbnail: ContextVideoThumnbnail,
615591
} = useMessagesContext();
@@ -653,7 +629,6 @@ export const Gallery = (props: GalleryProps) => {
653629
ImageLoadingIndicator,
654630
ImageReloadIndicator,
655631
images,
656-
legacyImageViewerSwipeBehaviour,
657632
message,
658633
myMessageTheme,
659634
onLongPress,

package/src/components/Channel/Channel.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
343343
| 'InlineDateSeparator'
344344
| 'InlineUnreadIndicator'
345345
| 'isAttachmentEqual'
346-
| 'legacyImageViewerSwipeBehaviour'
347346
| 'ImageLoadingFailedIndicator'
348347
| 'ImageLoadingIndicator'
349348
| 'ImageReloadIndicator'
@@ -661,7 +660,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
661660
keyboardBehavior,
662661
KeyboardCompatibleView = KeyboardCompatibleViewDefault,
663662
keyboardVerticalOffset,
664-
legacyImageViewerSwipeBehaviour = false,
665663
LoadingErrorIndicator = LoadingErrorIndicatorDefault,
666664
LoadingIndicator = LoadingIndicatorDefault,
667665
loadingMore: loadingMoreProp,
@@ -1942,7 +1940,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
19421940
InlineUnreadIndicator,
19431941
isAttachmentEqual,
19441942
isMessageAIGenerated,
1945-
legacyImageViewerSwipeBehaviour,
19461943
markdownRules,
19471944
Message,
19481945
MessageActionList,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export const useCreateMessagesContext = ({
5252
InlineUnreadIndicator,
5353
isAttachmentEqual,
5454
isMessageAIGenerated,
55-
legacyImageViewerSwipeBehaviour,
5655
markdownRules,
5756
Message,
5857
MessageActionList,
@@ -170,7 +169,6 @@ export const useCreateMessagesContext = ({
170169
InlineUnreadIndicator,
171170
isAttachmentEqual,
172171
isMessageAIGenerated,
173-
legacyImageViewerSwipeBehaviour,
174172
markdownRules,
175173
Message,
176174
MessageActionList,

package/src/components/MessageList/MessageFlashList.tsx

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ import {
2828
useChannelContext,
2929
} from '../../contexts/channelContext/ChannelContext';
3030
import { ChatContextValue, useChatContext } from '../../contexts/chatContext/ChatContext';
31-
import {
32-
ImageGalleryContextValue,
33-
useImageGalleryContext,
34-
} from '../../contexts/imageGalleryContext/ImageGalleryContext';
3531
import {
3632
MessagesContextValue,
3733
useMessagesContext,
@@ -48,7 +44,6 @@ import { mergeThemes, ThemeProvider, useTheme } from '../../contexts/themeContex
4844
import { ThreadContextValue, useThreadContext } from '../../contexts/threadContext/ThreadContext';
4945

5046
import { useStableCallback } from '../../hooks';
51-
import { FileTypes } from '../../types/types';
5247

5348
let FlashList;
5449

@@ -121,7 +116,6 @@ type MessageFlashListPropsWithContext = Pick<
121116
| 'maximumMessageLimit'
122117
> &
123118
Pick<ChatContextValue, 'client'> &
124-
Pick<ImageGalleryContextValue, 'setMessages'> &
125119
Pick<PaginatedMessageListContextValue, 'loadMore' | 'loadMoreRecent'> &
126120
Pick<
127121
MessagesContextValue,
@@ -130,7 +124,6 @@ type MessageFlashListPropsWithContext = Pick<
130124
| 'FlatList'
131125
| 'InlineDateSeparator'
132126
| 'InlineUnreadIndicator'
133-
| 'legacyImageViewerSwipeBehaviour'
134127
| 'Message'
135128
| 'ScrollToBottomButton'
136129
| 'MessageSystem'
@@ -179,7 +172,6 @@ type MessageFlashListPropsWithContext = Pick<
179172
HeaderComponent?: React.ComponentType;
180173
/** Whether or not the FlatList is inverted. Defaults to true */
181174
inverted?: boolean;
182-
isListActive?: boolean;
183175
/** Turn off grouping of messages by user */
184176
noGroupByUser?: boolean;
185177
onListScroll?: ScrollViewProps['onScroll'];
@@ -271,9 +263,7 @@ const MessageFlashListWithContext = (props: MessageFlashListPropsWithContext) =>
271263
highlightedMessageId,
272264
InlineDateSeparator,
273265
InlineUnreadIndicator,
274-
isListActive = false,
275266
isLiveStreaming = false,
276-
legacyImageViewerSwipeBehaviour,
277267
loadChannelAroundMessage,
278268
loading,
279269
LoadingIndicator,
@@ -296,7 +286,6 @@ const MessageFlashListWithContext = (props: MessageFlashListPropsWithContext) =>
296286
selectedPicker,
297287
setChannelUnreadState,
298288
setFlatListRef,
299-
setMessages,
300289
setSelectedPicker,
301290
setTargetedMessage,
302291
shouldShowUnreadUnderlay,
@@ -802,59 +791,6 @@ const MessageFlashListWithContext = (props: MessageFlashListPropsWithContext) =>
802791
],
803792
);
804793

805-
const messagesWithImages =
806-
legacyImageViewerSwipeBehaviour &&
807-
processedMessageList.filter((message) => {
808-
const isMessageTypeDeleted = message.type === 'deleted';
809-
if (!isMessageTypeDeleted && message.attachments) {
810-
return message.attachments.some(
811-
(attachment) =>
812-
attachment.type === FileTypes.Image &&
813-
!attachment.title_link &&
814-
!attachment.og_scrape_url &&
815-
(attachment.image_url || attachment.thumb_url),
816-
);
817-
}
818-
return false;
819-
});
820-
821-
/**
822-
* This is for the useEffect to run again in the case that a message
823-
* gets edited with more or the same number of images
824-
*/
825-
const imageString =
826-
legacyImageViewerSwipeBehaviour &&
827-
messagesWithImages &&
828-
messagesWithImages
829-
.map((message) =>
830-
message.attachments
831-
?.map((attachment) => attachment.image_url || attachment.thumb_url || '')
832-
.join(),
833-
)
834-
.join();
835-
836-
const numberOfMessagesWithImages =
837-
legacyImageViewerSwipeBehaviour && messagesWithImages && messagesWithImages.length;
838-
const threadExists = !!thread;
839-
840-
useEffect(() => {
841-
if (
842-
legacyImageViewerSwipeBehaviour &&
843-
isListActive &&
844-
((threadList && thread) || (!threadList && !thread))
845-
) {
846-
setMessages(messagesWithImages as LocalMessage[]);
847-
}
848-
// eslint-disable-next-line react-hooks/exhaustive-deps
849-
}, [
850-
imageString,
851-
isListActive,
852-
legacyImageViewerSwipeBehaviour,
853-
numberOfMessagesWithImages,
854-
threadExists,
855-
threadList,
856-
]);
857-
858794
/**
859795
* We are keeping full control on message pagination, and not relying on react-native for it.
860796
* The reasons being,
@@ -1216,14 +1152,12 @@ export const MessageFlashList = (props: MessageFlashListProps) => {
12161152
threadList,
12171153
} = useChannelContext();
12181154
const { client } = useChatContext();
1219-
const { setMessages } = useImageGalleryContext();
12201155
const {
12211156
DateHeader,
12221157
disableTypingIndicator,
12231158
FlatList,
12241159
InlineDateSeparator,
12251160
InlineUnreadIndicator,
1226-
legacyImageViewerSwipeBehaviour,
12271161
Message,
12281162
MessageSystem,
12291163
myMessageTheme,
@@ -1256,7 +1190,6 @@ export const MessageFlashList = (props: MessageFlashListProps) => {
12561190
InlineDateSeparator,
12571191
InlineUnreadIndicator,
12581192
isListActive: isChannelActive,
1259-
legacyImageViewerSwipeBehaviour,
12601193
loadChannelAroundMessage,
12611194
loading,
12621195
LoadingIndicator,
@@ -1276,7 +1209,6 @@ export const MessageFlashList = (props: MessageFlashListProps) => {
12761209
scrollToFirstUnreadThreshold,
12771210
selectedPicker,
12781211
setChannelUnreadState,
1279-
setMessages,
12801212
setSelectedPicker,
12811213
setTargetedMessage,
12821214
shouldShowUnreadUnderlay,

0 commit comments

Comments
 (0)