@cometchat/chat-uikit-react-native 5.3.9 → 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 +28 -6
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +649 -49
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +23 -4
- package/src/CometChatMessageList/CometChatMessageList.tsx +530 -58
- 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 +321 -62
- 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 +43 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +43 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +44 -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 +44 -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
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package com.reactnativecometchatuikit
|
|
2
|
+
|
|
3
|
+
import android.content.ClipboardManager
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import com.facebook.react.bridge.Promise
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
8
|
+
import com.facebook.react.bridge.ReactMethod
|
|
9
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
10
|
+
import java.io.File
|
|
11
|
+
|
|
12
|
+
class CometChatClipboardModule(reactContext: ReactApplicationContext)
|
|
13
|
+
: ReactContextBaseJavaModule(reactContext) {
|
|
14
|
+
|
|
15
|
+
override fun getName() = "CometChatClipboardModule"
|
|
16
|
+
|
|
17
|
+
@ReactMethod
|
|
18
|
+
fun hasImageInClipboard(promise: Promise) {
|
|
19
|
+
val cm = reactApplicationContext
|
|
20
|
+
.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
21
|
+
val clip = cm.primaryClip
|
|
22
|
+
val hasUri = clip != null && (0 until clip.itemCount).any { i ->
|
|
23
|
+
clip.getItemAt(i)?.uri != null
|
|
24
|
+
}
|
|
25
|
+
promise.resolve(hasUri)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@ReactMethod
|
|
29
|
+
fun getClipboardImage(promise: Promise) {
|
|
30
|
+
val cm = reactApplicationContext
|
|
31
|
+
.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
32
|
+
val clip = cm.primaryClip
|
|
33
|
+
if (clip == null || clip.itemCount == 0) { promise.resolve(null); return }
|
|
34
|
+
val uri = clip.getItemAt(0)?.uri
|
|
35
|
+
if (uri == null) { promise.resolve(null); return }
|
|
36
|
+
try {
|
|
37
|
+
val inputStream = reactApplicationContext.contentResolver.openInputStream(uri)
|
|
38
|
+
?: run { promise.resolve(null); return }
|
|
39
|
+
val file = File(reactApplicationContext.cacheDir, "clipboard_paste.jpg")
|
|
40
|
+
inputStream.use { it.copyTo(file.outputStream()) }
|
|
41
|
+
val map = WritableNativeMap().apply {
|
|
42
|
+
putString("uri", "file://${file.absolutePath}")
|
|
43
|
+
putString("mimeType", "image/jpeg")
|
|
44
|
+
putInt("size", file.length().toInt())
|
|
45
|
+
putString("name", "clipboard_paste.jpg")
|
|
46
|
+
}
|
|
47
|
+
promise.resolve(map)
|
|
48
|
+
} catch (e: Exception) {
|
|
49
|
+
promise.reject("ERROR", e.message)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -26,6 +26,7 @@ public class CometchatUiKitPackage implements ReactPackage {
|
|
|
26
26
|
modules.add(new WebViewManager(reactContext));
|
|
27
27
|
modules.add(new TimeZoneCodeManager(reactContext));
|
|
28
28
|
modules.add(new ProximityModule(reactContext));
|
|
29
|
+
modules.add(new CometChatClipboardModule(reactContext));
|
|
29
30
|
return modules;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -47,6 +47,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
|
47
47
|
import com.facebook.react.bridge.ReactMethod;
|
|
48
48
|
import com.facebook.react.bridge.ReadableMap;
|
|
49
49
|
import com.facebook.react.bridge.WritableMap;
|
|
50
|
+
import com.facebook.react.bridge.WritableArray;
|
|
50
51
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
51
52
|
|
|
52
53
|
import java.io.File;
|
|
@@ -81,9 +82,11 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
81
82
|
private static final int READ_REQUEST_CODE = 100;
|
|
82
83
|
private static final int CAPTURE_STILL_IMAGE = 101;
|
|
83
84
|
private static final int REQUEST_LAUNCH_CAMERA = 1;
|
|
85
|
+
private static final int READ_REQUEST_CODE_MULTI = 102;
|
|
84
86
|
private static int IMAGE_QUALITY = 20;
|
|
85
87
|
|
|
86
88
|
private Callback callback;
|
|
89
|
+
private Callback multiCallback;
|
|
87
90
|
|
|
88
91
|
private static final String FIELD_URI = "uri";
|
|
89
92
|
private static final String FIELD_FILE_COPY_URI = "fileCopyUri";
|
|
@@ -132,6 +135,10 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
132
135
|
private final ActivityEventListener activityEventListener = new BaseActivityEventListener() {
|
|
133
136
|
@Override
|
|
134
137
|
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
|
|
138
|
+
if (requestCode == READ_REQUEST_CODE_MULTI) {
|
|
139
|
+
if (multiCallback != null) onShowActivityResultMulti(resultCode, data, multiCallback);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
135
142
|
if (callback == null) {
|
|
136
143
|
Log.e(NAME, "callback was null in onActivityResult");
|
|
137
144
|
return;
|
|
@@ -319,6 +326,33 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
319
326
|
return Uri.fromFile(destFile);
|
|
320
327
|
}
|
|
321
328
|
|
|
329
|
+
private void onShowActivityResultMulti(int resultCode, Intent data, Callback storedCallback) {
|
|
330
|
+
if (resultCode != Activity.RESULT_OK) return;
|
|
331
|
+
List<Uri> uris = new ArrayList<>();
|
|
332
|
+
if (data != null) {
|
|
333
|
+
ClipData clipData = data.getClipData();
|
|
334
|
+
if (clipData != null && clipData.getItemCount() > 0) {
|
|
335
|
+
for (int i = 0; i < clipData.getItemCount(); i++) {
|
|
336
|
+
uris.add(clipData.getItemAt(i).getUri());
|
|
337
|
+
}
|
|
338
|
+
} else if (data.getData() != null) {
|
|
339
|
+
uris.add(data.getData());
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (uris.isEmpty()) return;
|
|
343
|
+
ExecutorService service = Executors.newSingleThreadExecutor();
|
|
344
|
+
service.execute(new Runnable() {
|
|
345
|
+
@Override
|
|
346
|
+
public void run() {
|
|
347
|
+
WritableArray array = Arguments.createArray();
|
|
348
|
+
for (Uri uri : uris) {
|
|
349
|
+
array.pushMap(getMetadata(uri));
|
|
350
|
+
}
|
|
351
|
+
storedCallback.invoke(array);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
322
356
|
private void onShowActivityResult(int resultCode, Intent data, Callback storedPromise) {
|
|
323
357
|
if (resultCode == Activity.RESULT_OK) {
|
|
324
358
|
Uri uri = null;
|
|
@@ -1669,21 +1703,74 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
1669
1703
|
}
|
|
1670
1704
|
}
|
|
1671
1705
|
|
|
1706
|
+
@ReactMethod
|
|
1707
|
+
public void openFileChooserMulti(String fileType, int maxSelection, Callback callback) {
|
|
1708
|
+
try {
|
|
1709
|
+
this.multiCallback = callback;
|
|
1710
|
+
Activity currentActivity = getCurrentActivity();
|
|
1711
|
+
if ("image".equals(fileType)) {
|
|
1712
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
1713
|
+
// Android 13+: system photo picker — no READ_MEDIA_IMAGES permission required
|
|
1714
|
+
Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
|
|
1715
|
+
// Cap selection to the remaining allowance (server count limit − already staged),
|
|
1716
|
+
// clamped to the OS max. cap==1 is valid — the photo picker enters single-select and
|
|
1717
|
+
// returns getData() (handled by onShowActivityResultMulti's data.getData() branch).
|
|
1718
|
+
int cap = Math.min(Math.max(1, maxSelection), MediaStore.getPickImagesMaxLimit());
|
|
1719
|
+
intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, cap);
|
|
1720
|
+
currentActivity.startActivityForResult(intent, READ_REQUEST_CODE_MULTI, Bundle.EMPTY);
|
|
1721
|
+
} else {
|
|
1722
|
+
// Android < 13: open gallery via ACTION_GET_CONTENT with multi-select
|
|
1723
|
+
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
1724
|
+
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
1725
|
+
intent.setType("image/*");
|
|
1726
|
+
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, maxSelection != 1); // single-select when the cap is 1
|
|
1727
|
+
currentActivity.startActivityForResult(intent, READ_REQUEST_CODE_MULTI, Bundle.EMPTY);
|
|
1728
|
+
}
|
|
1729
|
+
} else {
|
|
1730
|
+
// Non-image: document picker without createChooser so EXTRA_ALLOW_MULTIPLE works.
|
|
1731
|
+
// Use setType("*/*") + EXTRA_MIME_TYPES rather than setType("audio/*"): a SPECIFIC
|
|
1732
|
+
// top-level type (audio/*, video/*) routes many devices to a single-select media/
|
|
1733
|
+
// music picker that ignores EXTRA_ALLOW_MULTIPLE — which is why documents ("*/*")
|
|
1734
|
+
// allowed multi-select but audio did not. "*/*" forces the multi-select DocumentsUI;
|
|
1735
|
+
// EXTRA_MIME_TYPES keeps it filtered to the requested kind.
|
|
1736
|
+
String mime = getType(fileType);
|
|
1737
|
+
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
|
1738
|
+
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
1739
|
+
intent.setType("*/*");
|
|
1740
|
+
if (mime != null && !mime.isEmpty() && !"*/*".equals(mime)) {
|
|
1741
|
+
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{ mime });
|
|
1742
|
+
}
|
|
1743
|
+
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, maxSelection != 1); // single-select when the cap is 1
|
|
1744
|
+
currentActivity.startActivityForResult(intent, READ_REQUEST_CODE_MULTI, Bundle.EMPTY);
|
|
1745
|
+
}
|
|
1746
|
+
} catch (ActivityNotFoundException e) {
|
|
1747
|
+
Log.e(TAG, "openFileChooserMulti: " + e.getMessage());
|
|
1748
|
+
} catch (Exception e) {
|
|
1749
|
+
Log.e(TAG, "openFileChooserMulti: " + e.getMessage());
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1672
1753
|
@ReactMethod
|
|
1673
1754
|
public void checkAndDownload(String url, String name, Callback callback) {
|
|
1674
|
-
Long downloadId = downloadFile(name, url);
|
|
1675
1755
|
try {
|
|
1756
|
+
if (fileExists(name)) {
|
|
1757
|
+
// Already downloaded — open it and report done
|
|
1758
|
+
openFileWithOption(name, ignored -> {});
|
|
1759
|
+
callback.invoke("{\"success\": true, \"alreadyExists\": true}");
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
Long downloadId = downloadFile(name, url);
|
|
1676
1763
|
if (downloadId == null) {
|
|
1677
|
-
callback.invoke("
|
|
1764
|
+
callback.invoke("{\"success\": false, \"error\": \"Download could not be started\"}");
|
|
1678
1765
|
return;
|
|
1679
1766
|
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1767
|
+
JSONObject result = new JSONObject();
|
|
1768
|
+
result.put("success", true);
|
|
1769
|
+
result.put("downloadId", downloadId.longValue());
|
|
1770
|
+
callback.invoke(result.toString());
|
|
1771
|
+
} catch (Exception e) {
|
|
1772
|
+
callback.invoke("{\"success\": false, \"error\": \"" + e.getMessage() + "\"}");
|
|
1685
1773
|
}
|
|
1686
|
-
callback.invoke(obj.toString());
|
|
1687
1774
|
}
|
|
1688
1775
|
|
|
1689
1776
|
@ReactMethod
|
|
@@ -2,7 +2,15 @@ package com.reactnativecometchatuikit
|
|
|
2
2
|
|
|
3
3
|
import android.content.ClipboardManager
|
|
4
4
|
import android.content.ClipData
|
|
5
|
+
import android.content.ContentResolver
|
|
5
6
|
import android.content.Context
|
|
7
|
+
import android.net.Uri
|
|
8
|
+
import android.provider.OpenableColumns
|
|
9
|
+
import android.webkit.MimeTypeMap
|
|
10
|
+
import androidx.core.view.ContentInfoCompat
|
|
11
|
+
import androidx.core.view.OnReceiveContentListener
|
|
12
|
+
import androidx.core.view.ViewCompat
|
|
13
|
+
import java.io.File
|
|
6
14
|
import android.graphics.Canvas
|
|
7
15
|
import android.graphics.Color
|
|
8
16
|
import android.graphics.Paint
|
|
@@ -377,10 +385,20 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
377
385
|
s.setSpan(ForegroundColorSpan(codeColor), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
|
|
378
386
|
}
|
|
379
387
|
"codeBlock" -> {
|
|
380
|
-
|
|
381
|
-
//
|
|
382
|
-
|
|
383
|
-
s.
|
|
388
|
+
// Only apply TypefaceSpan/ForegroundColorSpan if not already covered
|
|
389
|
+
// by an existing auto-extended span. Redundant overlapping spans cause
|
|
390
|
+
// Android's DynamicLayout to re-measure text multiple times (perf kill).
|
|
391
|
+
val existingMono = s.getSpans(spanStart, spanEnd, TypefaceSpan::class.java)
|
|
392
|
+
.any { it.family == "monospace" && s.getSpanStart(it) <= spanStart && s.getSpanEnd(it) >= spanEnd }
|
|
393
|
+
if (!existingMono) {
|
|
394
|
+
s.setSpan(TypefaceSpan("monospace"), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
|
|
395
|
+
}
|
|
396
|
+
val existingColor = s.getSpans(spanStart, spanEnd, ForegroundColorSpan::class.java)
|
|
397
|
+
.any { s.getSpanStart(it) <= spanStart && s.getSpanEnd(it) >= spanEnd }
|
|
398
|
+
if (!existingColor) {
|
|
399
|
+
val cbTextColor = if (isDarkMode()) Color.parseColor("#E0E0E0") else Color.parseColor("#333333")
|
|
400
|
+
s.setSpan(ForegroundColorSpan(cbTextColor), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
|
|
401
|
+
}
|
|
384
402
|
// Extend existing CodeBlockBorderSpan or create new one
|
|
385
403
|
val existingBorderSpans = s.getSpans(0, s.length, CodeBlockBorderSpan::class.java)
|
|
386
404
|
var extended = false
|
|
@@ -566,8 +584,10 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
566
584
|
renumberNumberedLists()
|
|
567
585
|
isInternalChange = false
|
|
568
586
|
}
|
|
587
|
+
|
|
569
588
|
// Apply hanging indent for lines with list/blockquote prefixes (ENG-31433)
|
|
570
589
|
applyListIndentation()
|
|
590
|
+
|
|
571
591
|
// Issue 1: When text becomes empty, reset all pending/explicit style toggles
|
|
572
592
|
if (s != null && s.isEmpty()) {
|
|
573
593
|
pendingStyles.clear()
|
|
@@ -733,6 +753,7 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
733
753
|
|
|
734
754
|
sendContentChangeWithDelta()
|
|
735
755
|
saveToUndoStack()
|
|
756
|
+
|
|
736
757
|
pendingDelta = null
|
|
737
758
|
}
|
|
738
759
|
previousText = s?.toString() ?: ""
|
|
@@ -740,6 +761,7 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
740
761
|
post {
|
|
741
762
|
updateContentSize()
|
|
742
763
|
invalidate()
|
|
764
|
+
|
|
743
765
|
// If line count changed (soft-wrap), schedule another redraw
|
|
744
766
|
// after the framework's layout pass to ensure onDraw sees
|
|
745
767
|
// the updated Layout with correct line positions.
|
|
@@ -764,9 +786,194 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
764
786
|
// Install text selection context menu (conditionally adds Bold/Italic/Underline/Strikethrough)
|
|
765
787
|
updateSelectionActionModeCallback()
|
|
766
788
|
|
|
789
|
+
// Install the OnReceiveContentListener so pasted rich content (images / files
|
|
790
|
+
// from Photos, file explorers, other apps) is intercepted, extracted to temp
|
|
791
|
+
// files, and surfaced to JS via the onPasteMedia event. Plain text pastes are
|
|
792
|
+
// returned unchanged so normal text-paste behavior is preserved.
|
|
793
|
+
installOnReceiveContentListener()
|
|
794
|
+
|
|
767
795
|
isInitialized = true
|
|
768
796
|
}
|
|
769
797
|
|
|
798
|
+
/**
|
|
799
|
+
* Registers a [OnReceiveContentListener] on this EditText via [ViewCompat] so that
|
|
800
|
+
* pasted (and drag-and-dropped) rich content is intercepted before the platform
|
|
801
|
+
* inserts it as text. This is the modern, backwards-compatible API (androidx.core);
|
|
802
|
+
* on API 31+ it is backed by the platform ON_RECEIVE_CONTENT infrastructure, and on
|
|
803
|
+
* older API levels androidx routes clipboard pastes through the same callback.
|
|
804
|
+
*
|
|
805
|
+
* Media (image, video, audio and application MIME types) is copied to a temp file in
|
|
806
|
+
* cacheDir and emitted to JS; plain text (and anything else) is passed through
|
|
807
|
+
* unchanged so the default paste/insert behavior is untouched.
|
|
808
|
+
*/
|
|
809
|
+
private fun installOnReceiveContentListener() {
|
|
810
|
+
// Register the concrete top-level MIME types we want a shot at. Android's
|
|
811
|
+
// setOnReceiveContentListener FORBIDS a "*/*" wildcard (the top-level type must be
|
|
812
|
+
// concrete — it throws IllegalArgumentException otherwise); the subtype "/*"
|
|
813
|
+
// wildcard is allowed. These cover images, video, audio, and every file kind
|
|
814
|
+
// (application/*, text/*). We still decide per-item below whether to consume
|
|
815
|
+
// (URI-backed media/files) or pass through (plain text has no URI).
|
|
816
|
+
val mimeTypes = arrayOf("image/*", "video/*", "audio/*", "application/*", "text/*")
|
|
817
|
+
val listener = OnReceiveContentListener { _, payload ->
|
|
818
|
+
handleReceivedContent(payload)
|
|
819
|
+
}
|
|
820
|
+
ViewCompat.setOnReceiveContentListener(this, mimeTypes, listener)
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Splits the incoming [ContentInfoCompat] payload into a media part (content:// URIs
|
|
825
|
+
* we extract) and a remaining part (text / anything else) that we hand back to the
|
|
826
|
+
* platform so normal paste continues. Returns the remaining payload, or null if we
|
|
827
|
+
* consumed everything.
|
|
828
|
+
*/
|
|
829
|
+
private fun handleReceivedContent(payload: ContentInfoCompat): ContentInfoCompat? {
|
|
830
|
+
// Partition the clip: URIs (potential media) vs. everything else (text, etc.).
|
|
831
|
+
val split = payload.partition { item -> item.uri != null }
|
|
832
|
+
val uriPayload: ContentInfoCompat? = split.first
|
|
833
|
+
val remaining: ContentInfoCompat? = split.second
|
|
834
|
+
|
|
835
|
+
if (uriPayload == null) {
|
|
836
|
+
// No URI content — this is a plain text (or other) paste. Pass through
|
|
837
|
+
// unchanged so normal text paste proceeds. Do NOT emit.
|
|
838
|
+
return payload
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
val emitted = try {
|
|
842
|
+
extractAndEmitMedia(uriPayload.clip)
|
|
843
|
+
} catch (e: Exception) {
|
|
844
|
+
e.printStackTrace()
|
|
845
|
+
false
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// If we could not extract anything usable from the URIs (e.g. resolver returned
|
|
849
|
+
// no stream), fall back to letting the platform handle the whole payload so we
|
|
850
|
+
// never silently swallow a paste.
|
|
851
|
+
return if (emitted) remaining else payload
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Iterates over each item in the pasted [ClipData], copies content:// (or file://)
|
|
856
|
+
* media to a temp file in cacheDir, and emits a single onPasteMedia event with an
|
|
857
|
+
* `items` array. Each item: { uri, mimeType, name, size }. Returns true if at least
|
|
858
|
+
* one item was successfully extracted and the event was emitted.
|
|
859
|
+
*/
|
|
860
|
+
private fun extractAndEmitMedia(clip: ClipData): Boolean {
|
|
861
|
+
val resolver = context.contentResolver
|
|
862
|
+
val items: WritableArray = Arguments.createArray()
|
|
863
|
+
|
|
864
|
+
for (i in 0 until clip.itemCount) {
|
|
865
|
+
val uri = clip.getItemAt(i)?.uri ?: continue
|
|
866
|
+
try {
|
|
867
|
+
val itemMap = copyUriToTempFileMap(resolver, uri) ?: continue
|
|
868
|
+
items.pushMap(itemMap)
|
|
869
|
+
} catch (e: Exception) {
|
|
870
|
+
// Skip items that fail; never crash on a single bad clipboard entry.
|
|
871
|
+
e.printStackTrace()
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
if (items.size() == 0) return false
|
|
876
|
+
|
|
877
|
+
val payload = Arguments.createMap()
|
|
878
|
+
payload.putArray("items", items)
|
|
879
|
+
sendEvent("onPasteMedia", payload)
|
|
880
|
+
return true
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Copies a single content:// / file:// [uri] to a temp file in cacheDir and returns
|
|
885
|
+
* a WritableMap of { uri (file://), mimeType (REAL type), name (with extension),
|
|
886
|
+
* size (bytes) }. Returns null if the URI could not be read.
|
|
887
|
+
*/
|
|
888
|
+
private fun copyUriToTempFileMap(resolver: ContentResolver, uri: Uri): WritableMap? {
|
|
889
|
+
// Resolve the REAL mime type via the content resolver (do NOT hardcode).
|
|
890
|
+
val mimeType = resolver.getType(uri)
|
|
891
|
+
?: MimeTypeMap.getSingleton()
|
|
892
|
+
.getMimeTypeFromExtension(
|
|
893
|
+
MimeTypeMap.getFileExtensionFromUrl(uri.toString()).lowercase()
|
|
894
|
+
)
|
|
895
|
+
?: "application/octet-stream"
|
|
896
|
+
|
|
897
|
+
// Resolve a display name + size from the resolver where possible.
|
|
898
|
+
val (resolvedName, resolvedSize) = queryNameAndSize(resolver, uri)
|
|
899
|
+
|
|
900
|
+
// Derive an extension: prefer the one on the resolved name, else map from mime.
|
|
901
|
+
val extFromMime = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType)
|
|
902
|
+
val hasExt = resolvedName?.substringAfterLast('.', "")?.isNotEmpty() == true
|
|
903
|
+
val baseName = when {
|
|
904
|
+
!resolvedName.isNullOrBlank() && hasExt -> resolvedName
|
|
905
|
+
!resolvedName.isNullOrBlank() -> {
|
|
906
|
+
if (!extFromMime.isNullOrBlank()) "$resolvedName.$extFromMime" else resolvedName
|
|
907
|
+
}
|
|
908
|
+
else -> {
|
|
909
|
+
val ext = if (!extFromMime.isNullOrBlank()) ".$extFromMime" else ""
|
|
910
|
+
"pasted_media_${System.currentTimeMillis()}$ext"
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
// Guard against illegal filename characters when building the temp file.
|
|
914
|
+
val safeName = baseName.replace(Regex("[^A-Za-z0-9._-]"), "_")
|
|
915
|
+
|
|
916
|
+
// Copy the stream to a uniquely-named temp file so multiple pastes don't collide.
|
|
917
|
+
val tempFile = File.createTempFile(
|
|
918
|
+
"paste_${System.currentTimeMillis()}_",
|
|
919
|
+
"_$safeName",
|
|
920
|
+
context.cacheDir
|
|
921
|
+
)
|
|
922
|
+
|
|
923
|
+
val copied = resolver.openInputStream(uri)?.use { input ->
|
|
924
|
+
tempFile.outputStream().use { output ->
|
|
925
|
+
input.copyTo(output)
|
|
926
|
+
}
|
|
927
|
+
true
|
|
928
|
+
} ?: false
|
|
929
|
+
|
|
930
|
+
if (!copied || !tempFile.exists() || tempFile.length() == 0L) {
|
|
931
|
+
tempFile.delete()
|
|
932
|
+
return null
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
val size = if (resolvedSize > 0L) resolvedSize else tempFile.length()
|
|
936
|
+
|
|
937
|
+
return Arguments.createMap().apply {
|
|
938
|
+
putString("uri", "file://${tempFile.absolutePath}")
|
|
939
|
+
putString("mimeType", mimeType)
|
|
940
|
+
putString("name", safeName)
|
|
941
|
+
// size is bytes; use double to avoid Int overflow for large files (>2GB safe).
|
|
942
|
+
putDouble("size", size.toDouble())
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Queries the content resolver for a display name and size. Returns Pair(name?, size).
|
|
948
|
+
* Size is -1 when unknown. Falls back gracefully for file:// URIs.
|
|
949
|
+
*/
|
|
950
|
+
private fun queryNameAndSize(resolver: ContentResolver, uri: Uri): Pair<String?, Long> {
|
|
951
|
+
var name: String? = null
|
|
952
|
+
var size = -1L
|
|
953
|
+
if (uri.scheme == ContentResolver.SCHEME_CONTENT) {
|
|
954
|
+
try {
|
|
955
|
+
resolver.query(uri, null, null, null, null)?.use { cursor ->
|
|
956
|
+
if (cursor.moveToFirst()) {
|
|
957
|
+
val nameIdx = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
|
958
|
+
if (nameIdx >= 0 && !cursor.isNull(nameIdx)) {
|
|
959
|
+
name = cursor.getString(nameIdx)
|
|
960
|
+
}
|
|
961
|
+
val sizeIdx = cursor.getColumnIndex(OpenableColumns.SIZE)
|
|
962
|
+
if (sizeIdx >= 0 && !cursor.isNull(sizeIdx)) {
|
|
963
|
+
size = cursor.getLong(sizeIdx)
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
} catch (e: Exception) {
|
|
968
|
+
e.printStackTrace()
|
|
969
|
+
}
|
|
970
|
+
} else {
|
|
971
|
+
// file:// or other — derive name from the last path segment.
|
|
972
|
+
name = uri.lastPathSegment
|
|
973
|
+
}
|
|
974
|
+
return Pair(name, size)
|
|
975
|
+
}
|
|
976
|
+
|
|
770
977
|
private fun setupToolbar() {
|
|
771
978
|
toolbarPopup = PopupWindow(context).apply {
|
|
772
979
|
width = WindowManager.LayoutParams.WRAP_CONTENT
|
|
@@ -789,12 +996,34 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
789
996
|
}
|
|
790
997
|
|
|
791
998
|
override fun onPrepareActionMode(mode: android.view.ActionMode?, menu: android.view.Menu?): Boolean {
|
|
999
|
+
// Insertion action mode = long-press / cursor tap with NO selection (e.g. an
|
|
1000
|
+
// empty composer). Rebuild the menu so the system "Paste" bubble is available
|
|
1001
|
+
// — this is what lets the user paste an image/file into an empty composer.
|
|
1002
|
+
// (Previously the menu was cleared and left empty, so no Paste ever appeared.)
|
|
1003
|
+
// Paste is offered only when the clipboard has content; "Select all" is added
|
|
1004
|
+
// when there is text to select.
|
|
792
1005
|
menu?.clear()
|
|
1006
|
+
val clipboard =
|
|
1007
|
+
context.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
|
|
1008
|
+
if (clipboard?.hasPrimaryClip() == true) {
|
|
1009
|
+
menu?.add(0, android.R.id.paste, 0, android.R.string.paste)
|
|
1010
|
+
}
|
|
1011
|
+
if ((text?.length ?: 0) > 0) {
|
|
1012
|
+
menu?.add(0, android.R.id.selectAll, 1, android.R.string.selectAll)
|
|
1013
|
+
}
|
|
793
1014
|
return true
|
|
794
1015
|
}
|
|
795
1016
|
|
|
796
1017
|
override fun onActionItemClicked(mode: android.view.ActionMode?, item: android.view.MenuItem?): Boolean {
|
|
797
|
-
return
|
|
1018
|
+
return when (item?.itemId) {
|
|
1019
|
+
android.R.id.paste -> {
|
|
1020
|
+
onTextContextMenuItem(android.R.id.paste); mode?.finish(); true
|
|
1021
|
+
}
|
|
1022
|
+
android.R.id.selectAll -> {
|
|
1023
|
+
onTextContextMenuItem(android.R.id.selectAll); true
|
|
1024
|
+
}
|
|
1025
|
+
else -> false
|
|
1026
|
+
}
|
|
798
1027
|
}
|
|
799
1028
|
|
|
800
1029
|
override fun onDestroyActionMode(mode: android.view.ActionMode?) {}
|
|
@@ -999,7 +1228,7 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
999
1228
|
val textBaseY = paddingTop + gravityOffsetY
|
|
1000
1229
|
|
|
1001
1230
|
// ── Code block containers (unified rect per region, matching iOS) ──
|
|
1002
|
-
val spannable = text as? Spanned
|
|
1231
|
+
val spannable = text as? Spanned ?: run { super.onDraw(canvas); return }
|
|
1003
1232
|
if (spannable != null && textLayout != null) {
|
|
1004
1233
|
// 1. Find all code block regions by merging overlapping CodeBlockBorderSpan ranges.
|
|
1005
1234
|
// Only merge spans that truly overlap or are directly adjacent within the
|
|
@@ -2742,6 +2971,8 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
2742
2971
|
"onSizeChange" -> "topSizeChange"
|
|
2743
2972
|
"onActiveStylesChange" -> "topActiveStylesChange"
|
|
2744
2973
|
"onLinkTap" -> "topLinkTap"
|
|
2974
|
+
"onSendRequest" -> "topSendRequest"
|
|
2975
|
+
"onPasteMedia" -> "topPasteMedia"
|
|
2745
2976
|
else -> eventName
|
|
2746
2977
|
}
|
|
2747
2978
|
|
|
@@ -446,7 +446,8 @@ class RichTextEditorViewManager : SimpleViewManager<LinearLayout>() {
|
|
|
446
446
|
"topSizeChange" to mapOf("registrationName" to "onSizeChange"),
|
|
447
447
|
"topActiveStylesChange" to mapOf("registrationName" to "onActiveStylesChange"),
|
|
448
448
|
"topLinkTap" to mapOf("registrationName" to "onLinkTap"),
|
|
449
|
-
"topSendRequest" to mapOf("registrationName" to "onSendRequest")
|
|
449
|
+
"topSendRequest" to mapOf("registrationName" to "onSendRequest"),
|
|
450
|
+
"topPasteMedia" to mapOf("registrationName" to "onPasteMedia")
|
|
450
451
|
)
|
|
451
452
|
}
|
|
452
453
|
}
|