Skip to content

Commit 76ca4b1

Browse files
authored
fix: image gallery extra customizations (#3071)
* chore: add override for ImageReloadIndicator * fix: export missing entities * fix: add translation for more images in gallery * fix: add missing translation * fix: add other missing translation
1 parent 9705d90 commit 76ca4b1

File tree

19 files changed

+67
-8
lines changed

19 files changed

+67
-8
lines changed

package/src/components/Attachment/Gallery.tsx

Lines changed: 19 additions & 3 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';
@@ -13,6 +12,7 @@ import { getGalleryImageBorderRadius } from './utils/getGalleryImageBorderRadius
1312
import { openUrlSafely } from './utils/openUrlSafely';
1413

1514
import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
15+
import { useTranslationContext } from '../../contexts';
1616
import { useChatConfigContext } from '../../contexts/chatConfigContext/ChatConfigContext';
1717
import {
1818
ImageGalleryContextValue,
@@ -58,6 +58,7 @@ export type GalleryPropsWithContext<
5858
| 'VideoThumbnail'
5959
| 'ImageLoadingIndicator'
6060
| 'ImageLoadingFailedIndicator'
61+
| 'ImageReloadIndicator'
6162
| 'myMessageTheme'
6263
> &
6364
Pick<OverlayContextValue, 'setOverlay'> & {
@@ -90,6 +91,7 @@ const GalleryWithContext = <
9091
hasThreadReplies,
9192
ImageLoadingFailedIndicator,
9293
ImageLoadingIndicator,
94+
ImageReloadIndicator,
9395
images,
9496
legacyImageViewerSwipeBehaviour,
9597
message,
@@ -207,6 +209,7 @@ const GalleryWithContext = <
207209
colIndex={colIndex}
208210
ImageLoadingFailedIndicator={ImageLoadingFailedIndicator}
209211
ImageLoadingIndicator={ImageLoadingIndicator}
212+
ImageReloadIndicator={ImageReloadIndicator}
210213
imagesAndVideos={imagesAndVideos}
211214
invertedDirections={invertedDirections || false}
212215
key={rowIndex}
@@ -258,6 +261,7 @@ type GalleryThumbnailProps<
258261
| 'VideoThumbnail'
259262
| 'ImageLoadingIndicator'
260263
| 'ImageLoadingFailedIndicator'
264+
| 'ImageReloadIndicator'
261265
> &
262266
Pick<ImageGalleryContextValue<StreamChatGenerics>, 'setSelectedMessage' | 'setMessages'> &
263267
Pick<
@@ -274,6 +278,7 @@ const GalleryThumbnail = <
274278
colIndex,
275279
ImageLoadingFailedIndicator,
276280
ImageLoadingIndicator,
281+
ImageReloadIndicator,
277282
imagesAndVideos,
278283
invertedDirections,
279284
legacyImageViewerSwipeBehaviour,
@@ -306,6 +311,7 @@ const GalleryThumbnail = <
306311
},
307312
},
308313
} = useTheme();
314+
const { t } = useTranslationContext();
309315

