@developer_tribe/react-native-comnyx 0.13.13 → 0.15.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 (132) hide show
  1. package/android/generated/RCTAppDependencyProvider.h +25 -0
  2. package/android/generated/RCTAppDependencyProvider.mm +55 -0
  3. package/android/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
  4. package/android/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
  5. package/android/generated/RCTThirdPartyComponentsProvider.h +16 -0
  6. package/android/generated/RCTThirdPartyComponentsProvider.mm +23 -0
  7. package/android/generated/ReactAppDependencyProvider.podspec +34 -0
  8. package/android/generated/jni/CMakeLists.txt +36 -0
  9. package/android/generated/jni/RNComnyxSpec-generated.cpp +22 -0
  10. package/android/generated/jni/RNComnyxSpec.h +24 -0
  11. package/android/generated/jni/react/renderer/components/RNComnyxSpec/RNComnyxSpecJSI-generated.cpp +17 -0
  12. package/android/generated/jni/react/renderer/components/RNComnyxSpec/RNComnyxSpecJSI.h +19 -0
  13. package/android/src/main/AndroidManifest.xml +15 -0
  14. package/android/src/main/AndroidManifestNew.xml +4 -0
  15. package/android/src/main/java/com/comnyx/ComnyxMediaPickerModule.kt +347 -0
  16. package/android/src/main/java/com/comnyx/ComnyxPackage.kt +1 -1
  17. package/android/src/main/java/com/comnyx/VideoPlayerActivity.kt +91 -0
  18. package/ios/ComnyxMediaPicker.m +29 -0
  19. package/ios/ComnyxMediaPicker.swift +436 -0
  20. package/lib/commonjs/NativeComnyxMediaPicker.js +83 -0
  21. package/lib/commonjs/NativeComnyxMediaPicker.js.map +1 -0
  22. package/lib/commonjs/api/index.js +19 -0
  23. package/lib/commonjs/api/index.js.map +1 -1
  24. package/lib/commonjs/api/media.js +76 -0
  25. package/lib/commonjs/api/media.js.map +1 -0
  26. package/lib/commonjs/assets/attachment-01.png +0 -0
  27. package/lib/commonjs/assets/gallery.png +0 -0
  28. package/lib/commonjs/assets/video-play.png +0 -0
  29. package/lib/commonjs/assets/x-circle.png +0 -0
  30. package/lib/commonjs/components/ChatList.js +48 -22
  31. package/lib/commonjs/components/ChatList.js.map +1 -1
  32. package/lib/commonjs/components/LinkifyText.js +5 -1
  33. package/lib/commonjs/components/LinkifyText.js.map +1 -1
  34. package/lib/commonjs/components/MediaMessageItem.js +333 -0
  35. package/lib/commonjs/components/MediaMessageItem.js.map +1 -0
  36. package/lib/commonjs/components/MediaPickerButton.js +244 -0
  37. package/lib/commonjs/components/MediaPickerButton.js.map +1 -0
  38. package/lib/commonjs/components/MediaViewerModal.js +164 -0
  39. package/lib/commonjs/components/MediaViewerModal.js.map +1 -0
  40. package/lib/commonjs/components/MessageInput.js +344 -73
  41. package/lib/commonjs/components/MessageInput.js.map +1 -1
  42. package/lib/commonjs/components/MessageItem.js +17 -8
  43. package/lib/commonjs/components/MessageItem.js.map +1 -1
  44. package/lib/commonjs/constants/translations.js +174 -29
  45. package/lib/commonjs/constants/translations.js.map +1 -1
  46. package/lib/commonjs/data/fake/media.js +105 -0
  47. package/lib/commonjs/data/fake/media.js.map +1 -0
  48. package/lib/commonjs/types/MediaTypes.js +2 -0
  49. package/lib/commonjs/types/MediaTypes.js.map +1 -0
  50. package/lib/commonjs/version.js +1 -1
  51. package/lib/commonjs/version.js.map +1 -1
  52. package/lib/module/NativeComnyxMediaPicker.js +73 -0
  53. package/lib/module/NativeComnyxMediaPicker.js.map +1 -0
  54. package/lib/module/api/index.js +1 -0
  55. package/lib/module/api/index.js.map +1 -1
  56. package/lib/module/api/media.js +70 -0
  57. package/lib/module/api/media.js.map +1 -0
  58. package/lib/module/assets/attachment-01.png +0 -0
  59. package/lib/module/assets/gallery.png +0 -0
  60. package/lib/module/assets/video-play.png +0 -0
  61. package/lib/module/assets/x-circle.png +0 -0
  62. package/lib/module/components/ChatList.js +48 -22
  63. package/lib/module/components/ChatList.js.map +1 -1
  64. package/lib/module/components/LinkifyText.js +5 -1
  65. package/lib/module/components/LinkifyText.js.map +1 -1
  66. package/lib/module/components/MediaMessageItem.js +330 -0
  67. package/lib/module/components/MediaMessageItem.js.map +1 -0
  68. package/lib/module/components/MediaPickerButton.js +240 -0
  69. package/lib/module/components/MediaPickerButton.js.map +1 -0
  70. package/lib/module/components/MediaViewerModal.js +160 -0
  71. package/lib/module/components/MediaViewerModal.js.map +1 -0
  72. package/lib/module/components/MessageInput.js +347 -75
  73. package/lib/module/components/MessageInput.js.map +1 -1
  74. package/lib/module/components/MessageItem.js +17 -8
  75. package/lib/module/components/MessageItem.js.map +1 -1
  76. package/lib/module/constants/translations.js +174 -29
  77. package/lib/module/constants/translations.js.map +1 -1
  78. package/lib/module/data/fake/media.js +99 -0
  79. package/lib/module/data/fake/media.js.map +1 -0
  80. package/lib/module/types/MediaTypes.js +2 -0
  81. package/lib/module/types/MediaTypes.js.map +1 -0
  82. package/lib/module/version.js +1 -1
  83. package/lib/module/version.js.map +1 -1
  84. package/lib/typescript/src/NativeComnyxMediaPicker.d.ts +9 -0
  85. package/lib/typescript/src/NativeComnyxMediaPicker.d.ts.map +1 -0
  86. package/lib/typescript/src/api/index.d.ts +1 -0
  87. package/lib/typescript/src/api/index.d.ts.map +1 -1
  88. package/lib/typescript/src/api/media.d.ts +7 -0
  89. package/lib/typescript/src/api/media.d.ts.map +1 -0
  90. package/lib/typescript/src/components/ChatList.d.ts.map +1 -1
  91. package/lib/typescript/src/components/LinkifyText.d.ts.map +1 -1
  92. package/lib/typescript/src/components/MediaMessageItem.d.ts +6 -0
  93. package/lib/typescript/src/components/MediaMessageItem.d.ts.map +1 -0
  94. package/lib/typescript/src/components/MediaPickerButton.d.ts +5 -0
  95. package/lib/typescript/src/components/MediaPickerButton.d.ts.map +1 -0
  96. package/lib/typescript/src/components/MediaViewerModal.d.ts +8 -0
  97. package/lib/typescript/src/components/MediaViewerModal.d.ts.map +1 -0
  98. package/lib/typescript/src/components/MessageInput.d.ts.map +1 -1
  99. package/lib/typescript/src/components/MessageItem.d.ts.map +1 -1
  100. package/lib/typescript/src/constants/translations.d.ts.map +1 -1
  101. package/lib/typescript/src/data/fake/media.d.ts +6 -0
  102. package/lib/typescript/src/data/fake/media.d.ts.map +1 -0
  103. package/lib/typescript/src/types/Conversation.d.ts +19 -0
  104. package/lib/typescript/src/types/Conversation.d.ts.map +1 -1
  105. package/lib/typescript/src/types/LocalizationKeys.d.ts +5 -0
  106. package/lib/typescript/src/types/LocalizationKeys.d.ts.map +1 -1
  107. package/lib/typescript/src/types/MediaTypes.d.ts +26 -0
  108. package/lib/typescript/src/types/MediaTypes.d.ts.map +1 -0
  109. package/lib/typescript/src/version.d.ts +1 -1
  110. package/lib/typescript/src/version.d.ts.map +1 -1
  111. package/package.json +1 -1
  112. package/src/NativeComnyxMediaPicker.ts +83 -0
  113. package/src/api/index.ts +1 -0
  114. package/src/api/media.ts +116 -0
  115. package/src/assets/attachment-01.png +0 -0
  116. package/src/assets/gallery.png +0 -0
  117. package/src/assets/video-play.png +0 -0
  118. package/src/assets/x-circle.png +0 -0
  119. package/src/components/ChatList.tsx +81 -24
  120. package/src/components/CustomerForm.tsx +1 -1
  121. package/src/components/LinkifyText.tsx +3 -2
  122. package/src/components/MediaMessageItem.tsx +390 -0
  123. package/src/components/MediaPickerButton.tsx +269 -0
  124. package/src/components/MediaViewerModal.tsx +168 -0
  125. package/src/components/MessageInput.tsx +396 -84
  126. package/src/components/MessageItem.tsx +19 -5
  127. package/src/constants/translations.ts +145 -0
  128. package/src/data/fake/media.ts +110 -0
  129. package/src/types/Conversation.ts +20 -0
  130. package/src/types/LocalizationKeys.ts +5 -0
  131. package/src/types/MediaTypes.ts +27 -0
  132. package/src/version.ts +1 -1
