Skip to content

Commit 8dbded3

Browse files
committed
chore: add override for ImageReloadIndicator
1 parent 1cc008c commit 8dbded3

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

package/src/components/Attachment/Gallery.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Pressable, StyleSheet, Text, View } from 'react-native';
44
import type { Attachment } from 'stream-chat';
55

66
import { GalleryImage } from './GalleryImage';
7-
import { ImageReloadIndicator } from './ImageReloadIndicator';
87
import { buildGallery } from './utils/buildGallery/buildGallery';
98

109
import type { Thumbnail } from './utils/buildGallery/types';
@@ -58,6 +57,7 @@ export type GalleryPropsWithContext<
5857
| 'VideoThumbnail'
5958
| 'ImageLoadingIndicator'
6059
| 'ImageLoadingFailedIndicator'
60+
| 'ImageReloadIndicator'
6161
| 'myMessageTheme'
6262
> &
6363
Pick<OverlayContextValue, 'setOverlay'> & {
@@ -90,6 +90,7 @@ const GalleryWithContext = <
9090
hasThreadReplies,
9191
ImageLoadingFailedIndicator,
9292
ImageLoadingIndicator,
93+
ImageReloadIndicator,
9394
images,
9495
legacyImageViewerSwipeBehaviour,
9596
message,
@@ -207,6 +208,7 @@ const GalleryWithContext = <
207208
colIndex={colIndex}
208209
ImageLoadingFailedIndicator={ImageLoadingFailedIndicator}
209210
ImageLoadingIndicator={ImageLoadingIndicator}
211+
ImageReloadIndicator={ImageReloadIndicator}
210212
imagesAndVideos={imagesAndVideos}
211213
invertedDirections={invertedDirections || false}
212214
key={rowIndex}
@@ -258,6 +260,7 @@ type GalleryThumbnailProps<
258260
| 'VideoThumbnail'
259261
| 'ImageLoadingIndicator'
260262
| 'ImageLoadingFailedIndicator'
263+
| 'ImageReloadIndicator'
261264
> &
262265
Pick<ImageGalleryContextValue<StreamChatGenerics>, 'setSelectedMessage' | 'setMessages'> &
263266
Pick<
@@ -274,6 +277,7 @@ const GalleryThumbnail = <
274277
colIndex,
275278
ImageLoadingFailedIndicator,
276279
ImageLoadingIndicator,
280+
ImageReloadIndicator,
277281
imagesAndVideos,
278282
invertedDirections,
279283
legacyImageViewerSwipeBehaviour,
@@ -397,6 +401,7 @@ const GalleryThumbnail = <
397401
borderRadius={imageBorderRadius ?? borderRadius}
398402
ImageLoadingFailedIndicator={ImageLoadingFailedIndicator}
399403
ImageLoadingIndicator={ImageLoadingIndicator}
404+
ImageReloadIndicator={ImageReloadIndicator}
400405
thumbnail={thumbnail}
401406
/>
402407
</View>
@@ -425,10 +430,15 @@ const GalleryImageThumbnail = <
425430
borderRadius,
426431
ImageLoadingFailedIndicator,
427432
ImageLoadingIndicator,
433+
ImageReloadIndicator,
428434
thumbnail,
429435
}: Pick<
430436
GalleryThumbnailProps<StreamChatGenerics>,
431-
'ImageLoadingFailedIndicator' | 'ImageLoadingIndicator' | 'thumbnail' | 'borderRadius'
437+
| 'ImageLoadingFailedIndicator'
438+
| 'ImageLoadingIndicator'
439+
| 'ImageReloadIndicator'
440+
| 'thumbnail'
441+
| 'borderRadius'
432442
>) => {
433443
const {
434444
isLoadingImage,
@@ -585,6 +595,7 @@ export const Gallery = <
585595
hasThreadReplies,
586596
ImageLoadingFailedIndicator: PropImageLoadingFailedIndicator,
587597
ImageLoadingIndicator: PropImageLoadingIndicator,
598+
ImageReloadIndicator: PropImageReloadIndicator,
588599
images: propImages,
589600
message: propMessage,
590601
myMessageTheme: propMyMessageTheme,
@@ -617,6 +628,7 @@ export const Gallery = <
617628
additionalPressableProps: contextAdditionalPressableProps,
618629
ImageLoadingFailedIndicator: ContextImageLoadingFailedIndicator,
619630
ImageLoadingIndicator: ContextImageLoadingIndicator,
631+
ImageReloadIndicator: ContextImageReloadIndicator,
620632
legacyImageViewerSwipeBehaviour,
621633
myMessageTheme: contextMyMessageTheme,
622634
VideoThumbnail: ContextVideoThumnbnail,
@@ -646,6 +658,7 @@ export const Gallery = <
646658
const ImageLoadingFailedIndicator =
647659
PropImageLoadingFailedIndicator || ContextImageLoadingFailedIndicator;
648660
const ImageLoadingIndicator = PropImageLoadingIndicator || ContextImageLoadingIndicator;
661+
const ImageReloadIndicator = PropImageReloadIndicator || ContextImageReloadIndicator;
649662
const myMessageTheme = propMyMessageTheme || contextMyMessageTheme;
650663

651664
return (
@@ -658,6 +671,7 @@ export const Gallery = <
658671
hasThreadReplies: hasThreadReplies || !!message?.reply_count,
659672
ImageLoadingFailedIndicator,
660673
ImageLoadingIndicator,
674+
ImageReloadIndicator,
661675
images,
662676
legacyImageViewerSwipeBehaviour,
663677
message,

package/src/components/Attachment/ImageReloadIndicator.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ import { Refresh } from '../../icons';
66

77
const REFRESH_ICON_SIZE = 24;
88

9-
export const ImageReloadIndicator = ({
10-
onReloadImage,
11-
style,
12-
}: {
9+
export type ImageReloadIndicatorProps = {
1310
onReloadImage: () => void;
1411
style: React.ComponentProps<typeof Pressable>['style'];
15-
}) => {
12+
};
13+
14+
export const ImageReloadIndicator = ({ onReloadImage, style }: ImageReloadIndicatorProps) => {
1615
const {
1716
theme: {
1817
colors: { grey_dark },

package/src/components/Channel/Channel.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ import { Gallery as GalleryDefault } from '../Attachment/Gallery';
118118
import { Giphy as GiphyDefault } from '../Attachment/Giphy';
119119
import { ImageLoadingFailedIndicator as ImageLoadingFailedIndicatorDefault } from '../Attachment/ImageLoadingFailedIndicator';
120120
import { ImageLoadingIndicator as ImageLoadingIndicatorDefault } from '../Attachment/ImageLoadingIndicator';
121+
import { ImageReloadIndicator as ImageReloadIndicatorDefault } from '../Attachment/ImageReloadIndicator';
121122
import { VideoThumbnail as VideoThumbnailDefault } from '../Attachment/VideoThumbnail';
122123
import { AutoCompleteSuggestionHeader as AutoCompleteSuggestionHeaderDefault } from '../AutoCompleteInput/AutoCompleteSuggestionHeader';
123124
import { AutoCompleteSuggestionItem as AutoCompleteSuggestionItemDefault } from '../AutoCompleteInput/AutoCompleteSuggestionItem';
@@ -325,6 +326,7 @@ export type ChannelPropsWithContext<
325326
| 'legacyImageViewerSwipeBehaviour'
326327
| 'ImageLoadingFailedIndicator'
327328
| 'ImageLoadingIndicator'
329+
| 'ImageReloadIndicator'
328330
| 'markdownRules'
329331
| 'Message'
330332
| 'MessageActionList'
@@ -569,6 +571,7 @@ const ChannelWithContext = <
569571
hideStickyDateHeader = false,
570572
ImageLoadingFailedIndicator = ImageLoadingFailedIndicatorDefault,
571573
ImageLoadingIndicator = ImageLoadingIndicatorDefault,
574+
ImageReloadIndicator = ImageReloadIndicatorDefault,
572575
ImageUploadPreview = ImageUploadPreviewDefault,
573576
initialScrollToFirstUnreadMessage = false,
574577
initialValue,
@@ -1917,6 +1920,7 @@ const ChannelWithContext = <
19171920
hasCreatePoll === undefined ? pollCreationEnabled : hasCreatePoll && pollCreationEnabled,
19181921
ImageLoadingFailedIndicator,
19191922
ImageLoadingIndicator,
1923+
ImageReloadIndicator,
19201924
initialScrollToFirstUnreadMessage: !messageId && initialScrollToFirstUnreadMessage, // when messageId is set, we scroll to the messageId instead of first unread
19211925
InlineDateSeparator,
19221926
InlineUnreadIndicator,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const useCreateMessagesContext = <
4848
hasCreatePoll,
4949
ImageLoadingFailedIndicator,
5050
ImageLoadingIndicator,
51+
ImageReloadIndicator,
5152
initialScrollToFirstUnreadMessage,
5253
InlineDateSeparator,
5354
InlineUnreadIndicator,
@@ -165,6 +166,7 @@ export const useCreateMessagesContext = <
165166
hasCreatePoll,
166167
ImageLoadingFailedIndicator,
167168
ImageLoadingIndicator,
169+
ImageReloadIndicator,
168170
initialScrollToFirstUnreadMessage,
169171
InlineDateSeparator,
170172
InlineUnreadIndicator,

package/src/contexts/messagesContext/MessagesContext.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { GalleryProps } from '../../components/Attachment/Gallery';
1616
import type { GiphyProps } from '../../components/Attachment/Giphy';
1717
import type { ImageLoadingFailedIndicatorProps } from '../../components/Attachment/ImageLoadingFailedIndicator';
1818
import type { ImageLoadingIndicatorProps } from '../../components/Attachment/ImageLoadingIndicator';
19+
import { ImageReloadIndicatorProps } from '../../components/Attachment/ImageReloadIndicator';
1920
import type { VideoThumbnailProps } from '../../components/Attachment/VideoThumbnail';
2021
import type {
2122
MessagePressableHandlerPayload,
@@ -153,6 +154,11 @@ export type MessagesContextValue<
153154
*/
154155
ImageLoadingFailedIndicator: React.ComponentType<ImageLoadingFailedIndicatorProps>;
155156

157+
/**
158+
* The indicator rendered at the center of an image whenever its loading fails, used to trigger retries.
159+
*/
160+
ImageReloadIndicator: React.ComponentType<ImageReloadIndicatorProps>;
161+
156162
/**
157163
* The indicator rendered when image is loading. By default renders <ActivityIndicator/>
158164
*/

0 commit comments

Comments
 (0)