@cometchat/chat-uikit-react-native 5.3.10 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +52 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +95 -8
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +237 -6
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +2 -1
- package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +85 -47
- package/ios/CometChatClipboardModule.m +11 -0
- package/ios/CometChatClipboardModule.swift +41 -0
- package/ios/FileManager.m +201 -39
- package/ios/RichTextEditorView.swift +312 -4
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/SoundPlayer.m +18 -6
- package/package.json +9 -7
- package/react-native-cometchat-ui-kit.podspec +1 -0
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +692 -107
- package/src/CometChatConversations/CometChatConversations.tsx +19 -6
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +649 -49
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +23 -4
- package/src/CometChatMessageList/CometChatMessageList.tsx +463 -54
- package/src/CometChatMessageList/MANUAL_TEST_CASES.md +154 -0
- package/src/CometChatMessageList/components/MessageListItem.tsx +30 -17
- package/src/CometChatMessageList/style.ts +33 -5
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +13 -0
- package/src/CometChatRichTextEditor/index.tsx +25 -0
- package/src/CometChatSearch/CometChatSearch.tsx +296 -154
- package/src/calls/CallingExtension.tsx +19 -13
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +20 -1
- package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +20 -9
- package/src/index.ts +39 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +40 -34
- package/src/shared/base/Types.ts +3 -0
- package/src/shared/constants/UIKitConstants.ts +15 -1
- package/src/shared/framework/DataSource.ts +14 -4
- package/src/shared/framework/DataSourceDecorator.tsx +17 -8
- package/src/shared/framework/MessageDataSource.tsx +307 -60
- package/src/shared/helper/useToast.tsx +29 -0
- package/src/shared/icons/components/audio-file-type.tsx +11 -22
- package/src/shared/icons/components/document-file-type.tsx +11 -24
- package/src/shared/icons/components/image-file-type.tsx +12 -21
- package/src/shared/icons/components/link-file-type.tsx +25 -0
- package/src/shared/icons/components/pdf-file-type.tsx +11 -22
- package/src/shared/icons/components/presentation-file-type.tsx +11 -24
- package/src/shared/icons/components/spreadsheet-file-type.tsx +11 -24
- package/src/shared/icons/components/text-file-type.tsx +11 -21
- package/src/shared/icons/components/unknown-file-type.tsx +21 -25
- package/src/shared/icons/components/video-file-type.tsx +11 -24
- package/src/shared/icons/components/zip-file-type.tsx +11 -24
- package/src/shared/icons/icon-mapping.tsx +2 -0
- package/src/shared/index.ts +28 -0
- package/src/shared/modals/AttachmentPickerConfiguration.ts +13 -0
- package/src/shared/modals/SelectedAttachment.ts +65 -0
- package/src/shared/modals/UploadState.ts +10 -0
- package/src/shared/modals/index.ts +4 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +42 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +42 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +43 -2
- package/src/shared/services/UploadQueueService.ts +145 -0
- package/src/shared/services/index.ts +2 -0
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +42 -18
- package/src/shared/utils/MessageUtils.tsx +13 -4
- package/src/shared/utils/attachmentLimits.ts +156 -0
- package/src/shared/utils/audioPlaybackCoordinator.ts +28 -0
- package/src/shared/utils/batchMediaContext.tsx +30 -0
- package/src/shared/utils/conversationUtils.ts +26 -4
- package/src/shared/utils/groupAttachments.ts +93 -0
- package/src/shared/utils/index.ts +8 -0
- package/src/shared/utils/openMultiFileChooser.ts +123 -0
- package/src/shared/utils/partitionAttachmentsByKind.ts +44 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +28 -0
- package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +16 -0
- package/src/shared/views/ClipboardPasteHandler/index.ts +2 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +1 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +32 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.tsx +90 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +276 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +827 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTray.tsx +110 -0
- package/src/shared/views/CometChatAttachmentPreview/StagedVideoDurationProbe.tsx +53 -0
- package/src/shared/views/CometChatAttachmentPreview/index.ts +8 -0
- package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +305 -0
- package/src/shared/views/CometChatAttachmentViewer/index.ts +2 -0
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +71 -74
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +587 -0
- package/src/shared/views/CometChatAudiosBubble/index.ts +2 -0
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +5 -7
- package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +182 -0
- package/src/shared/views/CometChatCaptionText/index.ts +2 -0
- package/src/shared/views/CometChatComposerErrorBanner.tsx +83 -0
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +141 -0
- package/src/shared/views/CometChatConversationStarter/index.ts +2 -0
- package/src/shared/views/CometChatConversationSummary/CometChatConversationSummary.tsx +155 -0
- package/src/shared/views/CometChatConversationSummary/index.ts +2 -0
- package/src/shared/views/CometChatFileBubble/style.ts +6 -4
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +316 -0
- package/src/shared/views/CometChatFilesBubble/index.ts +2 -0
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +323 -0
- package/src/shared/views/CometChatImagesBubble/index.ts +2 -0
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +425 -0
- package/src/shared/views/CometChatMediaViewer/index.ts +2 -0
- package/src/shared/views/CometChatMediaViewer/mediaViewerUtils.ts +30 -0
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +14 -4
- package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +1 -0
- package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +172 -0
- package/src/shared/views/CometChatSmartReplies/index.ts +2 -0
- package/src/shared/views/CometChatVideoBubble/style.ts +3 -3
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +441 -0
- package/src/shared/views/CometChatVideosBubble/index.ts +2 -0
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +78 -0
- package/src/shared/views/CometChatVoiceNoteBubble/index.ts +2 -0
- package/src/shared/views/index.ts +37 -1
- package/src/theme/CometChatThemeHelper.ts +8 -0
- package/src/theme/default/color/dark.ts +9 -0
- package/src/theme/default/color/light.ts +10 -0
- package/src/theme/type.ts +73 -0
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +0 -478
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +0 -613
- package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +0 -76
- package/src/shared/CometChatUiKit/checkAuthSettings-review.md +0 -211
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CometChatMediaViewer — §8.2.1
|
|
3
|
+
*
|
|
4
|
+
* Unified fullscreen pager for image + video attachments.
|
|
5
|
+
* Each page renders by mimeType:
|
|
6
|
+
* - image/* → zoomable image
|
|
7
|
+
* - video/* → inline react-native-video player
|
|
8
|
+
*
|
|
9
|
+
* Audio and file attachments are NOT pages here — they are handled at the tile level.
|
|
10
|
+
* Contract: `mediaItems` should contain only image/* and video/* attachments.
|
|
11
|
+
*/
|
|
12
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
13
|
+
import {
|
|
14
|
+
ActivityIndicator,
|
|
15
|
+
Dimensions,
|
|
16
|
+
Image,
|
|
17
|
+
Modal,
|
|
18
|
+
NativeModules,
|
|
19
|
+
PanResponder,
|
|
20
|
+
Platform,
|
|
21
|
+
StyleSheet,
|
|
22
|
+
Text,
|
|
23
|
+
TouchableOpacity,
|
|
24
|
+
View,
|
|
25
|
+
} from 'react-native';
|
|
26
|
+
import { CometChat } from '@cometchat/chat-sdk-react-native';
|
|
27
|
+
import Video from 'react-native-video';
|
|
28
|
+
import { Icon } from '../../icons/Icon';
|
|
29
|
+
import { useTheme } from '../../../theme';
|
|
30
|
+
import { useCometChatTranslation } from '../../resources/CometChatLocalizeNew';
|
|
31
|
+
import { clampIndex, isImageMime, isVideoMime, nextIndexForSwipe } from './mediaViewerUtils';
|
|
32
|
+
|
|
33
|
+
/** Default: an item is previewable if it's an image or a video. A per-kind bubble (ImagesBubble /
|
|
34
|
+
* VideosBubble) overrides this so anything outside its own kind renders the "No preview" page. */
|
|
35
|
+
const defaultCanPreview = (att: CometChat.Attachment): boolean => {
|
|
36
|
+
const m = att.getMimeType?.() ?? '';
|
|
37
|
+
return isImageMime(m) || isVideoMime(m);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export interface CometChatMediaViewerProps {
|
|
41
|
+
/** Attachments to page through. May include non-previewable items → "No preview available" page. */
|
|
42
|
+
mediaItems: CometChat.Attachment[];
|
|
43
|
+
/** Zero-based index of the item to open on. */
|
|
44
|
+
startIndex: number;
|
|
45
|
+
visible: boolean;
|
|
46
|
+
onClose: () => void;
|
|
47
|
+
/** Optional: the parent message (used for sender/timestamp in header). */
|
|
48
|
+
message?: CometChat.BaseMessage;
|
|
49
|
+
/** Which items get a real preview; the rest show the "No preview available" page. Defaults to
|
|
50
|
+
* image-or-video. VideosBubble passes video-only, ImagesBubble image-only. */
|
|
51
|
+
canPreview?: (att: CometChat.Attachment) => boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type DownloadState = 'IDLE' | 'DOWNLOADING' | 'DONE' | 'FAILED';
|
|
55
|
+
|
|
56
|
+
const { FileManager } = NativeModules;
|
|
57
|
+
const { width: SCREEN_W } = Dimensions.get('window');
|
|
58
|
+
|
|
59
|
+
function formatFileSize(bytes: number): string {
|
|
60
|
+
if (!(bytes > 0)) return ''; // undefined / 0 / NaN → show nothing (not "undefined B")
|
|
61
|
+
if (bytes >= 1_048_576) return `${(bytes / 1_048_576).toFixed(1)} MB`;
|
|
62
|
+
if (bytes >= 1_024) return `${(bytes / 1_024).toFixed(0)} KB`;
|
|
63
|
+
return `${bytes} B`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
export const CometChatMediaViewer = ({
|
|
68
|
+
mediaItems,
|
|
69
|
+
startIndex,
|
|
70
|
+
visible,
|
|
71
|
+
onClose,
|
|
72
|
+
message,
|
|
73
|
+
canPreview = defaultCanPreview,
|
|
74
|
+
}: CometChatMediaViewerProps) => {
|
|
75
|
+
const { t } = useCometChatTranslation();
|
|
76
|
+
const theme = useTheme();
|
|
77
|
+
const [currentIndex, setCurrentIndex] = useState(() => clampIndex(startIndex, mediaItems.length));
|
|
78
|
+
const [mediaLoaded, setMediaLoaded] = useState(false);
|
|
79
|
+
const [mediaError, setMediaError] = useState(false);
|
|
80
|
+
const [isBuffering, setIsBuffering] = useState(false);
|
|
81
|
+
const [downloadState, setDownloadState] = useState<DownloadState>('IDLE');
|
|
82
|
+
|
|
83
|
+
// Ref so PanResponder closure always reads the latest index without re-creation
|
|
84
|
+
const currentIndexRef = useRef(clampIndex(startIndex, mediaItems.length));
|
|
85
|
+
|
|
86
|
+
// Sync startIndex when viewer reopens on a different item (clamped so out-of-range can't blank the page)
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (visible) {
|
|
89
|
+
const clamped = clampIndex(startIndex, mediaItems.length);
|
|
90
|
+
currentIndexRef.current = clamped;
|
|
91
|
+
setCurrentIndex(clamped);
|
|
92
|
+
setMediaLoaded(false);
|
|
93
|
+
setMediaError(false);
|
|
94
|
+
setDownloadState('IDLE');
|
|
95
|
+
setIsBuffering(false);
|
|
96
|
+
}
|
|
97
|
+
}, [visible, startIndex, mediaItems.length]);
|
|
98
|
+
|
|
99
|
+
const current = mediaItems[currentIndex];
|
|
100
|
+
// A per-kind bubble marks off-kind attachments (e.g. a .jpg inside a VIDEO message) as not
|
|
101
|
+
// previewable → they render the "No preview available" page instead of the image/video.
|
|
102
|
+
const previewable = current ? canPreview(current) : false;
|
|
103
|
+
const isVideo = previewable && current ? isVideoMime(current.getMimeType?.() ?? '') : false;
|
|
104
|
+
|
|
105
|
+
const mediaItemsRef = useRef(mediaItems);
|
|
106
|
+
// Keep the ref in sync outside render (not during it) so the PanResponder closure reads the latest list.
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
mediaItemsRef.current = mediaItems;
|
|
109
|
+
}, [mediaItems]);
|
|
110
|
+
|
|
111
|
+
const goTo = (idx: number) => {
|
|
112
|
+
const clamped = clampIndex(idx, mediaItemsRef.current.length);
|
|
113
|
+
currentIndexRef.current = clamped;
|
|
114
|
+
setCurrentIndex(clamped);
|
|
115
|
+
setMediaLoaded(false);
|
|
116
|
+
setMediaError(false);
|
|
117
|
+
setDownloadState('IDLE');
|
|
118
|
+
setIsBuffering(false);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const panResponder = useRef(
|
|
122
|
+
PanResponder.create({
|
|
123
|
+
// Swipe-to-page only on IMAGE pages. On video pages the native controls own all gestures
|
|
124
|
+
// (scrubbing is horizontal too), so we don't hijack them — page via the on-screen arrows (B3).
|
|
125
|
+
onMoveShouldSetPanResponder: (_, gs) => {
|
|
126
|
+
const it = mediaItemsRef.current[currentIndexRef.current];
|
|
127
|
+
const onVideo = it ? isVideoMime(it.getMimeType?.() ?? '') : false;
|
|
128
|
+
return !onVideo && Math.abs(gs.dx) > 10 && Math.abs(gs.dx) > Math.abs(gs.dy);
|
|
129
|
+
},
|
|
130
|
+
onPanResponderRelease: (_, gs) => {
|
|
131
|
+
const idx = currentIndexRef.current;
|
|
132
|
+
const next = nextIndexForSwipe(gs.dx, idx, mediaItemsRef.current.length);
|
|
133
|
+
if (next !== idx) goTo(next);
|
|
134
|
+
},
|
|
135
|
+
})
|
|
136
|
+
).current;
|
|
137
|
+
|
|
138
|
+
const handleDownload = () => {
|
|
139
|
+
if (!current || downloadState === 'DOWNLOADING' || downloadState === 'DONE') return;
|
|
140
|
+
setDownloadState('DOWNLOADING');
|
|
141
|
+
FileManager?.checkAndDownload(current.getUrl(), current.getName(), (result: string) => {
|
|
142
|
+
try {
|
|
143
|
+
const parsed = JSON.parse(result);
|
|
144
|
+
setDownloadState(parsed.success ? 'DONE' : 'FAILED');
|
|
145
|
+
} catch {
|
|
146
|
+
setDownloadState('FAILED');
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
if (!current) return null;
|
|
152
|
+
|
|
153
|
+
const shortName =
|
|
154
|
+
current.getName().length > 22
|
|
155
|
+
? `${current.getName().substring(0, 19)}…`
|
|
156
|
+
: current.getName();
|
|
157
|
+
|
|
158
|
+
const counterLabel = `${currentIndex + 1} / ${mediaItems.length}`;
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<Modal
|
|
162
|
+
animationType="slide"
|
|
163
|
+
transparent={false}
|
|
164
|
+
visible={visible}
|
|
165
|
+
onRequestClose={onClose}
|
|
166
|
+
statusBarTranslucent
|
|
167
|
+
>
|
|
168
|
+
<View testID="media-viewer" style={styles.root}>
|
|
169
|
+
{/* Header */}
|
|
170
|
+
<View style={styles.header}>
|
|
171
|
+
<TouchableOpacity
|
|
172
|
+
testID="media-viewer.close"
|
|
173
|
+
onPress={onClose}
|
|
174
|
+
style={styles.headerBtn}
|
|
175
|
+
accessibilityRole="button"
|
|
176
|
+
accessibilityLabel="Close viewer"
|
|
177
|
+
>
|
|
178
|
+
<Icon name="arrow-back-fill" color="#fff" height={22} width={22} />
|
|
179
|
+
</TouchableOpacity>
|
|
180
|
+
|
|
181
|
+
<View style={styles.headerMeta}>
|
|
182
|
+
<Text style={styles.headerTitle} numberOfLines={1}>{shortName}</Text>
|
|
183
|
+
<Text style={styles.headerSubtitle}>
|
|
184
|
+
{[formatFileSize(current.getSize()), mediaItems.length > 1 ? counterLabel : ''].filter(Boolean).join(' • ')}
|
|
185
|
+
</Text>
|
|
186
|
+
</View>
|
|
187
|
+
|
|
188
|
+
<TouchableOpacity
|
|
189
|
+
onPress={handleDownload}
|
|
190
|
+
style={styles.headerBtn}
|
|
191
|
+
accessibilityRole="button"
|
|
192
|
+
accessibilityLabel="Download"
|
|
193
|
+
disabled={downloadState === 'DOWNLOADING'}
|
|
194
|
+
>
|
|
195
|
+
{downloadState === 'DOWNLOADING' ? (
|
|
196
|
+
<ActivityIndicator color="#fff" size="small" />
|
|
197
|
+
) : downloadState === 'DONE' ? (
|
|
198
|
+
<Text style={styles.doneCheck}>{'✓'}</Text>
|
|
199
|
+
) : (
|
|
200
|
+
<Icon name="download-fill" color="#fff" height={20} width={20} />
|
|
201
|
+
)}
|
|
202
|
+
</TouchableOpacity>
|
|
203
|
+
</View>
|
|
204
|
+
|
|
205
|
+
{/* Media area — swipeable */}
|
|
206
|
+
<View style={styles.mediaArea} {...panResponder.panHandlers}>
|
|
207
|
+
{previewable && !mediaLoaded && !mediaError && (
|
|
208
|
+
<ActivityIndicator
|
|
209
|
+
color="#fff"
|
|
210
|
+
size="large"
|
|
211
|
+
style={StyleSheet.absoluteFill}
|
|
212
|
+
/>
|
|
213
|
+
)}
|
|
214
|
+
|
|
215
|
+
{!previewable ? (
|
|
216
|
+
// "No preview available" — an attachment outside this bubble's kind (e.g. an image inside
|
|
217
|
+
// a video message). Only a download is offered, like Google Drive's unsupported preview.
|
|
218
|
+
<View style={styles.noPreviewBox}>
|
|
219
|
+
<View style={styles.noPreviewIconCircle}>
|
|
220
|
+
<Icon name="unknown-file-type" height={56} width={56} />
|
|
221
|
+
</View>
|
|
222
|
+
<Text style={styles.noPreviewTitle}>
|
|
223
|
+
{t('NO_PREVIEW_AVAILABLE') || 'No preview available'}
|
|
224
|
+
</Text>
|
|
225
|
+
<Text style={styles.noPreviewSubtitle}>
|
|
226
|
+
{t('FILE_TYPE_NOT_SUPPORTED_PREVIEW') || "This file type isn't supported for preview."}
|
|
227
|
+
</Text>
|
|
228
|
+
<TouchableOpacity
|
|
229
|
+
testID="media-viewer.no-preview-download"
|
|
230
|
+
onPress={handleDownload}
|
|
231
|
+
disabled={downloadState === 'DOWNLOADING'}
|
|
232
|
+
style={[styles.downloadBtn, { backgroundColor: theme.color.primary }]}
|
|
233
|
+
accessibilityRole="button"
|
|
234
|
+
accessibilityLabel="Download"
|
|
235
|
+
>
|
|
236
|
+
{downloadState === 'DOWNLOADING' ? (
|
|
237
|
+
<ActivityIndicator color="#fff" size="small" />
|
|
238
|
+
) : (
|
|
239
|
+
<Icon
|
|
240
|
+
name={downloadState === 'DONE' ? 'check-fill' : 'download-fill'}
|
|
241
|
+
color="#fff"
|
|
242
|
+
height={20}
|
|
243
|
+
width={20}
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
<Text style={styles.downloadBtnText}>
|
|
247
|
+
{downloadState === 'DONE'
|
|
248
|
+
? t('DOWNLOADED') || 'Downloaded'
|
|
249
|
+
: t('DOWNLOAD') || 'Download'}
|
|
250
|
+
</Text>
|
|
251
|
+
</TouchableOpacity>
|
|
252
|
+
</View>
|
|
253
|
+
) : mediaError ? (
|
|
254
|
+
<View style={styles.errorBox}>
|
|
255
|
+
<Icon name="error-fill" color="#fff" height={40} width={40} />
|
|
256
|
+
<Text style={styles.errorText}>
|
|
257
|
+
{t('SOMETHING_WRONG') ?? 'Something went wrong. Please try again.'}
|
|
258
|
+
</Text>
|
|
259
|
+
</View>
|
|
260
|
+
) : isVideo ? (
|
|
261
|
+
// Native controls own play/pause/scrub — no custom tap-to-pause overlay, which would
|
|
262
|
+
// fight the control taps (B3).
|
|
263
|
+
<View style={styles.videoWrapper}>
|
|
264
|
+
<Video
|
|
265
|
+
source={{ uri: current.getUrl() }}
|
|
266
|
+
controls={true}
|
|
267
|
+
// The <Modal> keeps its children mounted when hidden, so without this the video would
|
|
268
|
+
// keep playing (audio too) after the viewer closes. Pause whenever the viewer isn't visible.
|
|
269
|
+
paused={!visible}
|
|
270
|
+
resizeMode="contain"
|
|
271
|
+
onLoad={() => { setMediaLoaded(true); setIsBuffering(false); }}
|
|
272
|
+
onLoadStart={() => setIsBuffering(true)}
|
|
273
|
+
onBuffer={({ isBuffering: b }) => setIsBuffering(b)}
|
|
274
|
+
onError={e => {
|
|
275
|
+
console.warn('[CometChatMediaViewer] video error', e);
|
|
276
|
+
setMediaError(true);
|
|
277
|
+
setMediaLoaded(true);
|
|
278
|
+
setIsBuffering(false);
|
|
279
|
+
}}
|
|
280
|
+
style={styles.fullMedia}
|
|
281
|
+
/>
|
|
282
|
+
{isBuffering && (
|
|
283
|
+
<ActivityIndicator
|
|
284
|
+
color="#fff"
|
|
285
|
+
size="large"
|
|
286
|
+
style={StyleSheet.absoluteFill}
|
|
287
|
+
/>
|
|
288
|
+
)}
|
|
289
|
+
</View>
|
|
290
|
+
) : (
|
|
291
|
+
<Image
|
|
292
|
+
source={{ uri: current.getUrl() }}
|
|
293
|
+
style={styles.fullMedia}
|
|
294
|
+
resizeMode="contain"
|
|
295
|
+
onLoad={() => setMediaLoaded(true)}
|
|
296
|
+
onError={() => { setMediaError(true); setMediaLoaded(true); }}
|
|
297
|
+
/>
|
|
298
|
+
)}
|
|
299
|
+
</View>
|
|
300
|
+
|
|
301
|
+
{/* Prev / Next arrows */}
|
|
302
|
+
{currentIndex > 0 && (
|
|
303
|
+
<TouchableOpacity
|
|
304
|
+
style={[styles.navArrow, styles.navLeft]}
|
|
305
|
+
onPress={() => goTo(currentIndex - 1)}
|
|
306
|
+
accessibilityRole="button"
|
|
307
|
+
accessibilityLabel="Previous"
|
|
308
|
+
>
|
|
309
|
+
<Icon name="arrow-back-fill" color="#fff" height={24} width={24} />
|
|
310
|
+
</TouchableOpacity>
|
|
311
|
+
)}
|
|
312
|
+
{currentIndex < mediaItems.length - 1 && (
|
|
313
|
+
<TouchableOpacity
|
|
314
|
+
style={[styles.navArrow, styles.navRight]}
|
|
315
|
+
onPress={() => goTo(currentIndex + 1)}
|
|
316
|
+
accessibilityRole="button"
|
|
317
|
+
accessibilityLabel="Next"
|
|
318
|
+
>
|
|
319
|
+
<Icon name="arrow-forward-fill" color="#fff" height={24} width={24} />
|
|
320
|
+
</TouchableOpacity>
|
|
321
|
+
)}
|
|
322
|
+
|
|
323
|
+
{/* Footer — page dots */}
|
|
324
|
+
{mediaItems.length > 1 && (
|
|
325
|
+
<View style={styles.footer}>
|
|
326
|
+
<View style={styles.dotsRow}>
|
|
327
|
+
{mediaItems.map((_, i) => (
|
|
328
|
+
<View
|
|
329
|
+
key={i}
|
|
330
|
+
style={[styles.dot, i === currentIndex ? styles.dotActive : undefined]}
|
|
331
|
+
/>
|
|
332
|
+
))}
|
|
333
|
+
</View>
|
|
334
|
+
</View>
|
|
335
|
+
)}
|
|
336
|
+
</View>
|
|
337
|
+
</Modal>
|
|
338
|
+
);
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const styles = StyleSheet.create({
|
|
342
|
+
root: { flex: 1, backgroundColor: '#000' },
|
|
343
|
+
header: {
|
|
344
|
+
position: 'absolute',
|
|
345
|
+
top: 0,
|
|
346
|
+
left: 0,
|
|
347
|
+
right: 0,
|
|
348
|
+
zIndex: 10,
|
|
349
|
+
flexDirection: 'row',
|
|
350
|
+
alignItems: 'center',
|
|
351
|
+
paddingTop: Platform.OS === 'ios' ? 52 : 28,
|
|
352
|
+
paddingHorizontal: 8,
|
|
353
|
+
paddingBottom: 12,
|
|
354
|
+
backgroundColor: 'rgba(0,0,0,0.45)',
|
|
355
|
+
},
|
|
356
|
+
headerBtn: {
|
|
357
|
+
width: 44,
|
|
358
|
+
height: 44,
|
|
359
|
+
justifyContent: 'center',
|
|
360
|
+
alignItems: 'center',
|
|
361
|
+
},
|
|
362
|
+
headerMeta: { flex: 1, marginHorizontal: 4 },
|
|
363
|
+
headerTitle: { color: '#fff', fontSize: 15, fontWeight: '600' },
|
|
364
|
+
headerSubtitle: { color: 'rgba(255,255,255,0.65)', fontSize: 12, marginTop: 2 },
|
|
365
|
+
doneCheck: { color: '#fff', fontSize: 18 },
|
|
366
|
+
mediaArea: {
|
|
367
|
+
flex: 1,
|
|
368
|
+
justifyContent: 'center',
|
|
369
|
+
alignItems: 'center',
|
|
370
|
+
marginTop: Platform.OS === 'ios' ? 100 : 80,
|
|
371
|
+
marginBottom: 60,
|
|
372
|
+
},
|
|
373
|
+
videoWrapper: { flex: 1, width: SCREEN_W },
|
|
374
|
+
fullMedia: { width: SCREEN_W, flex: 1 },
|
|
375
|
+
errorBox: { flex: 1, justifyContent: 'center', alignItems: 'center', gap: 12, paddingHorizontal: 24 },
|
|
376
|
+
errorText: { color: 'rgba(255,255,255,0.8)', fontSize: 14, textAlign: 'center' },
|
|
377
|
+
noPreviewBox: { flex: 1, justifyContent: 'center', alignItems: 'center', gap: 12, paddingHorizontal: 24 },
|
|
378
|
+
noPreviewIconCircle: {
|
|
379
|
+
width: 128,
|
|
380
|
+
height: 128,
|
|
381
|
+
borderRadius: 64,
|
|
382
|
+
backgroundColor: 'rgba(255,255,255,0.06)',
|
|
383
|
+
justifyContent: 'center',
|
|
384
|
+
alignItems: 'center',
|
|
385
|
+
marginBottom: 12,
|
|
386
|
+
},
|
|
387
|
+
noPreviewTitle: { color: '#fff', fontSize: 22, fontWeight: '700', textAlign: 'center' },
|
|
388
|
+
noPreviewSubtitle: { color: 'rgba(255,255,255,0.6)', fontSize: 15, textAlign: 'center' },
|
|
389
|
+
downloadBtn: {
|
|
390
|
+
flexDirection: 'row',
|
|
391
|
+
alignItems: 'center',
|
|
392
|
+
gap: 8,
|
|
393
|
+
paddingVertical: 14,
|
|
394
|
+
paddingHorizontal: 32,
|
|
395
|
+
borderRadius: 12,
|
|
396
|
+
marginTop: 16,
|
|
397
|
+
},
|
|
398
|
+
downloadBtnText: { color: '#fff', fontSize: 16, fontWeight: '600' },
|
|
399
|
+
navArrow: {
|
|
400
|
+
position: 'absolute',
|
|
401
|
+
top: '50%',
|
|
402
|
+
marginTop: -22,
|
|
403
|
+
width: 44,
|
|
404
|
+
height: 44,
|
|
405
|
+
justifyContent: 'center',
|
|
406
|
+
alignItems: 'center',
|
|
407
|
+
backgroundColor: 'rgba(0,0,0,0.35)',
|
|
408
|
+
borderRadius: 22,
|
|
409
|
+
zIndex: 20,
|
|
410
|
+
},
|
|
411
|
+
navLeft: { left: 8 },
|
|
412
|
+
navRight: { right: 8 },
|
|
413
|
+
footer: {
|
|
414
|
+
position: 'absolute',
|
|
415
|
+
bottom: 0,
|
|
416
|
+
left: 0,
|
|
417
|
+
right: 0,
|
|
418
|
+
paddingBottom: Platform.OS === 'ios' ? 32 : 16,
|
|
419
|
+
alignItems: 'center',
|
|
420
|
+
backgroundColor: 'rgba(0,0,0,0.35)',
|
|
421
|
+
},
|
|
422
|
+
dotsRow: { flexDirection: 'row', gap: 6, paddingVertical: 10 },
|
|
423
|
+
dot: { width: 6, height: 6, borderRadius: 3, backgroundColor: 'rgba(255,255,255,0.35)' },
|
|
424
|
+
dotActive: { backgroundColor: '#fff' },
|
|
425
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, native-free helpers for CometChatMediaViewer — extracted so the pager/index logic can be
|
|
3
|
+
* property-tested without importing react-native / react-native-video (repo convention: test pure
|
|
4
|
+
* logic, not rendered components).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export function isVideoMime(mime: string): boolean {
|
|
8
|
+
return mime.startsWith('video/');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isImageMime(mime: string): boolean {
|
|
12
|
+
return mime.startsWith('image/');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Keep an index inside [0, len-1] so an out-of-range startIndex never lands on a blank page (PR review). */
|
|
16
|
+
export function clampIndex(i: number, len: number): number {
|
|
17
|
+
if (len <= 0) return 0;
|
|
18
|
+
return Math.max(0, Math.min(i, len - 1));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Swipe-to-page result: a left-swipe (dx ≤ -threshold) advances, a right-swipe (dx ≥ threshold)
|
|
23
|
+
* retreats, both clamped to [0, total-1]. A sub-threshold swipe (or one at an edge) returns the
|
|
24
|
+
* clamped current index, i.e. no page change.
|
|
25
|
+
*/
|
|
26
|
+
export function nextIndexForSwipe(dx: number, current: number, total: number, threshold = 40): number {
|
|
27
|
+
if (dx <= -threshold) return clampIndex(current + 1, total);
|
|
28
|
+
if (dx >= threshold) return clampIndex(current - 1, total);
|
|
29
|
+
return clampIndex(current, total);
|
|
30
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { memo, useState, useCallback, useMemo, JSX } from "react";
|
|
2
|
-
import { View,
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
3
3
|
import { BubbleStyles } from "../../../theme/type";
|
|
4
4
|
import { MessageBubbleAlignmentType } from "../../base/Types";
|
|
5
5
|
|
|
@@ -126,11 +126,11 @@ export const CometChatMessageBubble = memo(
|
|
|
126
126
|
alignItems: alignItems,
|
|
127
127
|
}}
|
|
128
128
|
>
|
|
129
|
-
<View style={
|
|
129
|
+
<View style={styles.row}>
|
|
130
130
|
{LeadingView && LeadingView}
|
|
131
|
-
<View style={
|
|
131
|
+
<View style={styles.reactionWrap}>
|
|
132
132
|
{HeaderView && HeaderView}
|
|
133
|
-
<View style={{ ...style?.containerStyle, padding: 0, paddingHorizontal: 0, paddingVertical: 0, paddingTop: 0, paddingBottom: 0, paddingLeft: 0, paddingRight: 0 }} onLayout={handleLayout}>
|
|
133
|
+
<View style={{ ...style?.containerStyle, overflow: 'hidden', padding: 0, paddingHorizontal: 0, paddingVertical: 0, paddingTop: 0, paddingBottom: 0, paddingLeft: 0, paddingRight: 0 }} onLayout={handleLayout}>
|
|
134
134
|
{ReplyView && ReplyView}
|
|
135
135
|
<View style={{
|
|
136
136
|
padding: style?.containerStyle?.padding,
|
|
@@ -162,3 +162,13 @@ export const CometChatMessageBubble = memo(
|
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
);
|
|
165
|
+
|
|
166
|
+
const styles = StyleSheet.create({
|
|
167
|
+
row: {
|
|
168
|
+
flexDirection: "row",
|
|
169
|
+
},
|
|
170
|
+
reactionWrap: {
|
|
171
|
+
marginStart: 4,
|
|
172
|
+
maxWidth: "80%",
|
|
173
|
+
},
|
|
174
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Animated,
|
|
4
|
+
ScrollView,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
Text,
|
|
7
|
+
TouchableOpacity,
|
|
8
|
+
View,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { useTheme } from '../../../theme';
|
|
11
|
+
import { useCometChatTranslation } from '../../resources/CometChatLocalizeNew';
|
|
12
|
+
|
|
13
|
+
export interface CometChatSmartRepliesProps {
|
|
14
|
+
getSmartReplies: () => Promise<string[]>;
|
|
15
|
+
onSuggestionClicked?: (reply: string) => void;
|
|
16
|
+
closeCallback?: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type State = 'loading' | 'loaded' | 'empty' | 'error';
|
|
20
|
+
|
|
21
|
+
const CometChatSmartReplies: React.FC<CometChatSmartRepliesProps> = ({
|
|
22
|
+
getSmartReplies,
|
|
23
|
+
onSuggestionClicked,
|
|
24
|
+
closeCallback,
|
|
25
|
+
}) => {
|
|
26
|
+
const theme = useTheme();
|
|
27
|
+
const { t } = useCometChatTranslation();
|
|
28
|
+
const [state, setState] = useState<State>('loading');
|
|
29
|
+
const [replies, setReplies] = useState<string[]>([]);
|
|
30
|
+
const shimmer = useRef(new Animated.Value(0.4)).current;
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const loop = Animated.loop(
|
|
34
|
+
Animated.sequence([
|
|
35
|
+
Animated.timing(shimmer, { toValue: 1, duration: 800, useNativeDriver: true }),
|
|
36
|
+
Animated.timing(shimmer, { toValue: 0.4, duration: 800, useNativeDriver: true }),
|
|
37
|
+
])
|
|
38
|
+
);
|
|
39
|
+
loop.start();
|
|
40
|
+
|
|
41
|
+
getSmartReplies()
|
|
42
|
+
.then((res) => {
|
|
43
|
+
if (res && res.length > 0) {
|
|
44
|
+
setReplies(res);
|
|
45
|
+
setState('loaded');
|
|
46
|
+
} else {
|
|
47
|
+
setState('empty');
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.catch(() => setState('error'))
|
|
51
|
+
.finally(() => loop.stop());
|
|
52
|
+
|
|
53
|
+
return () => loop.stop();
|
|
54
|
+
}, []);
|
|
55
|
+
|
|
56
|
+
const s = styles(theme);
|
|
57
|
+
|
|
58
|
+
const renderBody = () => {
|
|
59
|
+
if (state === 'loading') {
|
|
60
|
+
return (
|
|
61
|
+
<ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerStyle={s.scrollContent}>
|
|
62
|
+
{[80, 110, 70].map((w, i) => (
|
|
63
|
+
<Animated.View key={i} style={[s.shimmerChip, { width: w, opacity: shimmer }]} />
|
|
64
|
+
))}
|
|
65
|
+
</ScrollView>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (state === 'error') {
|
|
69
|
+
return <Text style={s.stateText}>{t('ai_smart_replies_error')}</Text>;
|
|
70
|
+
}
|
|
71
|
+
if (state === 'empty') {
|
|
72
|
+
return <Text style={s.stateText}>{t('ai_smart_replies_empty')}</Text>;
|
|
73
|
+
}
|
|
74
|
+
return (
|
|
75
|
+
<ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerStyle={s.scrollContent}>
|
|
76
|
+
{replies.map((reply, i) => (
|
|
77
|
+
<TouchableOpacity
|
|
78
|
+
key={i}
|
|
79
|
+
style={s.chip}
|
|
80
|
+
onPress={() => onSuggestionClicked?.(reply)}
|
|
81
|
+
activeOpacity={0.7}
|
|
82
|
+
accessibilityRole="button"
|
|
83
|
+
accessibilityLabel={reply}
|
|
84
|
+
>
|
|
85
|
+
<Text style={s.chipText}>{reply}</Text>
|
|
86
|
+
</TouchableOpacity>
|
|
87
|
+
))}
|
|
88
|
+
</ScrollView>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<View style={s.wrapper}>
|
|
94
|
+
<View style={s.header}>
|
|
95
|
+
<Text style={s.title}>{t('ai_smart_replies_title')}</Text>
|
|
96
|
+
<TouchableOpacity
|
|
97
|
+
onPress={closeCallback}
|
|
98
|
+
hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
|
|
99
|
+
accessibilityRole="button"
|
|
100
|
+
accessibilityLabel={t('CLOSE')}
|
|
101
|
+
>
|
|
102
|
+
<Text style={s.closeIcon}>✕</Text>
|
|
103
|
+
</TouchableOpacity>
|
|
104
|
+
</View>
|
|
105
|
+
<View style={s.body}>{renderBody()}</View>
|
|
106
|
+
</View>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const styles = (theme: ReturnType<typeof useTheme>) =>
|
|
111
|
+
StyleSheet.create({
|
|
112
|
+
wrapper: {
|
|
113
|
+
backgroundColor: theme.color.background1,
|
|
114
|
+
borderTopWidth: 1,
|
|
115
|
+
borderTopColor: theme.color.borderDefault,
|
|
116
|
+
paddingBottom: 4,
|
|
117
|
+
},
|
|
118
|
+
header: {
|
|
119
|
+
flexDirection: 'row',
|
|
120
|
+
alignItems: 'center',
|
|
121
|
+
justifyContent: 'space-between',
|
|
122
|
+
paddingHorizontal: 16,
|
|
123
|
+
paddingTop: 10,
|
|
124
|
+
paddingBottom: 6,
|
|
125
|
+
},
|
|
126
|
+
title: {
|
|
127
|
+
color: theme.color.textSecondary,
|
|
128
|
+
fontSize: theme.typography.caption1.regular.fontSize,
|
|
129
|
+
fontFamily: theme.typography.caption1.medium?.fontFamily || theme.typography.caption1.regular.fontFamily,
|
|
130
|
+
textTransform: 'uppercase',
|
|
131
|
+
letterSpacing: 0.5,
|
|
132
|
+
},
|
|
133
|
+
closeIcon: {
|
|
134
|
+
color: theme.color.textSecondary,
|
|
135
|
+
fontSize: 14,
|
|
136
|
+
},
|
|
137
|
+
body: {
|
|
138
|
+
paddingBottom: 8,
|
|
139
|
+
},
|
|
140
|
+
scrollContent: {
|
|
141
|
+
paddingHorizontal: 12,
|
|
142
|
+
gap: 8,
|
|
143
|
+
},
|
|
144
|
+
shimmerChip: {
|
|
145
|
+
height: 34,
|
|
146
|
+
borderRadius: 17,
|
|
147
|
+
backgroundColor: theme.color.background4,
|
|
148
|
+
marginRight: 8,
|
|
149
|
+
},
|
|
150
|
+
chip: {
|
|
151
|
+
paddingHorizontal: 16,
|
|
152
|
+
paddingVertical: 8,
|
|
153
|
+
borderRadius: 17,
|
|
154
|
+
borderWidth: 1,
|
|
155
|
+
borderColor: theme.color.borderDefault,
|
|
156
|
+
backgroundColor: theme.color.background2,
|
|
157
|
+
},
|
|
158
|
+
chipText: {
|
|
159
|
+
color: theme.color.textPrimary,
|
|
160
|
+
fontSize: theme.typography.body.regular.fontSize,
|
|
161
|
+
fontFamily: theme.typography.body.regular.fontFamily,
|
|
162
|
+
},
|
|
163
|
+
stateText: {
|
|
164
|
+
color: theme.color.textSecondary,
|
|
165
|
+
fontSize: theme.typography.caption1.regular.fontSize,
|
|
166
|
+
fontFamily: theme.typography.caption1.regular.fontFamily,
|
|
167
|
+
paddingHorizontal: 16,
|
|
168
|
+
paddingVertical: 8,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
export default CometChatSmartReplies;
|