@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.
Files changed (138) hide show
  1. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  2. package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
  3. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  4. package/android/.gradle/7.4/gc.properties +0 -0
  5. package/android/.gradle/vcs-1/gc.properties +0 -0
  6. package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +52 -0
  7. package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
  8. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +95 -8
  9. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +237 -6
  10. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +2 -1
  11. package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +85 -47
  12. package/ios/CometChatClipboardModule.m +11 -0
  13. package/ios/CometChatClipboardModule.swift +41 -0
  14. package/ios/FileManager.m +201 -39
  15. package/ios/RichTextEditorView.swift +312 -4
  16. package/ios/RichTextEditorViewManager.m +1 -0
  17. package/ios/SoundPlayer.m +18 -6
  18. package/package.json +9 -7
  19. package/react-native-cometchat-ui-kit.podspec +1 -0
  20. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +692 -107
  21. package/src/CometChatConversations/CometChatConversations.tsx +19 -6
  22. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +649 -49
  23. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +23 -4
  24. package/src/CometChatMessageList/CometChatMessageList.tsx +463 -54
  25. package/src/CometChatMessageList/MANUAL_TEST_CASES.md +154 -0
  26. package/src/CometChatMessageList/components/MessageListItem.tsx +30 -17
  27. package/src/CometChatMessageList/style.ts +33 -5
  28. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +13 -0
  29. package/src/CometChatRichTextEditor/index.tsx +25 -0
  30. package/src/CometChatSearch/CometChatSearch.tsx +296 -154
  31. package/src/calls/CallingExtension.tsx +19 -13
  32. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +20 -1
  33. package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +20 -9
  34. package/src/index.ts +39 -0
  35. package/src/shared/CometChatUiKit/CometChatUIKit.ts +40 -34
  36. package/src/shared/base/Types.ts +3 -0
  37. package/src/shared/constants/UIKitConstants.ts +15 -1
  38. package/src/shared/framework/DataSource.ts +14 -4
  39. package/src/shared/framework/DataSourceDecorator.tsx +17 -8
  40. package/src/shared/framework/MessageDataSource.tsx +307 -60
  41. package/src/shared/helper/useToast.tsx +29 -0
  42. package/src/shared/icons/components/audio-file-type.tsx +11 -22
  43. package/src/shared/icons/components/document-file-type.tsx +11 -24
  44. package/src/shared/icons/components/image-file-type.tsx +12 -21
  45. package/src/shared/icons/components/link-file-type.tsx +25 -0
  46. package/src/shared/icons/components/pdf-file-type.tsx +11 -22
  47. package/src/shared/icons/components/presentation-file-type.tsx +11 -24
  48. package/src/shared/icons/components/spreadsheet-file-type.tsx +11 -24
  49. package/src/shared/icons/components/text-file-type.tsx +11 -21
  50. package/src/shared/icons/components/unknown-file-type.tsx +21 -25
  51. package/src/shared/icons/components/video-file-type.tsx +11 -24
  52. package/src/shared/icons/components/zip-file-type.tsx +11 -24
  53. package/src/shared/icons/icon-mapping.tsx +2 -0
  54. package/src/shared/index.ts +28 -0
  55. package/src/shared/modals/AttachmentPickerConfiguration.ts +13 -0
  56. package/src/shared/modals/SelectedAttachment.ts +65 -0
  57. package/src/shared/modals/UploadState.ts +10 -0
  58. package/src/shared/modals/index.ts +4 -0
  59. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +42 -1
  60. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +42 -1
  61. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +43 -2
  62. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +43 -2
  63. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +43 -2
  64. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +43 -2
  65. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +43 -2
  66. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +43 -2
  67. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +43 -2
  68. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +43 -2
  69. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +43 -2
  70. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +43 -2
  71. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +43 -2
  72. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +43 -2
  73. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +43 -2
  74. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +43 -2
  75. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +43 -2
  76. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +43 -2
  77. package/src/shared/services/UploadQueueService.ts +145 -0
  78. package/src/shared/services/index.ts +2 -0
  79. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +42 -18
  80. package/src/shared/utils/MessageUtils.tsx +13 -4
  81. package/src/shared/utils/attachmentLimits.ts +156 -0
  82. package/src/shared/utils/audioPlaybackCoordinator.ts +28 -0
  83. package/src/shared/utils/batchMediaContext.tsx +30 -0
  84. package/src/shared/utils/conversationUtils.ts +26 -4
  85. package/src/shared/utils/groupAttachments.ts +93 -0
  86. package/src/shared/utils/index.ts +8 -0
  87. package/src/shared/utils/openMultiFileChooser.ts +123 -0
  88. package/src/shared/utils/partitionAttachmentsByKind.ts +44 -0
  89. package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +28 -0
  90. package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +16 -0
  91. package/src/shared/views/ClipboardPasteHandler/index.ts +2 -0
  92. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +1 -0
  93. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +32 -0
  94. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.tsx +90 -0
  95. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +276 -0
  96. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +827 -0
  97. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTray.tsx +110 -0
  98. package/src/shared/views/CometChatAttachmentPreview/StagedVideoDurationProbe.tsx +53 -0
  99. package/src/shared/views/CometChatAttachmentPreview/index.ts +8 -0
  100. package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +305 -0
  101. package/src/shared/views/CometChatAttachmentViewer/index.ts +2 -0
  102. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +71 -74
  103. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +587 -0
  104. package/src/shared/views/CometChatAudiosBubble/index.ts +2 -0
  105. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +5 -7
  106. package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +182 -0
  107. package/src/shared/views/CometChatCaptionText/index.ts +2 -0
  108. package/src/shared/views/CometChatComposerErrorBanner.tsx +83 -0
  109. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +141 -0
  110. package/src/shared/views/CometChatConversationStarter/index.ts +2 -0
  111. package/src/shared/views/CometChatConversationSummary/CometChatConversationSummary.tsx +155 -0
  112. package/src/shared/views/CometChatConversationSummary/index.ts +2 -0
  113. package/src/shared/views/CometChatFileBubble/style.ts +6 -4
  114. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +316 -0
  115. package/src/shared/views/CometChatFilesBubble/index.ts +2 -0
  116. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +323 -0
  117. package/src/shared/views/CometChatImagesBubble/index.ts +2 -0
  118. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +425 -0
  119. package/src/shared/views/CometChatMediaViewer/index.ts +2 -0
  120. package/src/shared/views/CometChatMediaViewer/mediaViewerUtils.ts +30 -0
  121. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +14 -4
  122. package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +1 -0
  123. package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +172 -0
  124. package/src/shared/views/CometChatSmartReplies/index.ts +2 -0
  125. package/src/shared/views/CometChatVideoBubble/style.ts +3 -3
  126. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +441 -0
  127. package/src/shared/views/CometChatVideosBubble/index.ts +2 -0
  128. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +78 -0
  129. package/src/shared/views/CometChatVoiceNoteBubble/index.ts +2 -0
  130. package/src/shared/views/index.ts +37 -1
  131. package/src/theme/CometChatThemeHelper.ts +8 -0
  132. package/src/theme/default/color/dark.ts +9 -0
  133. package/src/theme/default/color/light.ts +10 -0
  134. package/src/theme/type.ts +73 -0
  135. package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +0 -478
  136. package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +0 -613
  137. package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +0 -76
  138. package/src/shared/CometChatUiKit/checkAuthSettings-review.md +0 -211