@@ -0,0 +1,390 @@
1
+ import { View, Image, TouchableOpacity } from 'react-native';
2
+ import { useState, useEffect } from 'react';
3
+ import type { AppConversationMessage } from '../types/Conversation';
4
+ import { useThemeColors } from '../hooks/useThemeColors';
5
+ import { AppText } from './AppText';
6
+ import { ScaledSheet } from './ScaledSheet';
7
+ import { activeOpacity } from '../constants/activeOpacity';
8
+ import { MediaViewerModal } from './MediaViewerModal';
9
+ import { openVideo, generateThumbnail } from '../NativeComnyxMediaPicker';
10
+ import { LinkifyText } from './LinkifyText';
11
+ import { Linking } from 'react-native';
12
+ import type { MediaFileDisplay } from '../types/MediaTypes';
13
+
14
+ const infoIcon = require('../assets/info-circle.png');
15
+ const clockIcon = require('../assets/iconamoon_clock-fill.png');
16
+
17
+ function MediaThumbnail({
18
+ file,
19
+ isUploading,
20
+ onImagePress,
21
+ onVideoPress,
22
+ single,
23
+ }: {
24
+ file: MediaFileDisplay;
25
+ isUploading?: boolean;
26
+ onImagePress: (uri: string) => void;
27
+ onVideoPress: (uri: string) => void;
28
+ single?: boolean;
29
+ }) {
30
+ const [generatedThumb, setGeneratedThumb] = useState<string | null>(null);
31
+ const displayUri = file.local_uri || file.url;
32
+ const isVideo = file.type === 'video';
33
+
34
+ useEffect(() => {
35
+ if (isVideo && !file.thumbnail_uri && !isUploading && displayUri) {
36
+ generateThumbnail(displayUri)
37
+ .then((thumb) => {
38
+ if (thumb) setGeneratedThumb(thumb);
39
+ })
40
+ .catch((err) => {
41
+ console.warn('[Comnyx] Could not generate thumbnail:', err);
42
+ });
43
+ }
44
+ }, [isVideo, file.thumbnail_uri, isUploading, displayUri]);
45
+
46
+ const effectiveThumb = file.thumbnail_uri || generatedThumb;
47
+ const thumbSource = isVideo
48
+ ? effectiveThumb
49
+ ? { uri: effectiveThumb }
50
+ : undefined
51
+ : { uri: displayUri };
52
+
53
+ const handlePress = () => {
54
+ if (isUploading) return;
55
+ if (isVideo) {
56
+ onVideoPress(displayUri);
57
+ } else {
58
+ onImagePress(displayUri);
59
+ }
60
+ };
61
+
62
+ const wrapperStyle = single ? styles.singleMediaWrapper : styles.gridItem;
63
+ const imageStyle = single ? styles.singleMediaImage : styles.gridImage;
64
+ const placeholderStyle = single
65
+ ? [styles.singleMediaImage, { backgroundColor: '#1a1a2e' }]
66
+ : [styles.videoPlaceholder, { backgroundColor: '#1a1a2e' }];
67
+
68
+ return (
69
+ <TouchableOpacity
70
+ style={wrapperStyle}
71
+ onPress={handlePress}
72
+ activeOpacity={activeOpacity}
73
+ disabled={isUploading}
74
+ >
75
+ {thumbSource ? (
76
+ <Image source={thumbSource} style={imageStyle} resizeMode="cover" />
77
+ ) : (
78
+ <View style={placeholderStyle} />
79
+ )}
80
+ {isVideo && !isUploading && (
81
+ <View style={styles.playOverlay}>
82
+ <AppText style={styles.playIcon}>▶</AppText>
83
+ </View>
84
+ )}
85
+ </TouchableOpacity>
86
+ );
87
+ }
88
+
89
+ export function MediaMessageItem({
90
+ item,
91
+ onShowPopup,
92
+ }: {
93
+ item: AppConversationMessage;
94
+ onShowPopup: () => void;
95
+ }) {
96
+ const themeColors = useThemeColors();
97
+ const isDeviceOwner = !item.user && !item.bot;
98
+ const isUploading = item.is_uploading;
99
+ const uploadProgress = item.upload_progress ?? 0;
100
+
101
+ const [viewerVisible, setViewerVisible] = useState(false);
102
+ const [viewerUri, setViewerUri] = useState<string>('');
103
+
104
+ const mediaFiles: MediaFileDisplay[] = (() => {
105
+ if (item.media_files && item.media_files.length > 0) {
106
+ return item.media_files.map((f) => ({
107
+ url: f.url,
108
+ type: f.type,
109
+ local_uri: f.local_uri,
110
+ thumbnail_uri: f.thumbnail_uri,
111
+ }));
112
+ }
113
+
114
+ const singleUri = item.media_local_uri || item.media_url;
115
+ if (singleUri) {
116
+ return [
117
+ {
118
+ url: item.media_url || singleUri,
119
+ type: (item.media_type as 'image' | 'video') || 'image',
120
+ local_uri: item.media_local_uri || undefined,
121
+ thumbnail_uri: item.media_thumbnail_uri || undefined,
122
+ },
123
+ ];
124
+ }
125
+ return [];
126
+ })();
127
+
128
+ const isMultiMedia = mediaFiles.length > 1;
129
+ const hasContent = !!(
130
+ typeof item.content === 'string' && item.content.trim()
131
+ );
132
+
133
+ const formattedDate = new Date(item.created_at).toLocaleTimeString([], {
134
+ hour: '2-digit',
135
+ minute: '2-digit',
136
+ });
137
+
138
+ const handleImagePress = (uri: string) => {
139
+ setViewerUri(uri);
140
+ setViewerVisible(true);
141
+ };
142
+
143
+ const handleVideoPress = (uri: string) => {
144
+ openVideo(uri).catch((err) =>
145
+ console.warn('[Comnyx] Could not open video:', err)
146
+ );
147
+ };
148
+
149
+ const renderFooter = () => {
150
+ if (isDeviceOwner && item.error) {
151
+ return <Image source={infoIcon} style={styles.infoIcon} />;
152
+ } else if (isDeviceOwner && (isUploading || !item.approved)) {
153
+ return (
154
+ <View style={styles.footerRow}>
155
+ {isUploading && (
156
+ <AppText style={styles.uploadPercentText}>
157
+ %{uploadProgress}
158
+ </AppText>
159
+ )}
160
+ <Image source={clockIcon} style={styles.clockIcon} />
161
+ </View>
162
+ );
163
+ } else {
164
+ return (
165
+ <AppText
166
+ style={[
167
+ styles.timestamp,
168
+ isDeviceOwner
169
+ ? styles.rightTimestamp
170
+ : [styles.leftTimestamp, { color: themeColors.text }],
171
+ ]}
172
+ >
173
+ {formattedDate}
174
+ </AppText>
175
+ );
176
+ }
177
+ };
178
+
179
+ return (
180
+ <TouchableOpacity
181
+ activeOpacity={isDeviceOwner && item.error ? 0.8 : 1}
182
+ onLongPress={onShowPopup}
183
+ onPress={() => {
184
+ isDeviceOwner && item.error ? onShowPopup() : {};
185
+ }}
186
+ style={[
187
+ styles.container,
188
+ isDeviceOwner ? styles.rightMessage : styles.leftMessage,
189
+ ]}
190
+ >
191
+ <View
192
+ style={[
193
+ styles.mediaBubble,
194
+ isDeviceOwner
195
+ ? { backgroundColor: themeColors.light_green }
196
+ : { backgroundColor: themeColors.ghost },
197
+ ]}
198
+ >
199
+ {isMultiMedia ? (
200
+ <View style={styles.gridContent}>
201
+ {mediaFiles.map((file, index) => (
202
+ <MediaThumbnail
203
+ key={`${file.url}-${index}`}
204
+ file={file}
205
+ isUploading={isUploading}
206
+ onImagePress={handleImagePress}
207
+ onVideoPress={handleVideoPress}
208
+ />
209
+ ))}
210
+ </View>
211
+ ) : mediaFiles.length === 1 ? (
212
+ <MediaThumbnail
213
+ file={mediaFiles[0]!}
214
+ isUploading={isUploading}
215
+ onImagePress={handleImagePress}
216
+ onVideoPress={handleVideoPress}
217
+ single
218
+ />
219
+ ) : null}
220
+
221
+ {hasContent && (
222
+ <View style={styles.contentContainer}>
223
+ <AppText
224
+ selectable={true}
225
+ style={[
226
+ styles.contentText,
227
+ isDeviceOwner
228
+ ? styles.rightContentText
229
+ : [styles.leftContentText, { color: themeColors.text }],
230
+ ]}
231
+ >
232
+ <LinkifyText
233
+ patterns={[
234
+ {
235
+ regex:
236
+ /https?:\/\/(?:[-\w.])+(?::[0-9]+)?(?:\/(?:[\w/_.])*(?:\?(?:[\w&=%.])*)?(?:#(?:[\w.])*)?)?/g,
237
+ color: '#0066CC',
238
+ navigate: (url) => {
239
+ if (url) {
240
+ Linking.openURL(url);
241
+ }
242
+ },
243
+ },
244
+ ]}
245
+ >
246
+ {typeof item.content === 'string' ? item.content : ''}
247
+ </LinkifyText>
248
+ </AppText>
249
+ </View>
250
+ )}
251
+ <View style={styles.footer}>{renderFooter()}</View>
252
+ </View>
253
+ {viewerVisible && (
254
+ <MediaViewerModal
255
+ visible={viewerVisible}
256
+ onClose={() => {
257
+ setViewerVisible(false);
258
+ setViewerUri('');
259
+ }}
260
+ mediaUri={viewerUri}
261
+ mediaType={'image'}
262
+ />
263
+ )}
264
+ </TouchableOpacity>
265
+ );
266
+ }
267
+
268
+ const styles = ScaledSheet.create({
269
+ container: {
270
+ maxWidth: '80%',
271
+ minWidth: 100,
272
+ marginVertical: '5@vs',
273
+ },
274
+ leftMessage: {
275
+ alignSelf: 'flex-start',
276
+ },
277
+ rightMessage: {
278
+ alignSelf: 'flex-end',
279
+ },
280
+ mediaBubble: {
281
+ borderRadius: '16@vs',
282
+ overflow: 'hidden',
283
+ paddingTop: '4@vs',
284
+ paddingHorizontal: '4@vs',
285
+ },
286
+ gridContent: {
287
+ flexDirection: 'row',
288
+ flexWrap: 'wrap',
289
+ gap: '3@s',
290
+ },
291
+ gridItem: {
292
+ position: 'relative',
293
+ width: '40@vs',
294
+ height: '40@vs',
295
+ borderRadius: '10@vs',
296
+ overflow: 'hidden',
297
+ },
298
+ gridImage: {
299
+ width: '100%',
300
+ height: '100%',
301
+ borderRadius: '10@vs',
302
+ },
303
+ singleMediaWrapper: {
304
+ position: 'relative',
305
+ borderRadius: '12@vs',
306
+ overflow: 'hidden',
307
+ alignSelf: 'flex-start',
308
+ },
309
+ singleMediaImage: {
310
+ width: '40@s',
311
+ aspectRatio: 1,
312
+ borderRadius: '12@vs',
313
+ },
314
+ videoPlaceholder: {
315
+ width: '100%',
316
+ height: '100%',
317
+ borderRadius: '10@vs',
318
+ justifyContent: 'center',
319
+ alignItems: 'center',
320
+ },
321
+ playOverlay: {
322
+ ...({
323
+ position: 'absolute',
324
+ top: 0,
325
+ left: 0,
326
+ right: 0,
327
+ bottom: 0,
328
+ justifyContent: 'center',
329
+ alignItems: 'center',
330
+ } as any),
331
+ },
332
+ playIcon: {
333
+ fontSize: '20@vs',
334
+ color: '#E0E0E0',
335
+ marginLeft: '2@s',
336
+ },
337
+ // Text content
338
+ contentContainer: {
339
+ paddingHorizontal: '8@s',
340
+ paddingTop: '4@vs',
341
+ },
342
+ contentText: {
343
+ fontSize: '16@vs',
344
+ },
345
+ leftContentText: {
346
+ color: '#000000',
347
+ },
348
+ rightContentText: {
349
+ color: '#000000',
350
+ },
351
+ // Footer
352
+ footer: {
353
+ flexDirection: 'row',
354
+ justifyContent: 'flex-end',
355
+ alignItems: 'center',
356
+ marginTop: '4@vs',
357
+ paddingHorizontal: '8@s',
358
+ paddingBottom: '4@vs',
359
+ },
360
+ footerRow: {
361
+ flexDirection: 'row',
362
+ alignItems: 'center',
363
+ gap: '4@s',
364
+ },
365
+ uploadPercentText: {
366
+ fontSize: '10@vs',
367
+ opacity: 0.7,
368
+ color: '#000000',
369
+ },
370
+ timestamp: {
371
+ fontSize: '10@vs',
372
+ opacity: 0.7,
373
+ },
374
+ leftTimestamp: {
375
+ color: '#666666',
376
+ },
377
+ rightTimestamp: {
378
+ color: '#000000',
379
+ },
380
+ infoIcon: {
381
+ width: '12@vs',
382
+ height: '12@vs',
383
+ marginLeft: '4@s',
384
+ },
385
+ clockIcon: {
386
+ width: '12@vs',
387
+ height: '12@vs',
388
+ marginLeft: '4@s',
389
+ },
390
+ });
@@ -0,0 +1,269 @@
1
+ import {
2
+ TouchableOpacity,
3
+ Image,
4
+ View,
5
+ Modal,
6
+ Animated,
7
+ Dimensions,
8
+ TouchableWithoutFeedback,
9
+ Platform,
10
+ } from 'react-native';
11
+ import { useState, useCallback, useRef } from 'react';
12
+ import { useThemeColors } from '../hooks/useThemeColors';
13
+ import { ScaledSheet } from './ScaledSheet';
14
+ import { activeOpacity } from '../constants/activeOpacity';
15
+ import { pickImage, pickVideo } from '../NativeComnyxMediaPicker';
16
+ import { AppText } from './AppText';
17
+ import { useLocalize } from '../hooks/useLocalize';
18
+ import type { MediaAsset } from '../types/MediaTypes';
19
+
20
+ const paperclipIcon = require('../assets/attachment-01.png');
21
+ const galleryIcon = require('../assets/gallery.png');
22
+ const videoPlayIcon = require('../assets/video-play.png');
23
+
24
+ const closeCircleIcon = require('../assets/x-circle.png');
25
+
26
+ const SCREEN_HEIGHT = Dimensions.get('window').height;
27
+
28
+ export function MediaPickerButton({
29
+ onMediaSelected,
30
+ }: {
31
+ onMediaSelected: (assets: MediaAsset[]) => void;
32
+ }) {
33
+ const themeColors = useThemeColors();
34
+ const localize = useLocalize();
35
+ const [visible, setVisible] = useState(false);
36
+ const slideAnim = useRef(new Animated.Value(SCREEN_HEIGHT)).current;
37
+
38
+ const open = useCallback(() => {
39
+ setVisible(true);
40
+ Animated.spring(slideAnim, {
41
+ toValue: 0,
42
+ useNativeDriver: true,
43
+ bounciness: 4,
44
+ speed: 14,
45
+ }).start();
46
+ }, [slideAnim]);
47
+
48
+ const close = useCallback(() => {
49
+ Animated.timing(slideAnim, {
50
+ toValue: SCREEN_HEIGHT,
51
+ duration: 250,
52
+ useNativeDriver: true,
53
+ }).start(() => {
54
+ setVisible(false);
55
+ });
56
+ }, [slideAnim]);
57
+
58
+ const pendingAction = useRef<(() => void) | null>(null);
59
+
60
+ const dismissAndRun = useCallback(
61
+ (action: () => void) => {
62
+ slideAnim.setValue(SCREEN_HEIGHT);
63
+ if (Platform.OS === 'ios') {
64
+ // Defer action until Modal's onDismiss fires to avoid
65
+ // "Attempt to present on a VC which is already presenting"
66
+ pendingAction.current = action;
67
+ setVisible(false);
68
+ } else {
69
+ setVisible(false);
70
+ action();
71
+ }
72
+ },
73
+ [slideAnim]
74
+ );
75
+
76
+ const handlePickImage = useCallback(async () => {
77
+ dismissAndRun(async () => {
78
+ try {
79
+ const assets = await pickImage();
80
+ if (assets.length > 0) onMediaSelected(assets);
81
+ } catch (e) {
82
+ console.error('[Comnyx] pickImage error:', e);
83
+ }
84
+ });
85
+ }, [dismissAndRun, onMediaSelected]);
86
+
87
+ const handlePickVideo = useCallback(async () => {
88
+ dismissAndRun(async () => {
89
+ try {
90
+ const assets = await pickVideo();
91
+ if (assets.length > 0) onMediaSelected(assets);
92
+ } catch (e) {
93
+ console.error('[Comnyx] pickVideo error:', e);
94
+ }
95
+ });
96
+ }, [dismissAndRun, onMediaSelected]);
97
+
98
+ return (
99
+ <>
100
+ <TouchableOpacity
101
+ style={styles.button}
102
+ onPress={open}
103
+ activeOpacity={activeOpacity}
104
+ >
105
+ <Image
106
+ source={paperclipIcon}
107
+ style={[styles.icon, { tintColor: themeColors.text }]}
108
+ />
109
+ </TouchableOpacity>
110
+
111
+ <Modal
112
+ visible={visible}
113
+ transparent
114
+ animationType="none"
115
+ onRequestClose={close}
116
+ onDismiss={() => {
117
+ if (pendingAction.current) {
118
+ const action = pendingAction.current;
119
+ pendingAction.current = null;
120
+ action();
121
+ }
122
+ }}
123
+ statusBarTranslucent
124
+ >
125
+ <TouchableWithoutFeedback onPress={close}>
126
+ <View style={styles.overlay}>
127
+ <TouchableWithoutFeedback>
128
+ <Animated.View
129
+ style={[
130
+ styles.sheet,
131
+ {
132
+ backgroundColor: themeColors.background,
133
+ transform: [{ translateY: slideAnim }],
134
+ },
135
+ ]}
136
+ >
137
+ <View style={styles.handle} />
138
+
139
+ <View style={styles.titleRow}>
140
+ <AppText style={[styles.title, { color: themeColors.text }]}>
141
+ {localize('chat.media.pick.title')}
142
+ </AppText>
143
+ {Platform.OS === 'android' && (
144
+ <TouchableOpacity
145
+ onPress={close}
146
+ activeOpacity={activeOpacity}
147
+ style={styles.closeButton}
148
+ >
149
+ <Image
150
+ source={closeCircleIcon}
151
+ style={styles.closeIcon}
152
+ />
153
+ </TouchableOpacity>
154
+ )}
155
+ </View>
156
+
157
+ <TouchableOpacity
158
+ style={styles.option}
159
+ onPress={handlePickImage}
160
+ activeOpacity={activeOpacity}
161
+ >
162
+ <Image
163
+ source={galleryIcon}
164
+ style={[styles.optionIcon, { tintColor: themeColors.text }]}
165
+ />
166
+ <AppText
167
+ style={[styles.optionText, { color: themeColors.text }]}
168
+ >
169
+ {localize('chat.media.pick.photo')}
170
+ </AppText>
171
+ </TouchableOpacity>
172
+
173
+ <TouchableOpacity
174
+ style={styles.option}
175
+ onPress={handlePickVideo}
176
+ activeOpacity={activeOpacity}
177
+ >
178
+ <Image
179
+ source={videoPlayIcon}
180
+ style={[styles.optionIcon, { tintColor: themeColors.text }]}
181
+ />
182
+ <AppText
183
+ style={[styles.optionText, { color: themeColors.text }]}
184
+ >
185
+ {localize('chat.media.pick.video')}
186
+ </AppText>
187
+ </TouchableOpacity>
188
+ </Animated.View>
189
+ </TouchableWithoutFeedback>
190
+ </View>
191
+ </TouchableWithoutFeedback>
192
+ </Modal>
193
+ </>
194
+ );
195
+ }
196
+
197
+ const styles = ScaledSheet.create({
198
+ button: {
199
+ justifyContent: 'center',
200
+ alignItems: 'center',
201
+ marginRight: '6@s',
202
+ paddingVertical: '6@vs',
203
+ },
204
+ icon: {
205
+ width: '28@vs',
206
+ height: '28@vs',
207
+ },
208
+ overlay: {
209
+ flex: 1,
210
+ backgroundColor: 'rgba(0,0,0,0.4)',
211
+ justifyContent: 'flex-end',
212
+ },
213
+ sheet: {
214
+ borderTopLeftRadius: '16@vs',
215
+ borderTopRightRadius: '16@vs',
216
+ paddingBottom: '34@vs',
217
+ paddingTop: '12@vs',
218
+ paddingHorizontal: '20@s',
219
+ },
220
+ handle: {
221
+ width: '36@s',
222
+ height: '4@vs',
223
+ backgroundColor: '#ccc',
224
+ borderRadius: '2@vs',
225
+ alignSelf: 'center',
226
+ marginBottom: '16@vs',
227
+ },
228
+ titleRow: {
229
+ flexDirection: 'row',
230
+ justifyContent: 'space-between',
231
+ alignItems: 'center',
232
+ marginBottom: '16@vs',
233
+ },
234
+ title: {
235
+ fontSize: '18@vs',
236
+ fontWeight: '600',
237
+ },
238
+ closeButton: {
239
+ padding: '4@vs',
240
+ },
241
+ closeIcon: {
242
+ width: '22@vs',
243
+ height: '22@vs',
244
+ },
245
+ optionIcon: {
246
+ width: '24@vs',
247
+ height: '24@vs',
248
+ marginRight: '12@s',
249
+ },
250
+ option: {
251
+ paddingVertical: '14@vs',
252
+ flexDirection: 'row',
253
+ alignItems: 'center',
254
+ },
255
+ optionText: {
256
+ fontSize: '16@vs',
257
+ },
258
+ cancelButton: {
259
+ marginTop: '8@vs',
260
+ paddingVertical: '14@vs',
261
+ alignItems: 'center',
262
+ borderTopWidth: 0.5,
263
+ borderTopColor: '#ddd',
264
+ },
265
+ cancelText: {
266
+ fontSize: '16@vs',
267
+ opacity: 0.6,
268
+ },
269
+ });