@cometchat/chat-uikit-react-native 5.5.0 → 5.5.2
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/fileHashes/fileHashes.lock +0 -0
- package/android/build.gradle +23 -89
- package/android/gradle.properties +5 -5
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatSoundModule.java +5 -1
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +52 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +37 -4
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +9 -1
- package/ios/FileManager.m +77 -3
- package/ios/RichTextEditorView.swift +52 -1
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/RichTextEditorViewManager.swift +8 -0
- package/package.json +8 -5
- package/react-native-cometchat-ui-kit.podspec +5 -19
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +69 -36
- package/src/CometChatConversations/CometChatConversations.tsx +12 -1
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +2 -2
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +50 -31
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +10 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +24 -19
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +7 -8
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +43 -19
- package/src/CometChatRichTextEditor/index.tsx +6 -1
- package/src/CometChatRichTextEditor/types.ts +2 -0
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +251 -14
- package/src/CometChatSearch/CometChatSearch.tsx +39 -11
- package/src/calls/CometChatOngoingCall/CometChatOngoingCall.tsx +56 -17
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +12 -9
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +13 -10
- package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +34 -27
- package/src/extensions/Polls/Polls.tsx +7 -7
- package/src/extensions/Polls/PollsBubble.tsx +2 -2
- package/src/globals.d.ts +6 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +2 -1
- package/src/shared/constants/UIKitConstants.ts +3 -17
- package/src/shared/constants/textPatterns.ts +45 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +25 -259
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +22 -11
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +56 -32
- package/src/shared/formatters/CometChatTextFormatter.ts +22 -0
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +8 -0
- package/src/shared/formatters/applyRawFormatters.ts +31 -0
- package/src/shared/formatters/codeElements.ts +21 -0
- package/src/shared/framework/MessageDataSource.tsx +14 -8
- package/src/shared/helper/types/index.ts +5 -0
- package/src/shared/libs/ImageZoom/ReactNativeZoomableView.tsx +4 -4
- package/src/shared/libs/ImageZoom/types/index.ts +2 -0
- package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +15 -30
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +138 -19
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +0 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +54 -1
- package/src/shared/resources/CometChatSoundManager/sound.js +2 -3
- package/src/shared/services/UploadQueueService.ts +7 -0
- package/src/shared/utils/CometChatMessageHelper/index.ts +3 -0
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +11 -0
- package/src/shared/utils/MarkdownUtils.ts +42 -5
- package/src/shared/utils/MessageUtils.tsx +7 -5
- package/src/shared/utils/PinnedMessagesHelper.ts +65 -0
- package/src/shared/utils/SavedMessagesHelper.ts +42 -6
- package/src/shared/utils/__testUtils__/messagesRequestBuilderMock.ts +37 -0
- package/src/shared/utils/cloneRequestBuilder.ts +25 -0
- package/src/shared/utils/groupMemberAddedRows.ts +28 -0
- package/src/shared/utils/linkPreviewSelection.ts +109 -0
- package/src/shared/utils/mentionTokens.ts +77 -0
- package/src/shared/utils/runAfterInteractions.ts +26 -0
- package/src/shared/utils/stripRichText.ts +2 -1
- package/src/shared/utils/tapGesture.ts +23 -0
- package/src/shared/utils/videoThumbnail.ts +74 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +15 -4
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +21 -13
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +13 -15
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +5 -0
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +4 -1
- package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +8 -1
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +1 -1
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +2 -1
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +7 -1
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +8 -26
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +4 -2
- package/src/shared/views/CometChatList/Header.tsx +9 -3
- package/src/shared/views/CometChatMediaRecorder/CometChatAudioPreview/CometChatAudioPreview.tsx +2 -1
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +28 -8
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -4
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +36 -4
- package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +2 -1
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +62 -30
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +5 -0
- package/src/CometChatMessageList/MANUAL_TEST_CASES.md +0 -154
|
Binary file
|
|
Binary file
|
package/android/build.gradle
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
mavenCentral()
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
dependencies {
|
|
8
|
-
classpath 'com.android.tools.build:gradle:4.2.0'
|
|
9
|
-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
// AGP and the Kotlin Gradle plugin come from the host app's root project (as in every RN
|
|
2
|
+
// template since 0.71). Pinning them here via a `buildscript` block fights the app's own
|
|
3
|
+
// versions — AGP 9 / Gradle 9 (RN 0.87) will not build with the old pins at all.
|
|
12
4
|
|
|
13
5
|
def isNewArchitectureEnabled() {
|
|
14
6
|
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
15
7
|
}
|
|
16
8
|
|
|
17
9
|
apply plugin: 'com.android.library'
|
|
18
|
-
|
|
10
|
+
|
|
11
|
+
// AGP 9 can compile Kotlin itself ("built-in Kotlin"), and applying kotlin-android on top of
|
|
12
|
+
// that fails. Apply it only when nothing has registered the `kotlin` extension yet, so this
|
|
13
|
+
// works both on AGP 9 and on the AGP 8 apps of older RN versions.
|
|
14
|
+
if (project.extensions.findByName("kotlin") == null) {
|
|
15
|
+
apply plugin: 'org.jetbrains.kotlin.android'
|
|
16
|
+
}
|
|
19
17
|
|
|
20
18
|
if (isNewArchitectureEnabled()) {
|
|
21
19
|
apply plugin: 'com.facebook.react'
|
|
@@ -30,6 +28,7 @@ def getExtOrIntegerDefault(name) {
|
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
android {
|
|
31
|
+
namespace "com.reactnativecometchatuikit"
|
|
33
32
|
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
|
|
34
33
|
|
|
35
34
|
defaultConfig {
|
|
@@ -37,102 +36,37 @@ android {
|
|
|
37
36
|
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
|
|
38
37
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
39
38
|
}
|
|
39
|
+
|
|
40
|
+
buildFeatures {
|
|
41
|
+
buildConfig true
|
|
42
|
+
}
|
|
43
|
+
|
|
40
44
|
buildTypes {
|
|
41
45
|
release {
|
|
42
46
|
minifyEnabled false
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
lint {
|
|
47
51
|
disable 'GradleCompatible'
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
compileOptions {
|
|
51
|
-
sourceCompatibility JavaVersion.
|
|
52
|
-
targetCompatibility JavaVersion.
|
|
55
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
56
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
53
57
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
repositories {
|
|
59
61
|
mavenCentral()
|
|
60
62
|
google()
|
|
61
|
-
|
|
62
|
-
def found = false
|
|
63
|
-
def defaultDir = null
|
|
64
|
-
def androidSourcesName = 'React Native sources'
|
|
65
|
-
|
|
66
|
-
if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
|
67
|
-
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
|
68
|
-
} else {
|
|
69
|
-
defaultDir = new File(
|
|
70
|
-
projectDir,
|
|
71
|
-
'/../../../node_modules/react-native/android'
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (defaultDir.exists()) {
|
|
76
|
-
maven {
|
|
77
|
-
url defaultDir.toString()
|
|
78
|
-
name androidSourcesName
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
|
|
82
|
-
found = true
|
|
83
|
-
} else {
|
|
84
|
-
def parentDir = rootProject.projectDir
|
|
85
|
-
|
|
86
|
-
1.upto(5, {
|
|
87
|
-
if (found) return true
|
|
88
|
-
parentDir = parentDir.parentFile
|
|
89
|
-
|
|
90
|
-
def androidSourcesDir = new File(
|
|
91
|
-
parentDir,
|
|
92
|
-
'node_modules/react-native'
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
def androidPrebuiltBinaryDir = new File(
|
|
96
|
-
parentDir,
|
|
97
|
-
'node_modules/react-native/android'
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
if (androidPrebuiltBinaryDir.exists()) {
|
|
101
|
-
maven {
|
|
102
|
-
url androidPrebuiltBinaryDir.toString()
|
|
103
|
-
name androidSourcesName
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
|
|
107
|
-
found = true
|
|
108
|
-
} else if (androidSourcesDir.exists()) {
|
|
109
|
-
maven {
|
|
110
|
-
url androidSourcesDir.toString()
|
|
111
|
-
name androidSourcesName
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
|
|
115
|
-
found = true
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (!found) {
|
|
121
|
-
throw new GradleException(
|
|
122
|
-
"${project.name}: unable to locate React Native android sources. " +
|
|
123
|
-
"Ensure you have you installed React Native as a dependency in your project and try again."
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
63
|
}
|
|
127
64
|
|
|
128
|
-
|
|
129
65
|
dependencies {
|
|
130
|
-
|
|
131
|
-
implementation "com.facebook.react:react-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.22"
|
|
135
|
-
// From node_modules
|
|
66
|
+
// Version is supplied by the React Native Gradle Plugin of the host app.
|
|
67
|
+
implementation "com.facebook.react:react-android"
|
|
68
|
+
implementation 'androidx.appcompat:appcompat:1.7.1'
|
|
69
|
+
implementation 'com.google.android.material:material:1.12.0'
|
|
136
70
|
}
|
|
137
71
|
|
|
138
72
|
if (isNewArchitectureEnabled()) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
CometchatUiKit_kotlinVersion=
|
|
2
|
-
CometchatUiKit_minSdkVersion=
|
|
3
|
-
CometchatUiKit_targetSdkVersion=
|
|
4
|
-
CometchatUiKit_compileSdkVersion=
|
|
5
|
-
CometchatUiKit_ndkversion=
|
|
1
|
+
CometchatUiKit_kotlinVersion=2.2.0
|
|
2
|
+
CometchatUiKit_minSdkVersion=24
|
|
3
|
+
CometchatUiKit_targetSdkVersion=36
|
|
4
|
+
CometchatUiKit_compileSdkVersion=36
|
|
5
|
+
CometchatUiKit_ndkversion=27.1.12297006
|
|
@@ -397,8 +397,12 @@ public class CometChatSoundModule
|
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
+
// `invalidate()`, not the deprecated onCatalystInstanceDestroy(): bridgeless RN (0.82+ is
|
|
401
|
+
// New-Architecture-only) tears modules down through invalidate(), so the old hook can be
|
|
402
|
+
// skipped and every pooled MediaPlayer would leak.
|
|
400
403
|
@Override
|
|
401
|
-
public void
|
|
404
|
+
public void invalidate() {
|
|
405
|
+
super.invalidate();
|
|
402
406
|
java.util.Iterator it = this.playerPool.entrySet().iterator();
|
|
403
407
|
while (it.hasNext()) {
|
|
404
408
|
Map.Entry entry = (Map.Entry) it.next();
|
|
@@ -18,6 +18,7 @@ import android.graphics.Bitmap;
|
|
|
18
18
|
import android.graphics.BitmapFactory;
|
|
19
19
|
import android.graphics.Matrix;
|
|
20
20
|
import android.media.ExifInterface;
|
|
21
|
+
import android.media.MediaMetadataRetriever;
|
|
21
22
|
import android.media.MediaPlayer;
|
|
22
23
|
import android.media.MediaRecorder;
|
|
23
24
|
import android.net.Uri;
|
|
@@ -725,6 +726,57 @@ public class FileManager extends ReactContextBaseJavaModule {
|
|
|
725
726
|
}
|
|
726
727
|
}
|
|
727
728
|
|
|
729
|
+
// Small JPEG of a local video's first frame, so a picked/sent video has a thumbnail without waiting
|
|
730
|
+
// for the server's thumbnail-generation extension (which publishes its URL before the image exists).
|
|
731
|
+
// Cached in cacheDir by source uri, so repeat calls for the same file are instant.
|
|
732
|
+
@ReactMethod
|
|
733
|
+
public void getVideoThumbnail(String uri, double maxSize, Promise promise) {
|
|
734
|
+
Executors.newSingleThreadExecutor().execute(() -> {
|
|
735
|
+
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
|
736
|
+
try {
|
|
737
|
+
int side = maxSize > 0 ? (int) maxSize : 320;
|
|
738
|
+
File dir = new File(getReactApplicationContext().getCacheDir(), "cometchat-video-thumbnails");
|
|
739
|
+
if (!dir.exists()) dir.mkdirs();
|
|
740
|
+
File thumb = new File(dir, Integer.toHexString(uri.hashCode()) + "_" + uri.length() + "_" + side + ".jpg");
|
|
741
|
+
if (thumb.exists()) {
|
|
742
|
+
promise.resolve(Uri.fromFile(thumb).toString());
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
Uri source = uri.startsWith("/") ? Uri.fromFile(new File(uri)) : Uri.parse(uri);
|
|
747
|
+
retriever.setDataSource(getReactApplicationContext(), source);
|
|
748
|
+
Bitmap frame;
|
|
749
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
|
750
|
+
frame = retriever.getScaledFrameAtTime(100_000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC, side, side);
|
|
751
|
+
} else {
|
|
752
|
+
Bitmap full = retriever.getFrameAtTime(100_000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
|
|
753
|
+
frame = full == null ? null : scaleToFit(full, side);
|
|
754
|
+
}
|
|
755
|
+
if (frame == null) {
|
|
756
|
+
promise.reject("thumbnail_failed", "Could not read a video frame");
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
try (FileOutputStream out = new FileOutputStream(thumb)) {
|
|
760
|
+
frame.compress(Bitmap.CompressFormat.JPEG, 80, out);
|
|
761
|
+
}
|
|
762
|
+
frame.recycle();
|
|
763
|
+
promise.resolve(Uri.fromFile(thumb).toString());
|
|
764
|
+
} catch (Exception e) {
|
|
765
|
+
promise.reject("thumbnail_failed", e.getMessage(), e);
|
|
766
|
+
} finally {
|
|
767
|
+
try { retriever.release(); } catch (Exception ignored) { }
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
private static Bitmap scaleToFit(Bitmap source, int side) {
|
|
773
|
+
float scale = Math.min(1f, side / (float) Math.max(source.getWidth(), source.getHeight()));
|
|
774
|
+
if (scale >= 1f) return source;
|
|
775
|
+
Bitmap scaled = Bitmap.createScaledBitmap(source, Math.round(source.getWidth() * scale), Math.round(source.getHeight() * scale), true);
|
|
776
|
+
source.recycle();
|
|
777
|
+
return scaled;
|
|
778
|
+
}
|
|
779
|
+
|
|
728
780
|
@ReactMethod
|
|
729
781
|
public void pauseRecording(Promise promise) {
|
|
730
782
|
if (audioRecorder != null) {
|
|
@@ -383,9 +383,14 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
383
383
|
changeStart = start
|
|
384
384
|
removedCount = count
|
|
385
385
|
addedCount = after
|
|
386
|
-
// Save selected text for URL-paste-over-selection detection
|
|
387
|
-
//
|
|
388
|
-
|
|
386
|
+
// Save selected text for URL-paste-over-selection detection: a replace counts only when
|
|
387
|
+
// the user had exactly that text highlighted. Keyboards also replace text while typing
|
|
388
|
+
// (rewriting "www" -> "Www.", autocorrect) but with a bare cursor, and those must not
|
|
389
|
+
// become links. No clipboard read here: Android 12+ toasts on every read.
|
|
390
|
+
val selStart = minOf(selectionStart, selectionEnd)
|
|
391
|
+
val selEnd = maxOf(selectionStart, selectionEnd)
|
|
392
|
+
if (count > 0 && after > 0 && s != null && start + count <= s.length &&
|
|
393
|
+
selStart != selEnd && selStart == start && selEnd == start + count) {
|
|
389
394
|
savedSelectedTextForPaste = s.subSequence(start, start + count).toString()
|
|
390
395
|
} else {
|
|
391
396
|
savedSelectedTextForPaste = null
|
|
@@ -2924,8 +2929,16 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
2924
2929
|
if (j >= chars.size) return null
|
|
2925
2930
|
if (j + 1 >= chars.size || chars[j + 1] != '(') return null
|
|
2926
2931
|
val urlStart = j + 2
|
|
2932
|
+
// Balanced: `(planet)` inside the address is kept and only an unmatched `)` closes the
|
|
2933
|
+
// link. Stopping at the first `)` turned a pasted [Mercury](…/Mercury_(planet)) into
|
|
2934
|
+
// "Mercury" linking to …/Mercury_(planet plus a stray ")".
|
|
2927
2935
|
var k = urlStart
|
|
2928
|
-
|
|
2936
|
+
var depth = 0
|
|
2937
|
+
while (k < chars.size) {
|
|
2938
|
+
if (chars[k] == '(') depth++
|
|
2939
|
+
else if (chars[k] == ')') { if (depth == 0) break; depth-- }
|
|
2940
|
+
k++
|
|
2941
|
+
}
|
|
2929
2942
|
if (k >= chars.size) return null
|
|
2930
2943
|
val linkText = String(chars, from + 1, j - from - 1)
|
|
2931
2944
|
val linkURL = String(chars, urlStart, k - urlStart)
|
|
@@ -5514,6 +5527,26 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
5514
5527
|
sendContentChange()
|
|
5515
5528
|
}
|
|
5516
5529
|
|
|
5530
|
+
/**
|
|
5531
|
+
* Replaces the current selection with plain text, or inserts at the caret when nothing is
|
|
5532
|
+
* selected — the editor-side half of a consumer's toolbar button.
|
|
5533
|
+
*
|
|
5534
|
+
* The run is inserted without carrying the spans of whatever it replaced, so a consumer's own
|
|
5535
|
+
* wire token lands as plain characters rather than inheriting the styling around it.
|
|
5536
|
+
*/
|
|
5537
|
+
fun replaceSelection(replacement: String) {
|
|
5538
|
+
val editable = text ?: return
|
|
5539
|
+
val start = selectionStart.coerceAtMost(selectionEnd).coerceIn(0, editable.length)
|
|
5540
|
+
val end = selectionStart.coerceAtLeast(selectionEnd).coerceIn(0, editable.length)
|
|
5541
|
+
|
|
5542
|
+
isInternalChange = true
|
|
5543
|
+
editable.replace(start, end, replacement)
|
|
5544
|
+
isInternalChange = false
|
|
5545
|
+
|
|
5546
|
+
setSelection((start + replacement.length).coerceAtMost(text?.length ?: 0))
|
|
5547
|
+
sendContentChange()
|
|
5548
|
+
}
|
|
5549
|
+
|
|
5517
5550
|
fun removeLink(location: Int, length: Int) {
|
|
5518
5551
|
val editable = text ?: return
|
|
5519
5552
|
val end = location + length
|
|
@@ -33,6 +33,7 @@ class RichTextEditorViewManager : SimpleViewManager<LinearLayout>() {
|
|
|
33
33
|
const val COMMAND_SET_CHECKLIST = "setChecklist"
|
|
34
34
|
const val COMMAND_SET_PARAGRAPH = "setParagraph"
|
|
35
35
|
const val COMMAND_INSERT_LINK = "insertLink"
|
|
36
|
+
const val COMMAND_REPLACE_SELECTION = "replaceSelection"
|
|
36
37
|
const val COMMAND_UNDO = "undo"
|
|
37
38
|
const val COMMAND_REDO = "redo"
|
|
38
39
|
const val COMMAND_CLEAR_FORMATTING = "clearFormatting"
|
|
@@ -127,7 +128,8 @@ class RichTextEditorViewManager : SimpleViewManager<LinearLayout>() {
|
|
|
127
128
|
COMMAND_REMOVE_LINK to 31,
|
|
128
129
|
COMMAND_UPDATE_LINK to 32,
|
|
129
130
|
COMMAND_APPLY_INLINE_STYLE to 33,
|
|
130
|
-
COMMAND_REMOVE_INLINE_STYLE to 34
|
|
131
|
+
COMMAND_REMOVE_INLINE_STYLE to 34,
|
|
132
|
+
COMMAND_REPLACE_SELECTION to 35
|
|
131
133
|
)
|
|
132
134
|
}
|
|
133
135
|
|
|
@@ -162,6 +164,12 @@ class RichTextEditorViewManager : SimpleViewManager<LinearLayout>() {
|
|
|
162
164
|
view.insertLink(url, linkText)
|
|
163
165
|
}
|
|
164
166
|
}
|
|
167
|
+
COMMAND_REPLACE_SELECTION -> {
|
|
168
|
+
val replacement = args?.getString(0) ?: ""
|
|
169
|
+
if (replacement.isNotEmpty()) {
|
|
170
|
+
view.replaceSelection(replacement)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
165
173
|
COMMAND_UNDO -> view.onUndoClick()
|
|
166
174
|
COMMAND_REDO -> view.onRedoClick()
|
|
167
175
|
COMMAND_CLEAR_FORMATTING -> view.onClearFormattingClick()
|
package/ios/FileManager.m
CHANGED
|
@@ -53,6 +53,16 @@ static NSString *const FIELD_SIZE = @"size";
|
|
|
53
53
|
hasListeners = YES;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
// The pickers share one `callback` slot, so a picker must TAKE it the moment it finishes (and clear the
|
|
57
|
+
// slot) rather than read it later. Otherwise a slow pick (PHPicker loading several videos) fires whatever
|
|
58
|
+
// callback a NEWER pick stored in the meantime — invoking that block twice, which RN aborts on
|
|
59
|
+
// ("Callback arg cannot be called more than once").
|
|
60
|
+
- (RCTResponseSenderBlock)takeCallback {
|
|
61
|
+
RCTResponseSenderBlock cb = callback;
|
|
62
|
+
callback = nil;
|
|
63
|
+
return cb;
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
- (void)stopObserving {
|
|
57
67
|
hasListeners = NO;
|
|
58
68
|
}
|
|
@@ -372,6 +382,52 @@ RCT_EXPORT_METHOD(openFileChooser:(NSString *)type callback:(RCTResponseSenderBl
|
|
|
372
382
|
}
|
|
373
383
|
|
|
374
384
|
|
|
385
|
+
// Small JPEG of a local video's first frame, so a picked/sent video has a thumbnail without waiting for
|
|
386
|
+
// the server's thumbnail-generation extension (which publishes its URL before the image exists).
|
|
387
|
+
// Cached in Caches/ by source path, so repeat calls for the same file are instant.
|
|
388
|
+
RCT_EXPORT_METHOD(getVideoThumbnail:(NSString *)uri maxSize:(nonnull NSNumber *)maxSize resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
389
|
+
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
|
|
390
|
+
NSURL *videoURL = [uri hasPrefix:@"/"] ? [NSURL fileURLWithPath:uri] : [NSURL URLWithString:uri];
|
|
391
|
+
if (!videoURL) {
|
|
392
|
+
reject(@"invalid_uri", @"Invalid video uri", nil);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
NSString *dir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject
|
|
396
|
+
stringByAppendingPathComponent:@"cometchat-video-thumbnails"];
|
|
397
|
+
[[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
|
|
398
|
+
NSString *key = [NSString stringWithFormat:@"%lu_%lu_%@", (unsigned long)videoURL.path.hash,
|
|
399
|
+
(unsigned long)videoURL.path.length, maxSize];
|
|
400
|
+
NSString *thumbPath = [dir stringByAppendingPathComponent:[key stringByAppendingPathExtension:@"jpg"]];
|
|
401
|
+
if ([[NSFileManager defaultManager] fileExistsAtPath:thumbPath]) {
|
|
402
|
+
resolve([NSURL fileURLWithPath:thumbPath].absoluteString);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
|
|
407
|
+
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
|
|
408
|
+
generator.appliesPreferredTrackTransform = YES; // keep portrait videos upright
|
|
409
|
+
CGFloat side = maxSize.doubleValue > 0 ? maxSize.doubleValue : 320;
|
|
410
|
+
generator.maximumSize = CGSizeMake(side, side);
|
|
411
|
+
// Nearest keyframe is fine for a preview and much faster than an exact frame.
|
|
412
|
+
generator.requestedTimeToleranceBefore = kCMTimePositiveInfinity;
|
|
413
|
+
generator.requestedTimeToleranceAfter = kCMTimePositiveInfinity;
|
|
414
|
+
|
|
415
|
+
NSError *error = nil;
|
|
416
|
+
CGImageRef cgImage = [generator copyCGImageAtTime:CMTimeMakeWithSeconds(0.1, 600) actualTime:NULL error:&error];
|
|
417
|
+
if (!cgImage) {
|
|
418
|
+
reject(@"thumbnail_failed", error.localizedDescription ?: @"Could not read a video frame", error);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
NSData *jpeg = UIImageJPEGRepresentation([UIImage imageWithCGImage:cgImage], 0.8);
|
|
422
|
+
CGImageRelease(cgImage);
|
|
423
|
+
if (![jpeg writeToFile:thumbPath atomically:YES]) {
|
|
424
|
+
reject(@"thumbnail_failed", @"Could not write the thumbnail", nil);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
resolve([NSURL fileURLWithPath:thumbPath].absoluteString);
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
|
|
375
431
|
RCT_EXPORT_METHOD(openFileChooserMulti:(NSString *)type maxSelection:(nonnull NSNumber *)maxSelection callback:(RCTResponseSenderBlock)call) {
|
|
376
432
|
callback = call;
|
|
377
433
|
UIViewController *presentedViewController = RCTPresentedViewController();
|
|
@@ -1104,6 +1160,11 @@ RCT_EXPORT_METHOD(clearSegments:(RCTResponseSenderBlock)callback) {
|
|
|
1104
1160
|
|
|
1105
1161
|
- (void)imagePickerController:(UIImagePickerController *)picker
|
|
1106
1162
|
didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info {
|
|
1163
|
+
RCTResponseSenderBlock callback = [self takeCallback];
|
|
1164
|
+
if (!callback) {
|
|
1165
|
+
[picker dismissViewControllerAnimated:TRUE completion:nil];
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1107
1168
|
switch (picker.sourceType) {
|
|
1108
1169
|
case UIImagePickerControllerSourceTypeCamera: {
|
|
1109
1170
|
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
|
|
@@ -1180,7 +1241,12 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
|
|
|
1180
1241
|
// PHPickerViewControllerDelegate — handles multi-select from Photos library (images and videos)
|
|
1181
1242
|
- (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results {
|
|
1182
1243
|
[picker dismissViewControllerAnimated:YES completion:nil];
|
|
1244
|
+
RCTResponseSenderBlock callback = [self takeCallback];
|
|
1245
|
+
if (!callback) {
|
|
1246
|
+
return;
|
|
1247
|
+
}
|
|
1183
1248
|
if (results.count == 0) {
|
|
1249
|
+
callback(@[@[]]);
|
|
1184
1250
|
return;
|
|
1185
1251
|
}
|
|
1186
1252
|
|
|
@@ -1229,9 +1295,7 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
|
|
|
1229
1295
|
}
|
|
1230
1296
|
|
|
1231
1297
|
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
|
1232
|
-
|
|
1233
|
-
callback(@[fileInfoArray]);
|
|
1234
|
-
}
|
|
1298
|
+
callback(@[fileInfoArray]);
|
|
1235
1299
|
});
|
|
1236
1300
|
}
|
|
1237
1301
|
|
|
@@ -1248,6 +1312,11 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
|
|
|
1248
1312
|
}
|
|
1249
1313
|
|
|
1250
1314
|
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
|
|
1315
|
+
RCTResponseSenderBlock callback = [self takeCallback];
|
|
1316
|
+
if (!callback) {
|
|
1317
|
+
_multipleSelection = NO;
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1251
1320
|
if (_multipleSelection) {
|
|
1252
1321
|
_multipleSelection = NO;
|
|
1253
1322
|
NSMutableArray *results = [NSMutableArray array];
|
|
@@ -1273,6 +1342,11 @@ didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id>
|
|
|
1273
1342
|
|
|
1274
1343
|
- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
|
|
1275
1344
|
NSLog(@"document pick cancelled");
|
|
1345
|
+
if (_multipleSelection) {
|
|
1346
|
+
_multipleSelection = NO;
|
|
1347
|
+
RCTResponseSenderBlock callback = [self takeCallback];
|
|
1348
|
+
if (callback) callback(@[@[]]);
|
|
1349
|
+
}
|
|
1276
1350
|
[controller dismissViewControllerAnimated:TRUE completion:nil];
|
|
1277
1351
|
}
|
|
1278
1352
|
|
|
@@ -3141,6 +3141,11 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
3141
3141
|
|
|
3142
3142
|
/// Returns true when a UTI represents pasteable media (image/video/audio/file),
|
|
3143
3143
|
/// and false for plain text / URLs which should paste as text.
|
|
3144
|
+
///
|
|
3145
|
+
/// Rich-text containers are excluded too. Copying TEXT puts one on the pasteboard next to
|
|
3146
|
+
/// the plain string — Safari adds a web archive, Notes / Mail / Pages / TextEdit add RTFD.
|
|
3147
|
+
/// Both conform to public.data, so without this a text copy from those apps was uploaded
|
|
3148
|
+
/// as a WEBARCHIVE / RTFD attachment and the text itself was never pasted.
|
|
3144
3149
|
private static func isMediaTypeIdentifier(_ typeId: String) -> Bool {
|
|
3145
3150
|
if #available(iOS 14.0, *) {
|
|
3146
3151
|
guard let type = UTType(typeId) else { return false }
|
|
@@ -3148,6 +3153,9 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
3148
3153
|
if type.conforms(to: .plainText) || type.conforms(to: .url) || type.conforms(to: .text) {
|
|
3149
3154
|
return false
|
|
3150
3155
|
}
|
|
3156
|
+
if type.conforms(to: .webArchive) || type.conforms(to: .rtfd) || type.conforms(to: .flatRTFD) {
|
|
3157
|
+
return false
|
|
3158
|
+
}
|
|
3151
3159
|
return type.conforms(to: .image)
|
|
3152
3160
|
|| type.conforms(to: .movie)
|
|
3153
3161
|
|| type.conforms(to: .audio)
|
|
@@ -3160,6 +3168,9 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
3160
3168
|
if UTTypeConformsTo(cf, kUTTypePlainText) || UTTypeConformsTo(cf, kUTTypeText) || UTTypeConformsTo(cf, kUTTypeURL) {
|
|
3161
3169
|
return false
|
|
3162
3170
|
}
|
|
3171
|
+
if UTTypeConformsTo(cf, kUTTypeWebArchive) || UTTypeConformsTo(cf, kUTTypeRTFD) || UTTypeConformsTo(cf, kUTTypeFlatRTFD) {
|
|
3172
|
+
return false
|
|
3173
|
+
}
|
|
3163
3174
|
return UTTypeConformsTo(cf, kUTTypeImage)
|
|
3164
3175
|
|| UTTypeConformsTo(cf, kUTTypeMovie)
|
|
3165
3176
|
|| UTTypeConformsTo(cf, kUTTypeAudio)
|
|
@@ -5292,6 +5303,38 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
5292
5303
|
emitActiveStyles()
|
|
5293
5304
|
}
|
|
5294
5305
|
|
|
5306
|
+
/// Replaces the current selection with plain text, or inserts at the caret when nothing is
|
|
5307
|
+
/// selected — the editor-side half of a consumer's toolbar button.
|
|
5308
|
+
///
|
|
5309
|
+
/// The run goes in with the editor's current typing attributes rather than the attributes of
|
|
5310
|
+
/// whatever it replaced, so a consumer's own wire token lands as plain characters instead of
|
|
5311
|
+
/// inheriting, say, the bold of the word it wrapped.
|
|
5312
|
+
func replaceSelection(with text: String) {
|
|
5313
|
+
let range = textView.selectedRange
|
|
5314
|
+
let mutableAttrString = NSMutableAttributedString(attributedString: textView.attributedText)
|
|
5315
|
+
let insertion = NSAttributedString(string: text, attributes: textView.typingAttributes)
|
|
5316
|
+
|
|
5317
|
+
isInternalChange = true
|
|
5318
|
+
if range.length > 0 {
|
|
5319
|
+
mutableAttrString.replaceCharacters(in: range, with: insertion)
|
|
5320
|
+
} else {
|
|
5321
|
+
mutableAttrString.insert(insertion, at: range.location)
|
|
5322
|
+
}
|
|
5323
|
+
textView.attributedText = mutableAttrString
|
|
5324
|
+
|
|
5325
|
+
// Caret after the inserted run. NSString length, not `text.count`: an emoji is one
|
|
5326
|
+
// Character but two UTF-16 units, and the text view counts in UTF-16.
|
|
5327
|
+
let caret = range.location + (text as NSString).length
|
|
5328
|
+
textView.selectedRange = NSRange(location: caret, length: 0)
|
|
5329
|
+
|
|
5330
|
+
placeholderLabel.isHidden = !textView.text.isEmpty
|
|
5331
|
+
isInternalChange = false
|
|
5332
|
+
saveToUndoStack()
|
|
5333
|
+
sendContentChange()
|
|
5334
|
+
updateToolbarButtonStates()
|
|
5335
|
+
emitActiveStyles()
|
|
5336
|
+
}
|
|
5337
|
+
|
|
5295
5338
|
func undo() {
|
|
5296
5339
|
guard undoStack.count > 1 else { return }
|
|
5297
5340
|
|
|
@@ -6280,8 +6323,16 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
6280
6323
|
guard j < chars.count else { return nil }
|
|
6281
6324
|
guard j + 1 < chars.count && chars[j + 1] == "(" else { return nil }
|
|
6282
6325
|
let urlStart = j + 2
|
|
6326
|
+
// Balanced: `(planet)` inside the address is kept and only an unmatched `)` closes the
|
|
6327
|
+
// link. Stopping at the first `)` turned a pasted [Mercury](…/Mercury_(planet)) into
|
|
6328
|
+
// "Mercury" linking to …/Mercury_(planet plus a stray ")".
|
|
6283
6329
|
var k = urlStart
|
|
6284
|
-
|
|
6330
|
+
var depth = 0
|
|
6331
|
+
while k < chars.count {
|
|
6332
|
+
if chars[k] == "(" { depth += 1 }
|
|
6333
|
+
else if chars[k] == ")" { if depth == 0 { break }; depth -= 1 }
|
|
6334
|
+
k += 1
|
|
6335
|
+
}
|
|
6285
6336
|
guard k < chars.count else { return nil }
|
|
6286
6337
|
let linkText = String(chars[(from + 1)..<j])
|
|
6287
6338
|
let linkURL = String(chars[urlStart..<k])
|
|
@@ -38,6 +38,7 @@ RCT_EXTERN_METHOD(clear:(nonnull NSNumber *)node)
|
|
|
38
38
|
RCT_EXTERN_METHOD(focus:(nonnull NSNumber *)node)
|
|
39
39
|
RCT_EXTERN_METHOD(blur:(nonnull NSNumber *)node)
|
|
40
40
|
RCT_EXTERN_METHOD(insertLink:(nonnull NSNumber *)node url:(nonnull NSString *)url text:(nonnull NSString *)text)
|
|
41
|
+
RCT_EXTERN_METHOD(replaceSelection:(nonnull NSNumber *)node text:(nonnull NSString *)text)
|
|
41
42
|
RCT_EXTERN_METHOD(undo:(nonnull NSNumber *)node)
|
|
42
43
|
RCT_EXTERN_METHOD(redo:(nonnull NSNumber *)node)
|
|
43
44
|
RCT_EXTERN_METHOD(toggleBold:(nonnull NSNumber *)node)
|
|
@@ -72,6 +72,14 @@ class RichTextEditorViewManager: RCTViewManager {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
@objc func replaceSelection(_ node: NSNumber, text: NSString) {
|
|
76
|
+
DispatchQueue.main.async {
|
|
77
|
+
if let view = self.bridge?.uiManager.view(forReactTag: node) as? RichTextEditorView {
|
|
78
|
+
view.replaceSelection(with: text as String)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
75
83
|
@objc func undo(_ node: NSNumber) {
|
|
76
84
|
DispatchQueue.main.async {
|
|
77
85
|
if let view = self.bridge?.uiManager.view(forReactTag: node) as? RichTextEditorView {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cometchat/chat-uikit-react-native",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.2",
|
|
4
4
|
"description": "Ready-to-use Chat UI Components for React Native",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"module": "src/index",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@babel/eslint-parser": "^7.27.0",
|
|
54
|
-
"@react-native/eslint-config": "0.
|
|
55
|
-
"@react-native/jest-preset": "
|
|
54
|
+
"@react-native/eslint-config": "0.87.1",
|
|
55
|
+
"@react-native/jest-preset": "0.87.1",
|
|
56
56
|
"@types/jest": "^29.5.13",
|
|
57
57
|
"@types/react": "*",
|
|
58
58
|
"commitlint": "^17.0.2",
|
|
@@ -87,10 +87,13 @@
|
|
|
87
87
|
"react-native-video": "*"
|
|
88
88
|
},
|
|
89
89
|
"jest": {
|
|
90
|
-
"preset": "react-native",
|
|
90
|
+
"preset": "@react-native/jest-preset",
|
|
91
91
|
"modulePathIgnorePatterns": [
|
|
92
92
|
"<rootDir>/lib/"
|
|
93
|
-
]
|
|
93
|
+
],
|
|
94
|
+
"moduleNameMapper": {
|
|
95
|
+
"\\.(wav|mp3|m4a|aac|ogg)$": "<rootDir>/jest/assetMock.js"
|
|
96
|
+
}
|
|
94
97
|
},
|
|
95
98
|
"commitlint": {
|
|
96
99
|
"extends": [
|