310316
const openImageViewer = () => {
311317
if (!legacyImageViewerSwipeBehaviour && message) {
@@ -397,6 +403,7 @@ const GalleryThumbnail = <
397403
borderRadius={imageBorderRadius ?? borderRadius}
398404
ImageLoadingFailedIndicator={ImageLoadingFailedIndicator}
399405
ImageLoadingIndicator={ImageLoadingIndicator}
406+
ImageReloadIndicator={ImageReloadIndicator}
400407
thumbnail={thumbnail}
401408
/>
402409
</View>
@@ -411,7 +418,7 @@ const GalleryThumbnail = <
411418
]}
412419
>
413420
<Text style={[styles.moreImagesText, moreImagesText]}>
414-
{`+${imagesAndVideos.length - 4}`}
421+
{String(t('+{{count}}', { count: imagesAndVideos.length - 4 }))}
415422
</Text>
416423
</View>
417424
) : null}
@@ -425,10 +432,15 @@ const GalleryImageThumbnail = <
425432
borderRadius,
426433
ImageLoadingFailedIndicator,
427434
ImageLoadingIndicator,
435+
ImageReloadIndicator,
428436
thumbnail,
429437
}: Pick<
430438
GalleryThumbnailProps<StreamChatGenerics>,
431-
'ImageLoadingFailedIndicator' | 'ImageLoadingIndicator' | 'thumbnail' | 'borderRadius'
439+
| 'ImageLoadingFailedIndicator'
440+
| 'ImageLoadingIndicator'
441+
| 'ImageReloadIndicator'
442+
| 'thumbnail'
443+
| 'borderRadius'
432444
>) => {
433445
const {
434446
isLoadingImage,
@@ -585,6 +597,7 @@ export const Gallery = <
585597
hasThreadReplies,
586598
ImageLoadingFailedIndicator: PropImageLoadingFailedIndicator,
587599
ImageLoadingIndicator: PropImageLoadingIndicator,
600+
ImageReloadIndicator: PropImageReloadIndicator,
588601
images: propImages,
589602
message: propMessage,
590603
myMessageTheme: propMyMessageTheme,
@@ -617,6 +630,7 @@ export const Gallery = <
617630
additionalPressableProps: contextAdditionalPressableProps,
618631
ImageLoadingFailedIndicator: ContextImageLoadingFailedIndicator,
619632
ImageLoadingIndicator: ContextImageLoadingIndicator,
633+
ImageReloadIndicator: ContextImageReloadIndicator,
620634
legacyImageViewerSwipeBehaviour,
621635
myMessageTheme: contextMyMessageTheme,
622636
VideoThumbnail: ContextVideoThumnbnail,
@@ -646,6 +660,7 @@ export const Gallery = <
646660
const ImageLoadingFailedIndicator =
647661
PropImageLoadingFailedIndicator || ContextImageLoadingFailedIndicator;
648662
const ImageLoadingIndicator = PropImageLoadingIndicator || ContextImageLoadingIndicator;
663+
const ImageReloadIndicator = PropImageReloadIndicator || ContextImageReloadIndicator;
649664
const myMessageTheme = propMyMessageTheme || contextMyMessageTheme;
650665

651666
return (
@@ -658,6 +673,7 @@ export const Gallery = <
658673
hasThreadReplies: hasThreadReplies || !!message?.reply_count,
659674
ImageLoadingFailedIndicator,
660675
ImageLoadingIndicator,
676+
ImageReloadIndicator,
661677
images,
662678
legacyImageViewerSwipeBehaviour,
663679
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'
@@ -568,6 +570,7 @@ const ChannelWithContext = <
568570
hideStickyDateHeader = false,
569571
ImageLoadingFailedIndicator = ImageLoadingFailedIndicatorDefault,
570572
ImageLoadingIndicator = ImageLoadingIndicatorDefault,
573+
ImageReloadIndicator = ImageReloadIndicatorDefault,
571574
ImageUploadPreview = ImageUploadPreviewDefault,
572575
initialScrollToFirstUnreadMessage = false,
573576
initialValue,
@@ -1916,6 +1919,7 @@ const ChannelWithContext = <
19161919
hasCreatePoll === undefined ? pollCreationEnabled : hasCreatePoll && pollCreationEnabled,
19171920
ImageLoadingFailedIndicator,
19181921
ImageLoadingIndicator,
1922+
ImageReloadIndicator,
19191923
initialScrollToFirstUnreadMessage: !messageId && initialScrollToFirstUnreadMessage, // when messageId is set, we scroll to the messageId instead of first unread
19201924
InlineDateSeparator,
19211925
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/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from './Attachment/FileIcon';
88
export * from './Attachment/Gallery';
99
export * from './Attachment/Giphy';
1010
export * from './Attachment/VideoThumbnail';
11+
export * from './Attachment/ImageReloadIndicator';
1112
export * from './Attachment/utils/buildGallery/buildGallery';
1213

1314
export * from './AttachmentPicker/AttachmentPicker';

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
*/

package/src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './useViewport';
44
export * from './useScreenDimensions';
55
export * from './useStateStore';
66
export * from './useStableCallback';
7+
export * from './useLoadingImage';

package/src/i18n/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"+{{count}}_many": "+{{count}}",
3+
"+{{count}}_one": "+{{count}}",
4+
"+{{count}}_other": "+{{count}}",
25
"1 Reply": "1 Reply",
36
"1 Thread Reply": "1 Thread Reply",
47
"Add a comment": "Add a comment",

package/src/i18n/es.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"+{{count}}_many": "+{{count}}",
3+
"+{{count}}_one": "+{{count}}",
4+
"+{{count}}_other": "+{{count}}",
25
"1 Reply": "1 respuesta",
36
"1 Thread Reply": "1 respuesta de hilo",
47
"Add a comment": "Agregar un comentario",

package/src/i18n/fr.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"+{{count}}_many": "+{{count}}",
3+
"+{{count}}_one": "+{{count}}",
4+
"+{{count}}_other": "+{{count}}",
25
"1 Reply": "1 Réponse",
36
"1 Thread Reply": "Réponse à 1 fil",
47
"Add a comment": "Ajouter un commentaire",

0 commit comments

Comments
 (0)