@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
|
@@ -19,6 +19,12 @@ import org.json.JSONObject;
|
|
|
19
19
|
|
|
20
20
|
import java.io.IOException;
|
|
21
21
|
|
|
22
|
+
// NOTE: every MediaPlayer call below is wrapped so a bad player state can never crash the RN app.
|
|
23
|
+
// The player is a single shared instance (WhatsApp-style, one clip at a time), so with several audio
|
|
24
|
+
// cards mounted it can legitimately be null (create failed), released, reset(idle) or in an error
|
|
25
|
+
// state at the moment any method is called. android.media.MediaPlayer throws IllegalStateException
|
|
26
|
+
// (or NPE when null) for a method invoked in the wrong state — those are RuntimeExceptions that would
|
|
27
|
+
// otherwise red-screen. We catch broadly and degrade gracefully (no-op / report an error) instead.
|
|
22
28
|
public class SoundPlayer extends ReactContextBaseJavaModule {
|
|
23
29
|
MediaPlayer mediaPlayer = null;
|
|
24
30
|
JSONObject obj = new JSONObject();
|
|
@@ -45,17 +51,17 @@ public class SoundPlayer extends ReactContextBaseJavaModule {
|
|
|
45
51
|
eventEmitter = getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
|
|
46
52
|
|
|
47
53
|
currentUrl = url;
|
|
48
|
-
mediaPlayer = MediaPlayer.create(getReactApplicationContext(), Uri.parse(url));
|
|
49
|
-
|
|
50
|
-
if(mediaPlayer == null)
|
|
51
|
-
return;
|
|
52
|
-
|
|
53
|
-
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
|
54
54
|
try {
|
|
55
|
+
mediaPlayer = MediaPlayer.create(getReactApplicationContext(), Uri.parse(url));
|
|
56
|
+
if (mediaPlayer == null)
|
|
57
|
+
return;
|
|
58
|
+
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
|
55
59
|
obj = new JSONObject();
|
|
56
|
-
obj.put("duration",mediaPlayer.getDuration()/1000);
|
|
57
|
-
} catch (
|
|
60
|
+
obj.put("duration", mediaPlayer.getDuration() / 1000);
|
|
61
|
+
} catch (Exception e) {
|
|
62
|
+
// create() / setAudioStreamType() / getDuration() in a bad state → don't crash.
|
|
58
63
|
e.printStackTrace();
|
|
64
|
+
return;
|
|
59
65
|
}
|
|
60
66
|
resolve.invoke(obj.toString());
|
|
61
67
|
}
|
|
@@ -66,28 +72,30 @@ public class SoundPlayer extends ReactContextBaseJavaModule {
|
|
|
66
72
|
this.stop();
|
|
67
73
|
emitEvent("complete", prevUrl);
|
|
68
74
|
}
|
|
69
|
-
|
|
75
|
+
|
|
70
76
|
if (mediaPlayer == null)
|
|
71
77
|
eventEmitter = getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
|
|
72
78
|
|
|
73
79
|
currentUrl = url;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
try {
|
|
81
|
+
mediaPlayer = MediaPlayer.create(getReactApplicationContext(), Uri.parse(url));
|
|
82
|
+
if (mediaPlayer == null) {
|
|
83
|
+
// create() returns null for an unplayable/unavailable URI — tell JS instead of hanging.
|
|
84
|
+
resolve.invoke("Error", "Unable to load audio");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
78
87
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
|
|
89
|
+
@Override
|
|
90
|
+
public void onCompletion(MediaPlayer mp) {
|
|
91
|
+
emitEvent("complete", url);
|
|
92
|
+
if (prevUrl.equals(url)){
|
|
93
|
+
prevUrl = "";
|
|
94
|
+
}
|
|
85
95
|
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
96
|
+
});
|
|
88
97
|
|
|
89
|
-
|
|
90
|
-
try {
|
|
98
|
+
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
|
91
99
|
mediaPlayer.start();
|
|
92
100
|
obj = new JSONObject();
|
|
93
101
|
obj.put("success", true);
|
|
@@ -99,40 +107,54 @@ public class SoundPlayer extends ReactContextBaseJavaModule {
|
|
|
99
107
|
obj.put("duration", duration);
|
|
100
108
|
obj.put("url", currentUrl);
|
|
101
109
|
resolve.invoke(obj.toString());
|
|
102
|
-
} catch (
|
|
110
|
+
} catch (Exception ex) {
|
|
111
|
+
// start()/getDuration() on a bad player state (IllegalStateException) or JSON error →
|
|
112
|
+
// report it, never crash. resolve is invoked exactly once on every path.
|
|
103
113
|
resolve.invoke("Error", ex.getMessage());
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
116
|
|
|
107
117
|
@ReactMethod
|
|
108
118
|
public void resume() {
|
|
109
|
-
|
|
110
|
-
mediaPlayer
|
|
119
|
+
try {
|
|
120
|
+
if (mediaPlayer != null) {
|
|
121
|
+
mediaPlayer.start();
|
|
122
|
+
}
|
|
123
|
+
} catch (Exception e) {
|
|
124
|
+
// start() on a released/error/idle player throws IllegalStateException — ignore.
|
|
125
|
+
e.printStackTrace();
|
|
111
126
|
}
|
|
112
127
|
}
|
|
113
128
|
|
|
114
129
|
@ReactMethod
|
|
115
130
|
public void playAt(int atTime, Callback resolve) {
|
|
116
|
-
|
|
131
|
+
try {
|
|
132
|
+
if (mediaPlayer == null) {
|
|
133
|
+
resolve.invoke("Error", "MediaPlayer not prepared.");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
117
136
|
mediaPlayer.seekTo(atTime * 1000);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
137
|
+
} catch (Exception e) {
|
|
138
|
+
// seekTo() in an invalid state throws IllegalStateException — report, don't crash.
|
|
139
|
+
resolve.invoke("Error", e.getMessage());
|
|
140
|
+
return;
|
|
122
141
|
}
|
|
142
|
+
obj = new JSONObject();
|
|
143
|
+
resolve.invoke(obj.toString());
|
|
123
144
|
}
|
|
124
145
|
|
|
125
146
|
@ReactMethod
|
|
126
147
|
public void pause(Callback resolve) {
|
|
127
|
-
if (mediaPlayer
|
|
148
|
+
if (mediaPlayer == null)
|
|
149
|
+
return;
|
|
150
|
+
try {
|
|
128
151
|
mediaPlayer.pause();
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
152
|
+
obj = new JSONObject();
|
|
153
|
+
obj.put("success", true);
|
|
154
|
+
resolve.invoke(obj.toString());
|
|
155
|
+
} catch (Exception ex) {
|
|
156
|
+
// pause() on a non-started player throws IllegalStateException — swallow, don't crash.
|
|
157
|
+
resolve.invoke(obj.toString());
|
|
136
158
|
}
|
|
137
159
|
}
|
|
138
160
|
|
|
@@ -140,24 +162,40 @@ public class SoundPlayer extends ReactContextBaseJavaModule {
|
|
|
140
162
|
public void stop() {
|
|
141
163
|
if(mediaPlayer == null)
|
|
142
164
|
return;
|
|
143
|
-
|
|
144
|
-
|
|
165
|
+
try {
|
|
166
|
+
mediaPlayer.stop();
|
|
167
|
+
mediaPlayer.reset();
|
|
168
|
+
} catch (Exception e) {
|
|
169
|
+
// stop() from Idle/Error state throws IllegalStateException — ignore, never crash.
|
|
170
|
+
e.printStackTrace();
|
|
171
|
+
}
|
|
145
172
|
}
|
|
146
173
|
|
|
147
174
|
@ReactMethod
|
|
148
175
|
public void releaseMediaPlayer() {
|
|
149
176
|
if(mediaPlayer == null)
|
|
150
177
|
return;
|
|
151
|
-
|
|
178
|
+
try {
|
|
179
|
+
mediaPlayer.release();
|
|
180
|
+
} catch (Exception e) {
|
|
181
|
+
e.printStackTrace();
|
|
182
|
+
}
|
|
183
|
+
// Null the reference so later calls (getPosition polls, another card's release) see a null
|
|
184
|
+
// player and take the safe path instead of touching a released one (IllegalStateException).
|
|
185
|
+
mediaPlayer = null;
|
|
152
186
|
}
|
|
153
187
|
|
|
154
188
|
@ReactMethod
|
|
155
189
|
public void getPosition(Callback resolve) {
|
|
190
|
+
obj = new JSONObject();
|
|
156
191
|
try {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
192
|
+
// Guard: the shared MediaPlayer may be null (create failed) or released/reset by another
|
|
193
|
+
// audio card between polls. getCurrentPosition() on a null/invalid player would throw an
|
|
194
|
+
// uncaught NPE/IllegalStateException and red-screen the app — report 0 instead.
|
|
195
|
+
int position = (mediaPlayer != null) ? mediaPlayer.getCurrentPosition() / 1000 : 0;
|
|
196
|
+
obj.put("position", position);
|
|
197
|
+
} catch (Exception e) {
|
|
198
|
+
try { obj.put("position", 0); } catch (JSONException ignored) {}
|
|
161
199
|
}
|
|
162
200
|
resolve.invoke(obj.toString());
|
|
163
201
|
}
|
|
@@ -167,4 +205,4 @@ public class SoundPlayer extends ReactContextBaseJavaModule {
|
|
|
167
205
|
public String getName() {
|
|
168
206
|
return MODULE_NAME;
|
|
169
207
|
}
|
|
170
|
-
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(CometChatClipboardModule, NSObject)
|
|
4
|
+
|
|
5
|
+
RCT_EXTERN_METHOD(hasImageInClipboard:(RCTPromiseResolveBlock)resolve
|
|
6
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
7
|
+
|
|
8
|
+
RCT_EXTERN_METHOD(getClipboardImage:(RCTPromiseResolveBlock)resolve
|
|
9
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
10
|
+
|
|
11
|
+
@end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
@objc(CometChatClipboardModule)
|
|
5
|
+
class CometChatClipboardModule: NSObject {
|
|
6
|
+
|
|
7
|
+
@objc func hasImageInClipboard(
|
|
8
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
9
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
10
|
+
) {
|
|
11
|
+
let pb = UIPasteboard.general
|
|
12
|
+
resolve(pb.image != nil || pb.hasImages)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@objc func getClipboardImage(
|
|
16
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
17
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
18
|
+
) {
|
|
19
|
+
guard let image = UIPasteboard.general.image else {
|
|
20
|
+
resolve(nil); return
|
|
21
|
+
}
|
|
22
|
+
guard let data = image.jpegData(compressionQuality: 0.9) else {
|
|
23
|
+
reject("ERROR", "Failed to encode clipboard image", nil); return
|
|
24
|
+
}
|
|
25
|
+
let tempURL = FileManager.default.temporaryDirectory
|
|
26
|
+
.appendingPathComponent("clipboard_paste.jpg")
|
|
27
|
+
do {
|
|
28
|
+
try data.write(to: tempURL)
|
|
29
|
+
} catch {
|
|
30
|
+
reject("ERROR", error.localizedDescription, error); return
|
|
31
|
+
}
|
|
32
|
+
resolve([
|
|
33
|
+
"uri": tempURL.absoluteString,
|
|
34
|
+
"mimeType": "image/jpeg",
|
|
35
|
+
"size": data.count,
|
|
36
|
+
"name": "clipboard_paste.jpg"
|
|
37
|
+
] as [String: Any])
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@objc static func requiresMainQueueSetup() -> Bool { return false }
|
|
41
|
+
}
|
package/ios/FileManager.m
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
#import <MobileCoreServices/MobileCoreServices.h>
|
|
8
8
|
#import <AVFoundation/AVFoundation.h>
|
|
9
9
|
#import <UIKit/UIKit.h>
|
|
10
|
+
#import <PhotosUI/PhotosUI.h>
|
|
10
11
|
|
|
11
12
|
static NSString *const E_DOCUMENT_PICKER_CANCELED = @"DOCUMENT_PICKER_CANCELED";
|
|
12
13
|
static NSString *const E_INVALID_DATA_RETURNED = @"INVALID_DATA_RETURNED";
|
|
@@ -22,7 +23,7 @@ static NSString *const FIELD_TYPE = @"type";
|
|
|
22
23
|
static NSString *const FIELD_SIZE = @"size";
|
|
23
24
|
|
|
24
25
|
|
|
25
|
-
@interface CometChatFileManager () <UIDocumentPickerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, AVAudioRecorderDelegate, AVAudioPlayerDelegate, UIDocumentInteractionControllerDelegate>
|
|
26
|
+
@interface CometChatFileManager () <UIDocumentPickerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, AVAudioRecorderDelegate, AVAudioPlayerDelegate, UIDocumentInteractionControllerDelegate, PHPickerViewControllerDelegate>
|
|
26
27
|
|
|
27
28
|
@property (nonatomic, strong) AVAudioSession *recordingSession;
|
|
28
29
|
@property (nonatomic, strong) AVAudioRecorder *audioRecorder;
|
|
@@ -45,6 +46,7 @@ static NSString *const FIELD_SIZE = @"size";
|
|
|
45
46
|
NSString *_url;
|
|
46
47
|
RCTResponseSenderBlock callback;
|
|
47
48
|
bool hasListeners;
|
|
49
|
+
BOOL _multipleSelection;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
- (void)startObserving {
|
|
@@ -61,33 +63,60 @@ static NSString *const FIELD_SIZE = @"size";
|
|
|
61
63
|
|
|
62
64
|
RCT_EXPORT_MODULE(FileManager)
|
|
63
65
|
|
|
66
|
+
// Private — download the remote file into the app's Documents dir. On success sets self->_url to the
|
|
67
|
+
// local file:// path and calls back {"success":true}; on failure {"success":false}. ONE async fetch
|
|
68
|
+
// (the old code did a blocking dataWithContentsOfURL AND a downloadTask — a double download that also
|
|
69
|
+
// never fired the callback when that pre-fetch failed, leaving JS stuck in "downloading").
|
|
70
|
+
- (void)downloadToDocuments:(NSString *)urlToDownload name:(NSString *)name callback:(RCTResponseSenderBlock)callback {
|
|
71
|
+
NSURL *url = [NSURL URLWithString:urlToDownload];
|
|
72
|
+
if (url == nil) { callback(@[@"{\"success\": false, \"error\": \"invalid url\"}"]); return; }
|
|
73
|
+
|
|
74
|
+
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
75
|
+
NSString *destPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:name];
|
|
76
|
+
NSURL *destinationFileURL = [NSURL fileURLWithPath:destPath];
|
|
77
|
+
|
|
78
|
+
NSURLSessionDownloadTask *task = [[NSURLSession sharedSession] downloadTaskWithURL:url
|
|
79
|
+
completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
80
|
+
if (error != nil || location == nil) {
|
|
81
|
+
callback(@[@"{\"success\": false, \"error\": \"download failed\"}"]);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
NSFileManager *fm = [NSFileManager defaultManager];
|
|
85
|
+
[fm removeItemAtURL:destinationFileURL error:nil]; // overwrite any prior copy
|
|
86
|
+
NSError *moveErr = nil;
|
|
87
|
+
[fm moveItemAtURL:location toURL:destinationFileURL error:&moveErr];
|
|
88
|
+
if (moveErr != nil) {
|
|
89
|
+
callback(@[@"{\"success\": false, \"error\": \"could not save file\"}"]);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
self->_url = [NSString stringWithFormat:@"file://%@", destPath];
|
|
93
|
+
callback(@[@"{\"success\": true}"]);
|
|
94
|
+
}];
|
|
95
|
+
[task resume];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The download button. Downloads the file, then presents the iOS share sheet so the user can Save to
|
|
99
|
+
// Files / Save to Photos / AirDrop — the sandbox-legal equivalent of Android's visible DownloadManager
|
|
100
|
+
// save (iOS apps cannot write to a shared public "Downloads" folder). Previously this saved into the
|
|
101
|
+
// app's PRIVATE Documents dir with no UI, so on iOS the download appeared to do nothing.
|
|
64
102
|
RCT_EXPORT_METHOD(checkAndDownload:(NSString *) urlToDownload name:(NSString *) name callback:(RCTResponseSenderBlock) callback) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
NSURL *url = [NSURL URLWithString:urlToDownload];
|
|
77
|
-
[[[NSURLSession sharedSession] downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
|
78
|
-
if (error == nil) {
|
|
79
|
-
NSLog(@"down moving %@ to %@", location, destinationFileURL);
|
|
80
|
-
[[NSFileManager defaultManager] moveItemAtURL:location toURL:destinationFileURL error:nil];
|
|
81
|
-
NSLog(@"downloaded to %@", filePath);
|
|
82
|
-
self->_url = filePath;
|
|
83
|
-
NSString *response = [NSString stringWithFormat:@"{\"success\": true, \"filePath\":%d}", filePath];
|
|
84
|
-
callback(@[response]);
|
|
85
|
-
return;
|
|
103
|
+
[self downloadToDocuments:urlToDownload name:name callback:^(NSArray *response) {
|
|
104
|
+
NSString *res = response.firstObject ?: @"";
|
|
105
|
+
if ([res containsString:@"\"success\": true"]) {
|
|
106
|
+
NSString *destPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:name];
|
|
107
|
+
NSURL *fileURL = [NSURL fileURLWithPath:destPath];
|
|
108
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
109
|
+
UIActivityViewController *share = [[UIActivityViewController alloc] initWithActivityItems:@[fileURL] applicationActivities:nil];
|
|
110
|
+
UIViewController *presenter = RCTPresentedViewController();
|
|
111
|
+
if (share.popoverPresentationController != nil) { // iPad anchor
|
|
112
|
+
share.popoverPresentationController.sourceView = presenter.view;
|
|
113
|
+
share.popoverPresentationController.sourceRect = CGRectMake(CGRectGetMidX(presenter.view.bounds), CGRectGetMidY(presenter.view.bounds), 0, 0);
|
|
86
114
|
}
|
|
87
|
-
|
|
88
|
-
}
|
|
115
|
+
[presenter presentViewController:share animated:YES completion:nil];
|
|
116
|
+
});
|
|
89
117
|
}
|
|
90
|
-
|
|
118
|
+
callback(response);
|
|
119
|
+
}];
|
|
91
120
|
}
|
|
92
121
|
|
|
93
122
|
- (void) openMedia:(NSString *) path {
|
|
@@ -134,12 +163,19 @@ RCT_EXPORT_METHOD(openFile:(NSString *) url name:(NSString *) fileName myCallbac
|
|
|
134
163
|
} else {
|
|
135
164
|
if (hasListeners)
|
|
136
165
|
[self sendEventWithName:@"status" body:@{@"url": url, @"state": @"downloading"}];
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
166
|
+
// Use the private helper (NOT checkAndDownload) — checkAndDownload now shows the share sheet,
|
|
167
|
+
// which must not pop up when we're only downloading in order to preview. The helper sets
|
|
168
|
+
// self->_url to the real local file path on success (the old code set it to the JSON string).
|
|
169
|
+
[self downloadToDocuments:url name:fileName callback:^(NSArray *response) {
|
|
170
|
+
NSString *res = response.firstObject ?: @"";
|
|
171
|
+
if ([res containsString:@"\"success\": true"]) {
|
|
172
|
+
[self openMedia:self->_url];
|
|
173
|
+
if (self->hasListeners)
|
|
174
|
+
[self sendEventWithName:@"status" body:@{@"url": url, @"state": @"opening"}];
|
|
175
|
+
callback(@[@"{\"success\": true}"]);
|
|
176
|
+
} else {
|
|
177
|
+
callback(@[@"{\"success\": false}"]);
|
|
178
|
+
}
|
|
143
179
|
}];
|
|
144
180
|
}
|
|
145
181
|
} @catch (NSException *exception) {
|
|
@@ -336,6 +372,45 @@ RCT_EXPORT_METHOD(openFileChooser:(NSString *)type callback:(RCTResponseSenderBl
|
|
|
336
372
|
}
|
|
337
373
|
|
|
338
374
|
|
|
375
|
+
RCT_EXPORT_METHOD(openFileChooserMulti:(NSString *)type maxSelection:(nonnull NSNumber *)maxSelection callback:(RCTResponseSenderBlock)call) {
|
|
376
|
+
callback = call;
|
|
377
|
+
UIViewController *presentedViewController = RCTPresentedViewController();
|
|
378
|
+
|
|
379
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
380
|
+
if ([@"image" isEqualToString:type]) {
|
|
381
|
+
// Use PHPickerViewController — opens the Photos library with a proper multi-select grid.
|
|
382
|
+
// Does NOT require NSPhotoLibraryUsageDescription (runs in a separate process on iOS 14+).
|
|
383
|
+
PHPickerConfiguration *config = [[PHPickerConfiguration alloc] init];
|
|
384
|
+
config.selectionLimit = maxSelection.integerValue; // remaining allowance (server count limit − already staged); 0 = unlimited
|
|
385
|
+
config.filter = [PHPickerFilter anyFilterMatchingSubfilters:@[[PHPickerFilter imagesFilter], [PHPickerFilter videosFilter]]];
|
|
386
|
+
PHPickerViewController *picker = [[PHPickerViewController alloc] initWithConfiguration:config];
|
|
387
|
+
picker.delegate = self;
|
|
388
|
+
[presentedViewController presentViewController:picker animated:YES completion:nil];
|
|
389
|
+
} else {
|
|
390
|
+
_multipleSelection = YES;
|
|
391
|
+
NSArray *documentTypes;
|
|
392
|
+
if ([@"audio" isEqualToString:type]) {
|
|
393
|
+
documentTypes = @[@"public.audio"];
|
|
394
|
+
} else if ([@"video" isEqualToString:type]) {
|
|
395
|
+
documentTypes = @[@"public.movie", @"public.video"];
|
|
396
|
+
} else if ([@"text" isEqualToString:type]) {
|
|
397
|
+
documentTypes = @[@"public.text"];
|
|
398
|
+
} else if ([@"zip" isEqualToString:type]) {
|
|
399
|
+
documentTypes = @[@"com.pkware.zip-archive"];
|
|
400
|
+
} else {
|
|
401
|
+
documentTypes = @[@"public.data"];
|
|
402
|
+
}
|
|
403
|
+
UIDocumentPickerViewController *documentController =
|
|
404
|
+
[[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes
|
|
405
|
+
inMode:UIDocumentPickerModeImport];
|
|
406
|
+
// Single-select when the cap is 1 (allowMultipleSelection=false, or only one slot left).
|
|
407
|
+
documentController.allowsMultipleSelection = (maxSelection.integerValue != 1);
|
|
408
|
+
documentController.delegate = self;
|
|
409
|
+
[presentedViewController presentViewController:documentController animated:YES completion:nil];
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
339
414
|
RCT_EXPORT_METHOD(shareMessage: (NSDictionary *) shareObj myCallback:(RCTResponseSenderBlock)callback) {
|
|
340
415
|
NSString *message = shareObj[@"message"];
|
|
341
416
|
NSString *type = shareObj[@"type"];
|
|
@@ -1040,7 +1115,10 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
|
|
|
1040
1115
|
NSString *type = [self getMimeType:new_image_url];
|
|
1041
1116
|
NSString *name = [new_image_url lastPathComponent];
|
|
1042
1117
|
NSString *uri = [NSString stringWithFormat:@"%@", new_image_url];
|
|
1043
|
-
|
|
1118
|
+
// The SDK presign step rejects a 0/missing size (same fix as the document
|
|
1119
|
+
// picker + PHPicker paths). The captured image is saved locally above, so
|
|
1120
|
+
// stat it for the real byte size — otherwise the attachment errors on upload.
|
|
1121
|
+
callback(@[@{@"name": name, @"type": type, @"uri": uri, @"size": [self getFileSizeForURL:new_image_url]}]);
|
|
1044
1122
|
} else {
|
|
1045
1123
|
NSLog(@"failed to get image");
|
|
1046
1124
|
callback(@[@{@"error": @"unable to get image"}]);
|
|
@@ -1099,14 +1177,98 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
|
|
|
1099
1177
|
[picker dismissViewControllerAnimated:TRUE completion:nil];
|
|
1100
1178
|
}
|
|
1101
1179
|
|
|
1180
|
+
// PHPickerViewControllerDelegate — handles multi-select from Photos library (images and videos)
|
|
1181
|
+
- (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results {
|
|
1182
|
+
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
1183
|
+
if (results.count == 0) {
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
dispatch_group_t group = dispatch_group_create();
|
|
1188
|
+
NSMutableArray *fileInfoArray = [NSMutableArray array];
|
|
1189
|
+
|
|
1190
|
+
for (PHPickerResult *result in results) {
|
|
1191
|
+
NSString *typeIdentifier = nil;
|
|
1192
|
+
if ([result.itemProvider hasItemConformingToTypeIdentifier:@"public.image"]) {
|
|
1193
|
+
typeIdentifier = @"public.image";
|
|
1194
|
+
} else if ([result.itemProvider hasItemConformingToTypeIdentifier:@"public.movie"]) {
|
|
1195
|
+
typeIdentifier = @"public.movie";
|
|
1196
|
+
}
|
|
1197
|
+
if (!typeIdentifier) continue;
|
|
1198
|
+
|
|
1199
|
+
dispatch_group_enter(group);
|
|
1200
|
+
[result.itemProvider loadFileRepresentationForTypeIdentifier:typeIdentifier
|
|
1201
|
+
completionHandler:^(NSURL *url, NSError *error) {
|
|
1202
|
+
if (url && !error) {
|
|
1203
|
+
NSString *dirPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[NSUUID UUID] UUIDString]];
|
|
1204
|
+
[[NSFileManager defaultManager] createDirectoryAtPath:dirPath
|
|
1205
|
+
withIntermediateDirectories:YES
|
|
1206
|
+
attributes:nil
|
|
1207
|
+
error:nil];
|
|
1208
|
+
NSString *destPath = [dirPath stringByAppendingPathComponent:url.lastPathComponent];
|
|
1209
|
+
NSError *copyError;
|
|
1210
|
+
[[NSFileManager defaultManager] copyItemAtPath:url.path toPath:destPath error:©Error];
|
|
1211
|
+
if (!copyError) {
|
|
1212
|
+
NSURL *destURL = [NSURL fileURLWithPath:destPath];
|
|
1213
|
+
NSString *mimeType = [self getMimeType:destURL] ?: @"image/jpeg";
|
|
1214
|
+
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:destPath error:nil];
|
|
1215
|
+
NSNumber *fileSize = attrs[NSFileSize] ?: @0;
|
|
1216
|
+
NSDictionary *fileInfo = @{
|
|
1217
|
+
@"name": destURL.lastPathComponent,
|
|
1218
|
+
@"type": mimeType,
|
|
1219
|
+
@"uri": destURL.absoluteString,
|
|
1220
|
+
@"size": fileSize,
|
|
1221
|
+
};
|
|
1222
|
+
@synchronized(fileInfoArray) {
|
|
1223
|
+
[fileInfoArray addObject:fileInfo];
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
dispatch_group_leave(group);
|
|
1228
|
+
}];
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
|
1232
|
+
if (fileInfoArray.count > 0) {
|
|
1233
|
+
callback(@[fileInfoArray]);
|
|
1234
|
+
}
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
- (NSNumber *)getFileSizeForURL:(NSURL *)url {
|
|
1239
|
+
// Import-mode document picks are copied into the app sandbox, so we can stat the local path
|
|
1240
|
+
// directly (no security-scoped access needed). The SDK's presign step REQUIRES a real byte
|
|
1241
|
+
// size — a 0/missing size is rejected server-side ("Failed to validate the data sent…").
|
|
1242
|
+
NSError *error = nil;
|
|
1243
|
+
NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:url.path error:&error];
|
|
1244
|
+
if (attrs && !error) {
|
|
1245
|
+
return @([attrs fileSize]);
|
|
1246
|
+
}
|
|
1247
|
+
return @(0);
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1102
1250
|
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1251
|
+
if (_multipleSelection) {
|
|
1252
|
+
_multipleSelection = NO;
|
|
1253
|
+
NSMutableArray *results = [NSMutableArray array];
|
|
1254
|
+
for (NSURL *url in urls) {
|
|
1255
|
+
NSString *uri = [NSString stringWithFormat:@"%@", url];
|
|
1256
|
+
NSString *type = [self getMimeType:url];
|
|
1257
|
+
NSString *name = [url lastPathComponent];
|
|
1258
|
+
if (!name) name = @"Unknown";
|
|
1259
|
+
if (!type) type = @"application/octet-stream";
|
|
1260
|
+
[results addObject:@{@"name": name, @"type": type, @"uri": uri, @"size": [self getFileSizeForURL:url]}];
|
|
1261
|
+
}
|
|
1262
|
+
callback(@[results]);
|
|
1263
|
+
} else {
|
|
1264
|
+
NSLog(@"document selected %@", urls[0]);
|
|
1265
|
+
NSString *uri = [NSString stringWithFormat:@"%@", urls[0]];
|
|
1266
|
+
NSString *type = [self getMimeType:urls[0]];
|
|
1267
|
+
NSString *name = [urls[0] lastPathComponent];
|
|
1268
|
+
if (!name) name = @"Unknown";
|
|
1269
|
+
if (!type) type = @"Unknown";
|
|
1270
|
+
callback(@[@{@"name": name, @"type": type, @"uri": uri, @"size": [self getFileSizeForURL:urls[0]]}]);
|
|
1271
|
+
}
|
|
1110
1272
|
}
|
|
1111
1273
|
|
|
1112
1274
|
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
|