@@ -0,0 +1,827 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
+ import {
3
+ Animated,
4
+ Easing,
5
+ Image,
6
+ LayoutChangeEvent,
7
+ NativeModules,
8
+ PanResponder,
9
+ StyleSheet,
10
+ Text,
11
+ TextStyle,
12
+ TouchableOpacity,
13
+ View,
14
+ ViewStyle,
15
+ } from 'react-native';
16
+ import Svg, { Circle } from 'react-native-svg';
17
+ import Video from 'react-native-video';
18
+ import { useTheme } from '../../../theme';
19
+ import { CometChatTheme } from '../../../theme/type';
20
+ import { useCompTheme } from '../../../theme/hook';
21
+ import { deepMerge } from '../../helper/helperFunctions';
22
+ import { SelectedAttachment } from '../../modals/SelectedAttachment';
23
+ import { Icon } from '../../icons/Icon';
24
+ import { getFileTypeIcon } from '../../constants/UIKitConstants';
25
+
26
+ const { SoundPlayer } = NativeModules;
27
+
28
+ // One-audio-at-a-time coordinator (WhatsApp-style): when one card starts playing, every other
29
+ // card resets its UI. The native SoundPlayer already holds a single MediaPlayer, so this only
30
+ // keeps each card's play/pause state in sync with that reality — resetters must NOT call any
31
+ // SoundPlayer method (that would stop the clip that just started).
32
+ const audioPlaySubscribers = new Set<(activeFileId: string) => void>();
33
+ const announceAudioPlay = (activeFileId: string) => {
34
+ audioPlaySubscribers.forEach((fn) => fn(activeFileId));
35
+ };
36
+
37
+ const parseJSON = (s: string): any => { try { return JSON.parse(s); } catch { return {}; } };
38
+ const fmtTime = (secs: number) => {
39
+ const s = Math.max(0, Math.floor(secs || 0));
40
+ return `${String(Math.floor(s / 60)).padStart(2, '0')}:${String(s % 60).padStart(2, '0')}`;
41
+ };
42
+
43
+ // Upload ring for the file-card loading state, with two distinct modes:
44
+ // - QUEUED (indeterminate): a fixed quarter-arc that spins continuously → "waiting to upload".
45
+ // - UPLOADING (determinate): the spin STOPS and the arc grows with the real progress %, starting
46
+ // from the top, so the user can actually read how far along the upload is.
47
+ const UploadRing = ({ progress, indeterminate }: { progress: number; indeterminate: boolean }) => {
48
+ const theme = useTheme();
49
+ const RING_SIZE = theme.spacing.spacing.s7; // 28 (nearest token to 30)
50
+ const RING_STROKE = theme.spacing.spacing.s1; // 4 (nearest token to 3)
51
+ const r = (RING_SIZE - RING_STROKE) / 2;
52
+ const circumference = 2 * Math.PI * r;
53
+ const spin = useRef(new Animated.Value(0)).current;
54
+ useEffect(() => {
55
+ // Only spin while QUEUED. Once uploading starts we show real progress, so the ring must be static.
56
+ if (!indeterminate) {
57
+ spin.setValue(0);
58
+ return;
59
+ }
60
+ const loop = Animated.loop(
61
+ Animated.timing(spin, {
62
+ toValue: 1,
63
+ duration: 900,
64
+ easing: Easing.linear,
65
+ useNativeDriver: true,
66
+ })
67
+ );
68
+ loop.start();
69
+ return () => loop.stop();
70
+ }, [spin, indeterminate]);
71
+ const rotate = spin.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '360deg'] });
72
+ // Queued → a fixed 25% arc (the spin makes it read as a loader). Uploading → the actual progress
73
+ // fraction, held static (the -90° rotation just makes the arc start from 12 o'clock).
74
+ const pct = indeterminate ? 0.25 : Math.min(1, Math.max(0, (progress || 0) / 100));
75
+ return (
76
+ <Animated.View pointerEvents="none" style={{ transform: [{ rotate: indeterminate ? rotate : '-90deg' }] }}>
77
+ <Svg width={RING_SIZE} height={RING_SIZE}>
78
+ <Circle cx={RING_SIZE / 2} cy={RING_SIZE / 2} r={r} stroke={theme.color.staticWhite} strokeOpacity={0.3} strokeWidth={RING_STROKE} fill="none" />
79
+ <Circle
80
+ cx={RING_SIZE / 2}
81
+ cy={RING_SIZE / 2}
82
+ r={r}
83
+ stroke={theme.color.staticWhite}
84
+ strokeWidth={RING_STROKE}
85
+ fill="none"
86
+ strokeLinecap="round"
87
+ strokeDasharray={circumference}
88
+ strokeDashoffset={circumference * (1 - pct)}
89
+ />
90
+ </Svg>
91
+ </Animated.View>
92
+ );
93
+ };
94
+
95
+ export interface CometChatAttachmentTileProps {
96
+ attachment: SelectedAttachment;
97
+ onRemove: (fileId: string) => void;
98
+ onRetry: (fileId: string) => void;
99
+ /** Called when the user taps the tile thumbnail (for image/video preview). */
100
+ onPress?: (fileId: string) => void;
101
+ /**
102
+ * testID forwarded to the tile's outer container (a native View); derived ids:
103
+ * `${testID}.remove`, `${testID}.retry`, `${testID}.uploading` (present only while uploading).
104
+ * A `testID` on a custom component is inert unless forwarded to a native node — so we spread it
105
+ * onto the real View/TouchableOpacity, not the component wrapper.
106
+ */
107
+ testID?: string;
108
+ /**
109
+ * Structured style overrides for the tile's variants (file card / media tile /
110
+ * audio card), deep-merged over the theme's `attachmentTileStyles`.
111
+ */
112
+ style?: CometChatTheme["attachmentTileStyles"];
113
+ }
114
+
115
+ // Non-media file tiles are a wide card (icon + name + type), not a square thumbnail.
116
+ // Figma (Android): width 200, height 72 (spacing.s18), radius 12 (radius.r3), padding 12
117
+ // (padding.p3), gap 8 (spacing.s2) — those four are theme tokens now; only the fixed 200px
118
+ // card width has no matching token, so it lives in styles.fileCard.
119
+ // Media-overlay colors (error dim, video scrim, duration pill) now come from the theme:
120
+ // theme.color.mediaErrorOverlay / mediaScrim / mediaDurationChip. See theme/default/color.
121
+
122
+ // ── Audio attachment player card ────────────────────────────────────────────────
123
+ // Picked/pasted audio (audio/*) renders as a player, not the plain file card: a purple
124
+ // play/pause circle + filename + a draggable seek bar + elapsed/total time, sharing the
125
+ // LOADING (ring) and ERROR (retry/"!" glyph + "Upload failed · Retry") states of the file card.
126
+ // Playback uses the shared native SoundPlayer. ponytail: SoundPlayer holds ONE MediaPlayer, so
127
+ // only one clip plays at a time and the pre-play total-duration shows the last-prepared clip
128
+ // when several audio files are staged together — play(uri) always reloads the correct clip, so
129
+ // playback is per-card correct. Per-card native players only if simultaneous durations matter.
130
+
131
+ const AudioAttachmentCard = ({
132
+ attachment,
133
+ onRemove,
134
+ onRetry,
135
+ onPress,
136
+ containerStyle,
137
+ audioCardStyle,
138
+ fileNameStyle,
139
+ removeButtonStyle,
140
+ }: Omit<CometChatAttachmentTileProps, 'style'> & {
141
+ containerStyle?: ViewStyle;
142
+ audioCardStyle?: ViewStyle;
143
+ fileNameStyle?: TextStyle;
144
+ removeButtonStyle?: ViewStyle;
145
+ }) => {
146
+ const theme = useTheme();
147
+ const { fileId, file, uploadState, uploadProgress } = attachment;
148
+
149
+ const [status, setStatus] = useState<'stopped' | 'playing' | 'paused'>('stopped');
150
+ const [duration, setDuration] = useState(0);
151
+ const [currentTime, setCurrentTime] = useState(0);
152
+ const [seeking, setSeeking] = useState(false);
153
+ const [seekFrac, setSeekFrac] = useState(0);
154
+ const trackWidth = useRef(0);
155
+ const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
156
+
157
+ const loading = uploadState === 'NONE' || uploadState === 'UPLOADING';
158
+ const failed = uploadState === 'FAILED';
159
+ const rejected = uploadState === 'REJECTED';
160
+ const isError = failed || rejected;
161
+ const showRemove = !loading;
162
+
163
+ // PanResponder / interval callbacks capture their first-render closure — read live values
164
+ // (loading/isError/duration) from a ref so seek + end-detection never go stale.
165
+ const liveRef = useRef({ loading, isError, duration, status });
166
+ liveRef.current = { loading, isError, duration, status };
167
+
168
+ const stopPolling = () => {
169
+ if (pollRef.current) {
170
+ clearInterval(pollRef.current);
171
+ pollRef.current = null;
172
+ }
173
+ };
174
+
175
+ const startPolling = () => {
176
+ stopPolling();
177
+ pollRef.current = setInterval(() => {
178
+ SoundPlayer?.getPosition?.((info: string) => {
179
+ const pos = parseJSON(info)?.position ?? 0;
180
+ setCurrentTime(pos);
181
+ const d = liveRef.current.duration;
182
+ if (d > 0 && pos >= d - 0.25) {
183
+ stopPolling();
184
+ setStatus('stopped');
185
+ setCurrentTime(0);
186
+ }
187
+ });
188
+ }, 250);
189
+ };
190
+
191
+ // Duration for the total-time display. Prefer the value the react-native-video probe already read
192
+ // (one independent player per file) — only fall back to the shared SoundPlayer when we don't have
193
+ // it. Prepping every audio tile on the single shared Android player made tap-to-preview flaky.
194
+ useEffect(() => {
195
+ if (attachment.durationSeconds && attachment.durationSeconds > 0) {
196
+ setDuration(attachment.durationSeconds);
197
+ } else {
198
+ SoundPlayer?.prepareMediaPlayer?.(file.uri, (info: string) => {
199
+ const d = parseJSON(info)?.duration;
200
+ if (typeof d === 'number' && d > 0) setDuration(d);
201
+ });
202
+ }
203
+ return () => {
204
+ stopPolling();
205
+ // Only release the SHARED player if THIS tile was the one using it — releasing on every tile's
206
+ // unmount thrashes the single Android player (still stops OUR playback on unmount).
207
+ if (liveRef.current.status === 'playing' || liveRef.current.status === 'paused') {
208
+ SoundPlayer?.releaseMediaPlayer?.();
209
+ }
210
+ };
211
+ }, [file.uri, attachment.durationSeconds]);
212
+
213
+ // When ANOTHER card starts playing, reset this one's UI (do not touch SoundPlayer — the
214
+ // native player is already playing the other clip).
215
+ useEffect(() => {
216
+ const onOtherPlay = (activeFileId: string) => {
217
+ if (activeFileId !== fileId) {
218
+ stopPolling();
219
+ setStatus('stopped');
220
+ setCurrentTime(0);
221
+ }
222
+ };
223
+ audioPlaySubscribers.add(onOtherPlay);
224
+ return () => {
225
+ audioPlaySubscribers.delete(onOtherPlay);
226
+ };
227
+ }, [fileId]);
228
+
229
+ const onToggle = () => {
230
+ if (loading || isError) return;
231
+ if (status === 'playing') {
232
+ SoundPlayer?.pause?.(() => {});
233
+ stopPolling();
234
+ setStatus('paused');
235
+ } else if (status === 'paused') {
236
+ announceAudioPlay(fileId); // resuming stops any other card that's playing
237
+ SoundPlayer?.resume?.();
238
+ setStatus('playing');
239
+ startPolling();
240
+ } else {
241
+ announceAudioPlay(fileId); // starting stops any other card that's playing
242
+ SoundPlayer?.play?.(file.uri, (info: string) => {
243
+ const d = parseJSON(info)?.duration;
244
+ if (typeof d === 'number' && d > 0) setDuration(d);
245
+ });
246
+ setStatus('playing');
247
+ setCurrentTime(0);
248
+ startPolling();
249
+ }
250
+ };
251
+
252
+ const seekTo = (frac: number) => {
253
+ const clamped = Math.min(1, Math.max(0, frac));
254
+ const secs = Math.round(clamped * liveRef.current.duration);
255
+ SoundPlayer?.playAt?.(secs, () => {});
256
+ setCurrentTime(secs);
257
+ };
258
+
259
+ const pan = useRef(
260
+ PanResponder.create({
261
+ onStartShouldSetPanResponder: () =>
262
+ !liveRef.current.loading && !liveRef.current.isError && liveRef.current.duration > 0,
263
+ onMoveShouldSetPanResponder: () =>
264
+ !liveRef.current.loading && !liveRef.current.isError && liveRef.current.duration > 0,
265
+ onPanResponderGrant: (e) => {
266
+ setSeeking(true);
267
+ const w = trackWidth.current || 1;
268
+ setSeekFrac(Math.min(1, Math.max(0, e.nativeEvent.locationX / w)));
269
+ },
270
+ onPanResponderMove: (e) => {
271
+ const w = trackWidth.current || 1;
272
+ setSeekFrac(Math.min(1, Math.max(0, e.nativeEvent.locationX / w)));
273
+ },
274
+ onPanResponderRelease: (e) => {
275
+ const w = trackWidth.current || 1;
276
+ seekTo(e.nativeEvent.locationX / w);
277
+ setSeeking(false);
278
+ },
279
+ })
280
+ ).current;
281
+
282
+ // Clamp the displayed time to the duration — a mis-read clip (e.g. an .aac whose duration reads
283
+ // short) can make playback overshoot, and the time must never read past the total (00:03/00:01).
284
+ const rawTime = seeking ? seekFrac * duration : currentTime;
285
+ const dispTime = duration > 0 ? Math.min(rawTime, duration) : rawTime;
286
+ const frac = duration > 0 ? Math.min(1, Math.max(0, dispTime / duration)) : 0;
287
+ const fillPct = `${frac * 100}%` as const;
288
+ const S = theme.spacing.spacing;
289
+ const CIRCLE = S.s14; // 56 — same play circle as the sent audio bubble (CometChatAudiosBubble)
290
+ const TRACK_H = S.s1; // 4 — thin seek track
291
+ const THUMB = S.s3; // 12 — seek thumb
292
+
293
+ // Rejected → the whole card taps to reveal the failure reason (mirrors the file/media cards).
294
+ const AudioCardContainer: any = rejected && onPress ? TouchableOpacity : View;
295
+ const audioCardPressProps = rejected && onPress ? { activeOpacity: 0.7, onPress: () => onPress(fileId) } : {};
296
+
297
+ return (
298
+ <View style={[{ margin: theme.spacing.margin.m1 }, containerStyle]}>
299
+ <AudioCardContainer
300
+ {...audioCardPressProps}
301
+ style={[styles.audioCard, {
302
+ flexDirection: 'row',
303
+ alignItems: 'center',
304
+ gap: S.s3,
305
+ // Name · seek · time packed in a column BESIDE the circle (like the sent audio bubble) so
306
+ // the card stays compact instead of stacking three tall rows. padding.p3 = even spacing.
307
+ minHeight: theme.spacing.spacing.s18,
308
+ borderRadius: theme.spacing.radius.r3,
309
+ padding: theme.spacing.padding.p3,
310
+ backgroundColor: theme.color.background2,
311
+ borderWidth: 1,
312
+ borderColor: isError ? theme.color.error : theme.color.borderDefault,
313
+ }, audioCardStyle]}
314
+ >
315
+ {/* Purple play/pause circle; LOADING dims it + spins the ring, ERROR shows the glyph. */}
316
+ <TouchableOpacity
317
+ activeOpacity={loading || isError ? 1 : 0.8}
318
+ onPress={onToggle}
319
+ style={{
320
+ width: CIRCLE,
321
+ height: CIRCLE,
322
+ borderRadius: CIRCLE / 2,
323
+ overflow: 'hidden',
324
+ backgroundColor: theme.color.primary,
325
+ justifyContent: 'center',
326
+ alignItems: 'center',
327
+ }}
328
+ accessibilityRole="button"
329
+ accessibilityLabel={status === 'playing' ? 'Pause audio' : 'Play audio'}
330
+ >
331
+ <Icon
332
+ name={status === 'playing' ? 'pause-fill' : 'play-arrow-fill'}
333
+ size={S.s6}
334
+ color={theme.color.staticWhite}
335
+ />
336
+ {loading && (
337
+ <View
338
+ pointerEvents="none"
339
+ style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: theme.color.mediaErrorOverlay, justifyContent: 'center', alignItems: 'center' }}
340
+ >
341
+ <UploadRing progress={uploadProgress} indeterminate={uploadState === 'NONE'} />
342
+ </View>
343
+ )}
344
+ {isError && (
345
+ // Design: keep the play circle, dim it with a dark tint, then center a SMALL red badge with a
346
+ // white glyph (retry / "!") on top — NOT a full red fill. Mirrors the media tile's error badge.
347
+ <View
348
+ pointerEvents="none"
349
+ style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: theme.color.mediaErrorOverlay, justifyContent: 'center', alignItems: 'center' }}
350
+ >
351
+ <View style={{ width: S.s7, height: S.s7, borderRadius: S.s7 / 2, backgroundColor: theme.color.error, justifyContent: 'center', alignItems: 'center' }}>
352
+ <Icon name={failed ? 'retry' : 'error-fill'} size={failed ? S.s4 : S.s7} color={failed ? theme.color.staticWhite : theme.color.error} />
353
+ </View>
354
+ </View>
355
+ )}
356
+ </TouchableOpacity>
357
+
358
+ {/* Filename · seek bar · elapsed/total — stacked in a column beside the circle (▶ ──●──). */}
359
+ <View style={{ flex: 1 }}>
360
+ <Text
361
+ numberOfLines={1}
362
+ ellipsizeMode="middle"
363
+ style={[{ ...theme.typography.body.medium, color: theme.color.neutral900, marginRight: theme.spacing.margin.m4 }, fileNameStyle]}
364
+ >
365
+ {file.name}
366
+ </Text>
367
+ {isError ? (
368
+ failed ? (
369
+ // FAILED (transient) — whole label taps to re-upload.
370
+ <Text
371
+ onPress={() => onRetry(fileId)}
372
+ suppressHighlighting
373
+ style={{ ...theme.typography.caption2.medium, color: theme.color.error, marginTop: S.s0_5 }}
374
+ >
375
+ {'Tap to retry'}
376
+ </Text>
377
+ ) : (
378
+ // REJECTED (server denied) — remove-only, no retry.
379
+ <Text style={{ ...theme.typography.caption2.regular, color: theme.color.error, marginTop: S.s0_5 }}>
380
+ {'Upload failed'}
381
+ </Text>
382
+ )
383
+ ) : (
384
+ <>
385
+ {/* Draggable seek bar: thin track + purple fill + thumb. */}
386
+ <View
387
+ {...pan.panHandlers}
388
+ onLayout={(e: LayoutChangeEvent) => {
389
+ trackWidth.current = e.nativeEvent.layout.width;
390
+ }}
391
+ style={{ height: S.s6, justifyContent: 'center', marginTop: S.s0_5 }}
392
+ >
393
+ <View style={{ height: TRACK_H, borderRadius: TRACK_H / 2, backgroundColor: theme.color.neutral300 }}>
394
+ <View style={{ position: 'absolute', left: 0, top: 0, bottom: 0, width: fillPct, borderRadius: TRACK_H / 2, backgroundColor: theme.color.primary }} />
395
+ </View>
396
+ <View
397
+ style={{
398
+ position: 'absolute',
399
+ // Clamp the thumb fully inside the track [0, trackWidth - THUMB] so it never
400
+ // spills past either end (the fill is a %, the thumb needs pixel clamping).
401
+ left: Math.max(0, Math.min(frac * trackWidth.current - THUMB / 2, trackWidth.current - THUMB)),
402
+ width: THUMB,
403
+ height: THUMB,
404
+ borderRadius: THUMB / 2,
405
+ backgroundColor: theme.color.staticWhite,
406
+ borderWidth: 1,
407
+ borderColor: theme.color.neutral300,
408
+ }}
409
+ />
410
+ </View>
411
+ <Text style={{ ...theme.typography.caption1.regular, color: theme.color.neutral600, marginTop: S.s0_5 }}>
412
+ {`${fmtTime(dispTime)}/${fmtTime(duration)}`}
413
+ </Text>
414
+ </>
415
+ )}
416
+ </View>
417
+ </AudioCardContainer>
418
+
419
+ {showRemove && (
420
+ <TouchableOpacity
421
+ onPress={() => onRemove(fileId)}
422
+ hitSlop={{ top: theme.spacing.spacing.s2, right: theme.spacing.spacing.s2, bottom: theme.spacing.spacing.s2, left: theme.spacing.spacing.s2 }}
423
+ style={[{
424
+ position: 'absolute',
425
+ top: -theme.spacing.spacing.s2,
426
+ right: -theme.spacing.spacing.s2,
427
+ width: theme.spacing.spacing.s6,
428
+ height: theme.spacing.spacing.s6,
429
+ borderRadius: theme.spacing.radius.r3,
430
+ backgroundColor: theme.color.neutral700,
431
+ borderWidth: 2,
432
+ borderColor: theme.color.background1,
433
+ justifyContent: 'center',
434
+ alignItems: 'center',
435
+ }, removeButtonStyle]}
436
+ accessibilityRole="button"
437
+ accessibilityLabel="Remove attachment"
438
+ >
439
+ <Text style={{ ...theme.typography.caption2.regular, color: theme.color.staticWhite }}>{'✕'}</Text>
440
+ </TouchableOpacity>
441
+ )}
442
+ </View>
443
+ );
444
+ };
445
+
446
+ export const CometChatAttachmentTile = ({
447
+ attachment,
448
+ onRemove,
449
+ onRetry,
450
+ onPress,
451
+ style,
452
+ testID,
453
+ }: CometChatAttachmentTileProps) => {
454
+ const theme = useTheme();
455
+ const compTheme = useCompTheme();
456
+ const s = deepMerge(
457
+ theme.attachmentTileStyles ?? {},
458
+ compTheme.attachmentTileStyles ?? {},
459
+ style ?? {}
460
+ );
461
+ const { fileId, file, uploadState, uploadProgress } = attachment;
462
+
463
+ // Audio (audio/*) renders as a player card (play/pause + seek + time), not the file card.
464
+ if (file.type.startsWith('audio/')) {
465
+ return (
466
+ <AudioAttachmentCard
467
+ attachment={attachment}
468
+ onRemove={onRemove}
469
+ onRetry={onRetry}
470
+ onPress={onPress}
471
+ containerStyle={s.containerStyle}
472
+ audioCardStyle={s.audioCardStyle}
473
+ fileNameStyle={s.fileNameStyle}
474
+ removeButtonStyle={s.removeButtonStyle}
475
+ />
476
+ );
477
+ }
478
+
479
+ const isMedia =
480
+ file.type.startsWith('image/') || file.type.startsWith('video/');
481
+ // Tap opens the full-screen viewer ONLY once the media is fully uploaded (COMPLETED) — the tile
482
+ // is not tappable while it is still uploading / queued / errored.
483
+ const canPreview = isMedia && uploadState === 'COMPLETED';
484
+
485
+ // Non-media files (PDF / MP3 / docs) render as a WIDE card — colored file-type icon +
486
+ // name + type label — and stay clean: no exclamation / error overlay. Photos & videos
487
+ // keep the square thumbnail tile below. (Failed uploads: subtle red border + tap to retry.)
488
+ if (!isMedia) {
489
+ const ext = (file.name.split('.').pop() || '').toUpperCase();
490
+ const loading = uploadState === 'NONE' || uploadState === 'UPLOADING';
491
+ const failed = uploadState === 'FAILED'; // transient (onFailure) → Retry offered
492
+ const rejected = uploadState === 'REJECTED'; // server denied (onError) → remove-only, no Retry
493
+ const isError = failed || rejected;
494
+ const showRemove = !loading; // ✕ hidden while uploading; shown on DEFAULT + ERROR
495
+ // Only a REJECTED card is tappable (tap → failure-reason toast); keep it a plain View otherwise so
496
+ // the FAILED card's inner "Tap to retry" text keeps its own touch handling.
497
+ const FileCardContainer: any = rejected && onPress ? TouchableOpacity : View;
498
+ const fileCardPressProps = rejected && onPress ? { activeOpacity: 0.7, onPress: () => onPress(fileId) } : {};
499
+ return (
500
+ // Wrapper is `relative` (not clipped) so the ✕ badge can sit on the card's corner.
501
+ <View style={[{ margin: theme.spacing.margin.m1 }, s.containerStyle]}>
502
+ <FileCardContainer
503
+ accessibilityLabel={file.name}
504
+ {...fileCardPressProps}
505
+ style={[styles.fileCard, {
506
+ flexDirection: 'row',
507
+ alignItems: 'center',
508
+ gap: theme.spacing.spacing.s2,
509
+ height: theme.spacing.spacing.s18,
510
+ borderRadius: theme.spacing.radius.r3,
511
+ padding: theme.spacing.padding.p3,
512
+ // Figma tokens: Background02 (#FAFAFA) + 1px BorderDefault (#E9EAEB) define the card
513
+ // (flat, no shadow); the border turns red in the ERROR state.
514
+ backgroundColor: theme.color.background2,
515
+ borderWidth: 1,
516
+ borderColor: isError ? theme.color.error : theme.color.borderDefault,
517
+ }, s.fileCardStyle]}
518
+ >
519
+ {/* 48px colored file-type icon. LOADING dims it + spins the upload ring on top. */}
520
+ <View
521
+ style={{
522
+ width: theme.spacing.spacing.s12,
523
+ height: theme.spacing.spacing.s12,
524
+ borderRadius: theme.spacing.radius.r2,
525
+ overflow: 'hidden',
526
+ justifyContent: 'center',
527
+ alignItems: 'center',
528
+ }}
529
+ >
530
+ {isError ? (
531
+ // Error/retry (matches design, image 1): red document + the SAME dark backdrop tint
532
+ // (theme.color.mediaErrorOverlay) as the image/video/audio error tiles, with the status badge on top.
533
+ // FAILED (retryable) → white reload; REJECTED (denied) → white "!".
534
+ <>
535
+ <Icon name="description-fill" size={theme.spacing.spacing.s12} color={theme.color.error} />
536
+ <View
537
+ pointerEvents="none"
538
+ style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: theme.color.mediaErrorOverlay, justifyContent: 'center', alignItems: 'center' }}
539
+ >
540
+ <View
541
+ style={{
542
+ width: theme.spacing.spacing.s6,
543
+ height: theme.spacing.spacing.s6,
544
+ borderRadius: theme.spacing.radius.r3,
545
+ backgroundColor: theme.color.error,
546
+ borderWidth: 2,
547
+ borderColor: theme.color.staticWhite,
548
+ justifyContent: 'center',
549
+ alignItems: 'center',
550
+ }}
551
+ >
552
+ <Icon name={failed ? 'retry' : 'error-fill'} size={failed ? theme.spacing.spacing.s3 : theme.spacing.spacing.s6} color={failed ? theme.color.staticWhite : theme.color.error} />
553
+ {/* REJECTED → the SAME `error-fill` SVG the message-list error/retry receipt uses
554
+ (CometChatReceipt), so the tray error "!" matches the failed-message "!". */}
555
+ </View>
556
+ </View>
557
+ </>
558
+ ) : (
559
+ <>
560
+ <Icon name={getFileTypeIcon(file.name)} size={theme.spacing.spacing.s12} />
561
+ {loading && (
562
+ <View
563
+ pointerEvents="none"
564
+ style={{
565
+ position: 'absolute',
566
+ top: 0,
567
+ left: 0,
568
+ right: 0,
569
+ bottom: 0,
570
+ backgroundColor: theme.color.mediaErrorOverlay,
571
+ justifyContent: 'center',
572
+ alignItems: 'center',
573
+ }}
574
+ >
575
+ <UploadRing progress={uploadProgress} indeterminate={uploadState === 'NONE'} />
576
+ </View>
577
+ )}
578
+ </>
579
+ )}
580
+ </View>
581
+
582
+ <View style={{ flex: 1, marginRight: theme.spacing.margin.m3 }}>
583
+ <Text
584
+ numberOfLines={1}
585
+ ellipsizeMode="middle"
586
+ style={[{ ...theme.typography.body.medium, color: theme.color.neutral900 }, s.fileNameStyle]}
587
+ >
588
+ {file.name}
589
+ </Text>
590
+ {isError ? (
591
+ failed ? (
592
+ // FAILED (transient) — whole label taps to re-upload.
593
+ <Text
594
+ onPress={() => onRetry(fileId)}
595
+ suppressHighlighting
596
+ style={{ ...theme.typography.caption2.medium, color: theme.color.error, marginTop: theme.spacing.margin.m0_5 }}
597
+ >
598
+ {'Tap to retry'}
599
+ </Text>
600
+ ) : (
601
+ // REJECTED (server denied) — remove-only, no retry.
602
+ <Text style={{ ...theme.typography.caption2.regular, color: theme.color.error, marginTop: theme.spacing.margin.m0_5 }}>
603
+ {'Upload failed'}
604
+ </Text>
605
+ )
606
+ ) : (
607
+ Boolean(ext) && (
608
+ <Text style={{ ...theme.typography.caption2.regular, color: theme.color.neutral600, marginTop: theme.spacing.margin.m0_5 }}>
609
+ {ext}
610
+ </Text>
611
+ )
612
+ )}
613
+ </View>
614
+ </FileCardContainer>
615
+
616
+ {/* Remove (✕) — corner badge, DEFAULT + ERROR only (hidden while uploading). */}
617
+ {showRemove && (
618
+ <TouchableOpacity
619
+ onPress={() => onRemove(fileId)}
620
+ hitSlop={{ top: theme.spacing.spacing.s2, right: theme.spacing.spacing.s2, bottom: theme.spacing.spacing.s2, left: theme.spacing.spacing.s2 }}
621
+ style={[{
622
+ position: 'absolute',
623
+ top: -theme.spacing.spacing.s2,
624
+ right: -theme.spacing.spacing.s2,
625
+ width: theme.spacing.spacing.s6,
626
+ height: theme.spacing.spacing.s6,
627
+ borderRadius: theme.spacing.radius.r3,
628
+ backgroundColor: theme.color.neutral700,
629
+ borderWidth: 2,
630
+ borderColor: theme.color.background1,
631
+ justifyContent: 'center',
632
+ alignItems: 'center',
633
+ }, s.removeButtonStyle]}
634
+ accessibilityRole="button"
635
+ accessibilityLabel="Remove attachment"
636
+ >
637
+ <Text style={{ ...theme.typography.caption2.regular, color: theme.color.staticWhite }}>{'✕'}</Text>
638
+ </TouchableOpacity>
639
+ )}
640
+ </View>
641
+ );
642
+ }
643
+
644
+ // Media (image/video) square tile states — mirror the file/audio cards:
645
+ // DEFAULT → clean thumbnail + ✕ corner badge
646
+ // LOADING → dimmed + white upload ring (NONE/UPLOADING), ✕ hidden
647
+ // RETRY → FAILED (transient): red border + red retry circle (tap to re-upload)
648
+ // ERROR → REJECTED (denied): red border + red "!" circle, remove-only
649
+ const loading = uploadState === 'NONE' || uploadState === 'UPLOADING';
650
+ const failed = uploadState === 'FAILED';
651
+ const rejected = uploadState === 'REJECTED';
652
+ const isError = failed || rejected;
653
+ const showRemove = !loading;
654
+
655
+ return (
656
+ // Wrapper is relative (not clipped) so the ✕ badge can sit on the tile's corner.
657
+ <View testID={testID} style={[{ margin: theme.spacing.margin.m1 }, s.containerStyle]}>
658
+ <TouchableOpacity
659
+ testID={testID ? `${testID}.thumb` : undefined}
660
+ // Tappable when previewable (completed media) OR rejected (tap reveals the failure reason).
661
+ activeOpacity={(canPreview || rejected) && onPress ? 0.85 : 1}
662
+ onPress={(canPreview || rejected) && onPress ? () => onPress(fileId) : undefined}
663
+ style={[{
664
+ width: theme.spacing.spacing.s18,
665
+ height: theme.spacing.spacing.s18,
666
+ borderRadius: theme.spacing.radius.r2,
667
+ overflow: 'hidden',
668
+ backgroundColor: theme.color.neutral200,
669
+ borderWidth: isError ? 1.5 : 0,
670
+ borderColor: theme.color.error,
671
+ }, s.mediaTileStyle]}
672
+ >
673
+ {file.type.startsWith('video/') ? (
674
+ // A local video file can't render as an <Image>, so show its FIRST FRAME via a paused,
675
+ // muted react-native-video (no controls, never plays) as the thumbnail. The dark scrim
676
+ // sits behind it so the tile reads as a video before the frame decodes.
677
+ <>
678
+ <View
679
+ pointerEvents="none"
680
+ style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: theme.color.mediaScrim }}
681
+ />
682
+ <Video
683
+ source={{ uri: file.uri }}
684
+ paused
685
+ muted
686
+ repeat={false}
687
+ controls={false}
688
+ resizeMode="cover"
689
+ style={styles.fill}
690
+ />
691
+ </>
692
+ ) : (
693
+ <Image
694
+ source={{ uri: file.uri }}
695
+ style={styles.fill}
696
+ resizeMode="cover"
697
+ />
698
+ )}
699
+
700
+ {/* Video play glyph — hidden while loading / in error. */}
701
+ {file.type.startsWith('video/') && !loading && !isError && (
702
+ <View
703
+ pointerEvents="none"
704
+ style={styles.fillCenter}
705
+ >
706
+ <Icon name="play-arrow-fill" size={theme.spacing.spacing.s6} color={theme.color.staticWhite} />
707
+ </View>
708
+ )}
709
+
710
+ {/* Duration chip — video, once uploaded, with a known duration (bottom-start pill; same
711
+ look as the sent-message grid bubble). m:ss format. */}
712
+ {file.type.startsWith('video/') && uploadState === 'COMPLETED' &&
713
+ !!attachment.durationSeconds && attachment.durationSeconds > 0 && (
714
+ <View
715
+ pointerEvents="none"
716
+ style={[{
717
+ position: 'absolute',
718
+ bottom: theme.spacing.spacing.s1,
719
+ left: theme.spacing.spacing.s1,
720
+ backgroundColor: theme.color.mediaDurationChip,
721
+ borderRadius: theme.spacing.radius.r1,
722
+ paddingHorizontal: theme.spacing.padding.p1,
723
+ paddingVertical: theme.spacing.padding.p0_5,
724
+ }, s.durationChipStyle]}
725
+ >
726
+ <Text style={{ color: theme.color.staticWhite, fontSize: 11, fontWeight: '600' }}>
727
+ {`${Math.floor(attachment.durationSeconds / 60)}:${String(
728
+ Math.floor(attachment.durationSeconds % 60)
729
+ ).padStart(2, '0')}`}
730
+ </Text>
731
+ </View>
732
+ )}
733
+
734
+ {/* LOADING — dim + white upload ring. */}
735
+ {loading && (
736
+ <View
737
+ testID={testID ? `${testID}.uploading` : undefined}
738
+ pointerEvents="none"
739
+ style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: theme.color.mediaErrorOverlay, justifyContent: 'center', alignItems: 'center' }}
740
+ >
741
+ <UploadRing progress={uploadProgress} indeterminate={uploadState === 'NONE'} />
742
+ </View>
743
+ )}
744
+
745
+ {/* RETRY — FAILED (transient): tap the red retry circle to re-upload. */}
746
+ {failed && (
747
+ <TouchableOpacity
748
+ testID={testID ? `${testID}.retry` : undefined}
749
+ onPress={() => onRetry(fileId)}
750
+ activeOpacity={0.8}
751
+ style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: theme.color.mediaErrorOverlay, justifyContent: 'center', alignItems: 'center' }}
752
+ accessibilityRole="button"
753
+ accessibilityLabel="Retry upload"
754
+ >
755
+ <View style={{ width: theme.spacing.spacing.s9, height: theme.spacing.spacing.s9, borderRadius: theme.spacing.radius.r5, backgroundColor: theme.color.error, justifyContent: 'center', alignItems: 'center' }}>
756
+ <Icon name="retry" size={theme.spacing.spacing.s5} color={theme.color.staticWhite} />
757
+ </View>
758
+ </TouchableOpacity>
759
+ )}
760
+
761
+ {/* ERROR — REJECTED (denied): red "!" circle, remove-only. */}
762
+ {rejected && (
763
+ <View
764
+ pointerEvents="none"
765
+ style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: theme.color.mediaErrorOverlay, justifyContent: 'center', alignItems: 'center' }}
766
+ >
767
+ <View style={{ width: theme.spacing.spacing.s9, height: theme.spacing.spacing.s9, borderRadius: theme.spacing.radius.r5, backgroundColor: theme.color.error, justifyContent: 'center', alignItems: 'center' }}>
768
+ <Icon name="error-fill" size={theme.spacing.spacing.s9} color={theme.color.error} />
769
+ </View>
770
+ </View>
771
+ )}
772
+ </TouchableOpacity>
773
+
774
+ {/* Remove ✕ — corner badge; DEFAULT + ERROR/RETRY (hidden while uploading). */}
775
+ {showRemove && (
776
+ <TouchableOpacity
777
+ testID={testID ? `${testID}.remove` : undefined}
778
+ onPress={() => onRemove(fileId)}
779
+ hitSlop={{ top: theme.spacing.spacing.s2, right: theme.spacing.spacing.s2, bottom: theme.spacing.spacing.s2, left: theme.spacing.spacing.s2 }}
780
+ style={[{
781
+ position: 'absolute',
782
+ top: -theme.spacing.spacing.s2,
783
+ right: -theme.spacing.spacing.s2,
784
+ width: theme.spacing.spacing.s6,
785
+ height: theme.spacing.spacing.s6,
786
+ borderRadius: theme.spacing.radius.r3,
787
+ backgroundColor: theme.color.neutral700,
788
+ borderWidth: 2,
789
+ borderColor: theme.color.background1,
790
+ justifyContent: 'center',
791
+ alignItems: 'center',
792
+ }, s.removeButtonStyle]}
793
+ accessibilityRole="button"
794
+ accessibilityLabel="Remove attachment"
795
+ >
796
+ <Text style={{ ...theme.typography.caption2.regular, color: theme.color.staticWhite }}>{'✕'}</Text>
797
+ </TouchableOpacity>
798
+ )}
799
+ </View>
800
+ );
801
+ };
802
+
803
+ // Backward-compat alias
804
+ export const CometChatAttachmentPreviewItem = CometChatAttachmentTile;
805
+ export type CometChatAttachmentPreviewItemProps = CometChatAttachmentTileProps;
806
+
807
+ const styles = StyleSheet.create({
808
+ fillCenter: {
809
+ position: 'absolute',
810
+ top: 0,
811
+ left: 0,
812
+ right: 0,
813
+ bottom: 0,
814
+ justifyContent: 'center',
815
+ alignItems: 'center',
816
+ },
817
+ fill: {
818
+ width: '100%',
819
+ height: '100%',
820
+ },
821
+ fileCard: {
822
+ width: 200,
823
+ },
824
+ audioCard: {
825
+ width: 260,
826
+ },
827
+ });