@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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import UIKit
|
|
2
2
|
import React
|
|
3
|
+
import UniformTypeIdentifiers
|
|
4
|
+
import MobileCoreServices
|
|
3
5
|
|
|
4
6
|
class FloatingToolbar: UIView, UIScrollViewDelegate {
|
|
5
7
|
weak var editorView: RichTextEditorView?
|
|
@@ -574,9 +576,22 @@ class RichTextView: UITextView {
|
|
|
574
576
|
setNeedsDisplay()
|
|
575
577
|
}
|
|
576
578
|
|
|
577
|
-
/// Intercept paste to detect
|
|
578
|
-
/// (
|
|
579
|
+
/// Intercept paste to detect:
|
|
580
|
+
/// 1. Media (images / files) on the clipboard → extract to temp files and emit
|
|
581
|
+
/// the `onPasteMedia` event to JS (does NOT insert anything into the editor).
|
|
582
|
+
/// 2. URL-on-selected-text → create styled hyperlink
|
|
583
|
+
/// (matches Android onTextContextMenuItem paste handling).
|
|
584
|
+
/// 3. Markdown text → parse and insert as styled text.
|
|
585
|
+
/// 4. Otherwise → normal system text paste.
|
|
579
586
|
override func paste(_ sender: Any?) {
|
|
587
|
+
// ── (1) Media paste: images and/or file item providers ──
|
|
588
|
+
// Detect media BEFORE the string check because an image/file copied from
|
|
589
|
+
// Photos or a file provider may have NO plain-text representation, which
|
|
590
|
+
// would otherwise fall through to super.paste() and paste nothing useful.
|
|
591
|
+
if editorContainer?.handlePasteMediaIfAvailable() == true {
|
|
592
|
+
return
|
|
593
|
+
}
|
|
594
|
+
|
|
580
595
|
guard let pastedString = UIPasteboard.general.string else {
|
|
581
596
|
super.paste(sender)
|
|
582
597
|
return
|
|
@@ -782,9 +797,12 @@ class RichTextView: UITextView {
|
|
|
782
797
|
}
|
|
783
798
|
|
|
784
799
|
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
|
|
785
|
-
// Allow paste so clipboard content can be inserted and placeholder hides correctly
|
|
800
|
+
// Allow paste so clipboard content can be inserted and placeholder hides correctly.
|
|
801
|
+
// Also enable paste when the clipboard carries file item providers (e.g. a file
|
|
802
|
+
// copied from Files/another app) so media paste can be triggered.
|
|
786
803
|
if action == #selector(UIResponderStandardEditActions.paste(_:)) {
|
|
787
|
-
|
|
804
|
+
let pb = UIPasteboard.general
|
|
805
|
+
return pb.hasStrings || pb.hasImages || pb.hasURLs || !pb.itemProviders.isEmpty
|
|
788
806
|
}
|
|
789
807
|
// Allow standard text editing actions (matching Android system context menu)
|
|
790
808
|
if action == #selector(UIResponderStandardEditActions.cut(_:)) ||
|
|
@@ -874,6 +892,11 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
874
892
|
tv.textContainerInset = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 4)
|
|
875
893
|
tv.translatesAutoresizingMaskIntoConstraints = false
|
|
876
894
|
tv.backgroundColor = .clear
|
|
895
|
+
#if DEBUG
|
|
896
|
+
// e2e only: expose the inner UITextView to UI automation (Detox) so tests can type a caption.
|
|
897
|
+
// DEBUG-gated → not present in release builds.
|
|
898
|
+
tv.accessibilityIdentifier = "rich-text-editor-input"
|
|
899
|
+
#endif
|
|
877
900
|
|
|
878
901
|
// Set default paragraph style with consistent line height
|
|
879
902
|
let paragraphStyle = NSMutableParagraphStyle()
|
|
@@ -990,6 +1013,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
990
1013
|
@objc var onSizeChange: RCTDirectEventBlock?
|
|
991
1014
|
@objc var onActiveStylesChange: RCTDirectEventBlock?
|
|
992
1015
|
@objc var onLinkTap: RCTDirectEventBlock?
|
|
1016
|
+
@objc var onPasteMedia: RCTDirectEventBlock?
|
|
993
1017
|
|
|
994
1018
|
// Props sent from JS that need @objc declarations to avoid doesNotRecognizeSelector crash
|
|
995
1019
|
@objc var toolbarMode: String?
|
|
@@ -2868,6 +2892,290 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
|
|
|
2868
2892
|
])
|
|
2869
2893
|
}
|
|
2870
2894
|
|
|
2895
|
+
// MARK: - Paste Media (images / files)
|
|
2896
|
+
|
|
2897
|
+
/// Inspects `UIPasteboard.general` for media content (images and/or file item
|
|
2898
|
+
/// providers). If found, extracts each item to a temp file in NSTemporaryDirectory()
|
|
2899
|
+
/// and emits the `onPasteMedia` event to JS with an `items` array of
|
|
2900
|
+
/// `{ uri, mimeType, name, size }`. Returns `true` if media was detected and a
|
|
2901
|
+
/// paste-media flow was started (so the caller should NOT fall through to text paste).
|
|
2902
|
+
///
|
|
2903
|
+
/// For text-only clipboards this returns `false` so normal text paste proceeds.
|
|
2904
|
+
///
|
|
2905
|
+
/// Note: file representation loading is asynchronous; the event is emitted once all
|
|
2906
|
+
/// providers have finished loading. `true` is returned synchronously as soon as we
|
|
2907
|
+
/// know the clipboard carries media, so text paste is suppressed immediately.
|
|
2908
|
+
@objc func handlePasteMediaIfAvailable() -> Bool {
|
|
2909
|
+
let pb = UIPasteboard.general
|
|
2910
|
+
|
|
2911
|
+
// Prefer item providers (they carry real UTIs + file data for images AND files).
|
|
2912
|
+
let providers = pb.itemProviders
|
|
2913
|
+
if !providers.isEmpty {
|
|
2914
|
+
let mediaProviders = providers.filter { provider in
|
|
2915
|
+
// Consider it media if it can vend a file/data representation for any
|
|
2916
|
+
// non-plain-text type. Plain text / URLs alone should NOT be treated as media.
|
|
2917
|
+
return provider.registeredTypeIdentifiers.contains { typeId in
|
|
2918
|
+
return Self.isMediaTypeIdentifier(typeId)
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
if !mediaProviders.isEmpty {
|
|
2922
|
+
extractItemProviders(mediaProviders)
|
|
2923
|
+
return true
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
// Fallback: raw images on the pasteboard with no item provider (rare, e.g. a
|
|
2928
|
+
// screenshot placed directly as a UIImage).
|
|
2929
|
+
if pb.hasImages, let images = pb.images, !images.isEmpty {
|
|
2930
|
+
extractRawImages(images)
|
|
2931
|
+
return true
|
|
2932
|
+
}
|
|
2933
|
+
|
|
2934
|
+
return false
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
/// Returns true when a UTI represents pasteable media (image/video/audio/file),
|
|
2938
|
+
/// and false for plain text / URLs which should paste as text.
|
|
2939
|
+
private static func isMediaTypeIdentifier(_ typeId: String) -> Bool {
|
|
2940
|
+
if #available(iOS 14.0, *) {
|
|
2941
|
+
guard let type = UTType(typeId) else { return false }
|
|
2942
|
+
// Exclude plain text and URLs — those are handled by the text-paste path.
|
|
2943
|
+
if type.conforms(to: .plainText) || type.conforms(to: .url) || type.conforms(to: .text) {
|
|
2944
|
+
return false
|
|
2945
|
+
}
|
|
2946
|
+
return type.conforms(to: .image)
|
|
2947
|
+
|| type.conforms(to: .movie)
|
|
2948
|
+
|| type.conforms(to: .audio)
|
|
2949
|
+
|| type.conforms(to: .fileURL)
|
|
2950
|
+
|| type.conforms(to: .data)
|
|
2951
|
+
|| type.conforms(to: .item)
|
|
2952
|
+
} else {
|
|
2953
|
+
// Pre-iOS 14 fallback using MobileCoreServices.
|
|
2954
|
+
let cf = typeId as CFString
|
|
2955
|
+
if UTTypeConformsTo(cf, kUTTypePlainText) || UTTypeConformsTo(cf, kUTTypeText) || UTTypeConformsTo(cf, kUTTypeURL) {
|
|
2956
|
+
return false
|
|
2957
|
+
}
|
|
2958
|
+
return UTTypeConformsTo(cf, kUTTypeImage)
|
|
2959
|
+
|| UTTypeConformsTo(cf, kUTTypeMovie)
|
|
2960
|
+
|| UTTypeConformsTo(cf, kUTTypeAudio)
|
|
2961
|
+
|| UTTypeConformsTo(cf, kUTTypeData)
|
|
2962
|
+
|| UTTypeConformsTo(cf, kUTTypeItem)
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
/// Loads each NSItemProvider's file representation to a temp file, then emits
|
|
2967
|
+
/// `onPasteMedia` once all providers finish. Robust: items that fail are skipped.
|
|
2968
|
+
private func extractItemProviders(_ providers: [NSItemProvider]) {
|
|
2969
|
+
let group = DispatchGroup()
|
|
2970
|
+
// Guard concurrent appends from provider completion handlers on different queues.
|
|
2971
|
+
let lock = NSLock()
|
|
2972
|
+
var items: [[String: Any]] = []
|
|
2973
|
+
|
|
2974
|
+
for provider in providers {
|
|
2975
|
+
// Pick the best (most specific media) type identifier this provider offers.
|
|
2976
|
+
guard let typeId = bestMediaTypeIdentifier(for: provider) else { continue }
|
|
2977
|
+
|
|
2978
|
+
group.enter()
|
|
2979
|
+
// loadFileRepresentation gives us a temp URL we must copy out of before the
|
|
2980
|
+
// completion handler returns (the vended URL is only valid inside the block).
|
|
2981
|
+
provider.loadFileRepresentation(forTypeIdentifier: typeId) { [weak self] (url, error) in
|
|
2982
|
+
defer { group.leave() }
|
|
2983
|
+
guard let self = self, let srcURL = url, error == nil else {
|
|
2984
|
+
if let error = error { print("[RichTextEditor] paste file load failed: \(error)") }
|
|
2985
|
+
return
|
|
2986
|
+
}
|
|
2987
|
+
if let item = self.copyToTempAndBuildItem(
|
|
2988
|
+
from: srcURL,
|
|
2989
|
+
typeIdentifier: typeId,
|
|
2990
|
+
suggestedName: provider.suggestedName
|
|
2991
|
+
) {
|
|
2992
|
+
lock.lock()
|
|
2993
|
+
items.append(item)
|
|
2994
|
+
lock.unlock()
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
group.notify(queue: .main) { [weak self] in
|
|
3000
|
+
guard let self = self, !items.isEmpty else { return }
|
|
3001
|
+
self.emitPasteMedia(items: items)
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
/// Chooses the most appropriate media type identifier from a provider's registered
|
|
3006
|
+
/// identifiers (prefers concrete image/movie/audio/file types over generic ones).
|
|
3007
|
+
private func bestMediaTypeIdentifier(for provider: NSItemProvider) -> String? {
|
|
3008
|
+
let ids = provider.registeredTypeIdentifiers.filter { Self.isMediaTypeIdentifier($0) }
|
|
3009
|
+
if ids.isEmpty { return nil }
|
|
3010
|
+
if #available(iOS 14.0, *) {
|
|
3011
|
+
// Prefer image, then movie, then audio, then any file/data.
|
|
3012
|
+
let preferenceOrder: [UTType] = [.image, .movie, .audio, .pdf, .fileURL, .data, .item]
|
|
3013
|
+
for pref in preferenceOrder {
|
|
3014
|
+
if let match = ids.first(where: { UTType($0)?.conforms(to: pref) == true }) {
|
|
3015
|
+
return match
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
return ids.first
|
|
3020
|
+
}
|
|
3021
|
+
|
|
3022
|
+
/// Copies the data at `srcURL` to a uniquely-named temp file in NSTemporaryDirectory()
|
|
3023
|
+
/// and returns the JS item dict { uri, mimeType, name, size }, or nil on failure.
|
|
3024
|
+
private func copyToTempAndBuildItem(from srcURL: URL, typeIdentifier: String, suggestedName: String?) -> [String: Any]? {
|
|
3025
|
+
let fm = FileManager.default
|
|
3026
|
+
|
|
3027
|
+
// Resolve the REAL mime type + preferred extension from the UTI (do NOT hardcode).
|
|
3028
|
+
let mimeType = Self.mimeType(forTypeIdentifier: typeIdentifier)
|
|
3029
|
+
?? Self.mimeType(forPathExtension: srcURL.pathExtension)
|
|
3030
|
+
?? "application/octet-stream"
|
|
3031
|
+
let preferredExt = Self.preferredExtension(forTypeIdentifier: typeIdentifier)
|
|
3032
|
+
|
|
3033
|
+
// Build a display name with an extension.
|
|
3034
|
+
let srcExt = srcURL.pathExtension
|
|
3035
|
+
let ext = !srcExt.isEmpty ? srcExt : (preferredExt ?? "")
|
|
3036
|
+
let baseName: String
|
|
3037
|
+
if let suggested = suggestedName, !suggested.isEmpty {
|
|
3038
|
+
if (suggested as NSString).pathExtension.isEmpty, !ext.isEmpty {
|
|
3039
|
+
baseName = "\(suggested).\(ext)"
|
|
3040
|
+
} else {
|
|
3041
|
+
baseName = suggested
|
|
3042
|
+
}
|
|
3043
|
+
} else {
|
|
3044
|
+
let srcNameNoExt = srcURL.deletingPathExtension().lastPathComponent
|
|
3045
|
+
let core = srcNameNoExt.isEmpty ? "pasted_media_\(Int(Date().timeIntervalSince1970 * 1000))" : srcNameNoExt
|
|
3046
|
+
baseName = ext.isEmpty ? core : "\(core).\(ext)"
|
|
3047
|
+
}
|
|
3048
|
+
|
|
3049
|
+
// Unique temp destination so multiple pasted items never collide.
|
|
3050
|
+
let uniquePrefix = "paste_\(UUID().uuidString)_"
|
|
3051
|
+
let destURL = URL(fileURLWithPath: NSTemporaryDirectory())
|
|
3052
|
+
.appendingPathComponent("\(uniquePrefix)\(baseName)")
|
|
3053
|
+
|
|
3054
|
+
do {
|
|
3055
|
+
if fm.fileExists(atPath: destURL.path) {
|
|
3056
|
+
try fm.removeItem(at: destURL)
|
|
3057
|
+
}
|
|
3058
|
+
try fm.copyItem(at: srcURL, to: destURL)
|
|
3059
|
+
} catch {
|
|
3060
|
+
// Fallback: try reading data then writing (handles providers whose URL
|
|
3061
|
+
// can't be copied directly).
|
|
3062
|
+
do {
|
|
3063
|
+
let data = try Data(contentsOf: srcURL)
|
|
3064
|
+
try data.write(to: destURL)
|
|
3065
|
+
} catch {
|
|
3066
|
+
print("[RichTextEditor] paste temp copy failed: \(error)")
|
|
3067
|
+
return nil
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
let size = Self.fileSize(atPath: destURL.path)
|
|
3072
|
+
|
|
3073
|
+
return [
|
|
3074
|
+
"uri": destURL.absoluteString, // file:///... (absoluteString yields file:// URL)
|
|
3075
|
+
"mimeType": mimeType,
|
|
3076
|
+
"name": baseName,
|
|
3077
|
+
"size": size
|
|
3078
|
+
]
|
|
3079
|
+
}
|
|
3080
|
+
|
|
3081
|
+
/// Returns the byte size of the file at `path`, or 0 if it cannot be read.
|
|
3082
|
+
private static func fileSize(atPath path: String) -> Int {
|
|
3083
|
+
guard let attrs = try? FileManager.default.attributesOfItem(atPath: path),
|
|
3084
|
+
let size = attrs[.size] as? Int else {
|
|
3085
|
+
return 0
|
|
3086
|
+
}
|
|
3087
|
+
return size
|
|
3088
|
+
}
|
|
3089
|
+
|
|
3090
|
+
/// Handles raw UIImage(s) on the pasteboard that arrive without an item provider.
|
|
3091
|
+
private func extractRawImages(_ images: [UIImage]) {
|
|
3092
|
+
var items: [[String: Any]] = []
|
|
3093
|
+
for (idx, image) in images.enumerated() {
|
|
3094
|
+
// Prefer PNG to preserve transparency/quality; fall back to JPEG.
|
|
3095
|
+
let isPng: Bool
|
|
3096
|
+
let data: Data?
|
|
3097
|
+
if let png = image.pngData() {
|
|
3098
|
+
data = png; isPng = true
|
|
3099
|
+
} else {
|
|
3100
|
+
data = image.jpegData(compressionQuality: 0.9); isPng = false
|
|
3101
|
+
}
|
|
3102
|
+
guard let imageData = data else { continue }
|
|
3103
|
+
let ext = isPng ? "png" : "jpg"
|
|
3104
|
+
let mimeType = isPng ? "image/png" : "image/jpeg"
|
|
3105
|
+
let name = "pasted_image_\(Int(Date().timeIntervalSince1970 * 1000))_\(idx).\(ext)"
|
|
3106
|
+
let destURL = URL(fileURLWithPath: NSTemporaryDirectory())
|
|
3107
|
+
.appendingPathComponent("paste_\(UUID().uuidString)_\(name)")
|
|
3108
|
+
do {
|
|
3109
|
+
try imageData.write(to: destURL)
|
|
3110
|
+
let size = Self.fileSize(atPath: destURL.path)
|
|
3111
|
+
items.append([
|
|
3112
|
+
"uri": destURL.absoluteString,
|
|
3113
|
+
"mimeType": mimeType,
|
|
3114
|
+
"name": name,
|
|
3115
|
+
"size": size > 0 ? size : imageData.count
|
|
3116
|
+
])
|
|
3117
|
+
} catch {
|
|
3118
|
+
print("[RichTextEditor] paste raw image write failed: \(error)")
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
if !items.isEmpty {
|
|
3122
|
+
emitPasteMedia(items: items)
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
/// Emits the onPasteMedia event to JS on the main thread.
|
|
3127
|
+
private func emitPasteMedia(items: [[String: Any]]) {
|
|
3128
|
+
guard !items.isEmpty else { return }
|
|
3129
|
+
let payload: [String: Any] = ["items": items]
|
|
3130
|
+
if Thread.isMainThread {
|
|
3131
|
+
onPasteMedia?(payload)
|
|
3132
|
+
} else {
|
|
3133
|
+
DispatchQueue.main.async { [weak self] in
|
|
3134
|
+
self?.onPasteMedia?(payload)
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
|
|
3139
|
+
/// Resolves a mime type string from a UTI type identifier.
|
|
3140
|
+
private static func mimeType(forTypeIdentifier typeId: String) -> String? {
|
|
3141
|
+
if #available(iOS 14.0, *) {
|
|
3142
|
+
return UTType(typeId)?.preferredMIMEType
|
|
3143
|
+
} else {
|
|
3144
|
+
guard let mime = UTTypeCopyPreferredTagWithClass(typeId as CFString, kUTTagClassMIMEType)?.takeRetainedValue() else {
|
|
3145
|
+
return nil
|
|
3146
|
+
}
|
|
3147
|
+
return mime as String
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
|
|
3151
|
+
/// Resolves a mime type string from a file path extension.
|
|
3152
|
+
private static func mimeType(forPathExtension ext: String) -> String? {
|
|
3153
|
+
guard !ext.isEmpty else { return nil }
|
|
3154
|
+
if #available(iOS 14.0, *) {
|
|
3155
|
+
return UTType(filenameExtension: ext)?.preferredMIMEType
|
|
3156
|
+
} else {
|
|
3157
|
+
guard let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, ext as CFString, nil)?.takeRetainedValue() else {
|
|
3158
|
+
return nil
|
|
3159
|
+
}
|
|
3160
|
+
guard let mime = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() else {
|
|
3161
|
+
return nil
|
|
3162
|
+
}
|
|
3163
|
+
return mime as String
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
/// Resolves the preferred filename extension for a UTI type identifier.
|
|
3168
|
+
private static func preferredExtension(forTypeIdentifier typeId: String) -> String? {
|
|
3169
|
+
if #available(iOS 14.0, *) {
|
|
3170
|
+
return UTType(typeId)?.preferredFilenameExtension
|
|
3171
|
+
} else {
|
|
3172
|
+
guard let ext = UTTypeCopyPreferredTagWithClass(typeId as CFString, kUTTagClassFilenameExtension)?.takeRetainedValue() else {
|
|
3173
|
+
return nil
|
|
3174
|
+
}
|
|
3175
|
+
return ext as String
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
|
|
2871
3179
|
/// Returns sub-ranges of the given range that do NOT overlap with any mention.
|
|
2872
3180
|
/// Mirrors Android's `nonMentionRanges()` — formatting is applied only to these
|
|
2873
3181
|
/// segments so mention styling remains untouched (Req 6.1).
|
|
@@ -17,6 +17,7 @@ RCT_EXPORT_VIEW_PROPERTY(onEditorBlur, RCTDirectEventBlock)
|
|
|
17
17
|
RCT_EXPORT_VIEW_PROPERTY(onSizeChange, RCTDirectEventBlock)
|
|
18
18
|
RCT_EXPORT_VIEW_PROPERTY(onActiveStylesChange, RCTDirectEventBlock)
|
|
19
19
|
RCT_EXPORT_VIEW_PROPERTY(onLinkTap, RCTDirectEventBlock)
|
|
20
|
+
RCT_EXPORT_VIEW_PROPERTY(onPasteMedia, RCTDirectEventBlock)
|
|
20
21
|
|
|
21
22
|
// New properties for CometChat integration
|
|
22
23
|
RCT_EXPORT_VIEW_PROPERTY(selection, NSDictionary)
|
package/ios/SoundPlayer.m
CHANGED
|
@@ -31,10 +31,13 @@ RCT_EXPORT_MODULE(SoundPlayer)
|
|
|
31
31
|
RCT_EXPORT_METHOD(prepareMediaPlayer:(NSString *) url
|
|
32
32
|
callback:(RCTResponseSenderBlock) resolve) {
|
|
33
33
|
NSURL *nsurl;
|
|
34
|
-
if ([url hasPrefix:@"http"] || [url hasPrefix:@"
|
|
34
|
+
if ([url hasPrefix:@"http"] || [url hasPrefix:@"file:"]) {
|
|
35
|
+
// http/https AND local file:// URLs must go through URLWithString. fileURLWithPath:
|
|
36
|
+
// expects a PLAIN path and mangles a file:// URL (nil data → nil AVAudioPlayer →
|
|
37
|
+
// duration 0), which is why staged audio showed 00:00 on iOS. Plain paths use the else.
|
|
35
38
|
nsurl = [NSURL URLWithString:url];
|
|
36
39
|
} else {
|
|
37
|
-
nsurl = [NSURL fileURLWithPath:url]; //
|
|
40
|
+
nsurl = [NSURL fileURLWithPath:url]; // plain filesystem path (no scheme)
|
|
38
41
|
}
|
|
39
42
|
NSData *data = [NSData dataWithContentsOfURL:nsurl];
|
|
40
43
|
if ([audioPlayer isPlaying]) {
|
|
@@ -65,10 +68,13 @@ RCT_EXPORT_METHOD(play:(NSString *) url
|
|
|
65
68
|
[session setActive:YES error:nil];
|
|
66
69
|
|
|
67
70
|
NSURL *nsurl;
|
|
68
|
-
if ([url hasPrefix:@"http"] || [url hasPrefix:@"
|
|
71
|
+
if ([url hasPrefix:@"http"] || [url hasPrefix:@"file:"]) {
|
|
72
|
+
// http/https AND local file:// URLs must go through URLWithString. fileURLWithPath:
|
|
73
|
+
// expects a PLAIN path and mangles a file:// URL (nil data → nil AVAudioPlayer →
|
|
74
|
+
// duration 0), which is why staged audio showed 00:00 on iOS. Plain paths use the else.
|
|
69
75
|
nsurl = [NSURL URLWithString:url];
|
|
70
76
|
} else {
|
|
71
|
-
nsurl = [NSURL fileURLWithPath:url]; //
|
|
77
|
+
nsurl = [NSURL fileURLWithPath:url]; // plain filesystem path (no scheme)
|
|
72
78
|
}
|
|
73
79
|
NSData *data = [NSData dataWithContentsOfURL:nsurl];
|
|
74
80
|
if (!data) {
|
|
@@ -95,9 +101,15 @@ RCT_EXPORT_METHOD(play:(NSString *) url
|
|
|
95
101
|
resolve(@[response]);
|
|
96
102
|
}
|
|
97
103
|
|
|
104
|
+
// Seek to `atTime` seconds. Setting `currentTime` seeks within the clip and preserves the
|
|
105
|
+
// current play/pause state — unlike `playAtTime:`, which schedules future playback and does
|
|
106
|
+
// NOT seek. Matches Android's playAt(seconds) → seekTo().
|
|
98
107
|
RCT_EXPORT_METHOD(playAt:(NSInteger) atTime resolver:(RCTResponseSenderBlock)resolve) {
|
|
99
|
-
|
|
100
|
-
|
|
108
|
+
bool res = NO;
|
|
109
|
+
if (audioPlayer != nil) {
|
|
110
|
+
audioPlayer.currentTime = (NSTimeInterval)atTime;
|
|
111
|
+
res = YES;
|
|
112
|
+
}
|
|
101
113
|
NSString *response = [NSString stringWithFormat:@"{\"success\":%d}",res];
|
|
102
114
|
resolve(@[response]);
|
|
103
115
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cometchat/chat-uikit-react-native",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "Ready-to-use Chat UI Components for React Native",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"module": "src/index",
|
|
@@ -52,12 +52,14 @@
|
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@babel/eslint-parser": "^7.27.0",
|
|
54
54
|
"@react-native/eslint-config": "0.79.2",
|
|
55
|
+
"@react-native/jest-preset": "^0.86.0",
|
|
55
56
|
"@types/jest": "^29.5.13",
|
|
56
57
|
"@types/react": "*",
|
|
57
58
|
"commitlint": "^17.0.2",
|
|
58
59
|
"eslint": "^8.57.1",
|
|
59
60
|
"eslint-config-prettier": "^10.1.2",
|
|
60
61
|
"eslint-plugin-prettier": "^5.2.6",
|
|
62
|
+
"fast-check": "^4.8.0",
|
|
61
63
|
"jest": "^29.6.3",
|
|
62
64
|
"prettier": "^3.5.3",
|
|
63
65
|
"react": "*",
|
|
@@ -67,11 +69,11 @@
|
|
|
67
69
|
"dependencies": {
|
|
68
70
|
"@cometchat/cards-react-native": "^1.0.0",
|
|
69
71
|
"@types/prop-types": "^15.7.14",
|
|
72
|
+
"dayjs": "^1.11.18",
|
|
70
73
|
"prop-types": "^15.8.1",
|
|
74
|
+
"react-native-localize": "*",
|
|
71
75
|
"react-native-markdown-display": "^7.0.2",
|
|
72
|
-
"rxjs": "^7.8.2"
|
|
73
|
-
"dayjs": "^1.11.18",
|
|
74
|
-
"react-native-localize": "^3.5.2"
|
|
76
|
+
"rxjs": "^7.8.2"
|
|
75
77
|
},
|
|
76
78
|
"peerDependencies": {
|
|
77
79
|
"@cometchat/chat-sdk-react-native": "*",
|
|
@@ -79,9 +81,9 @@
|
|
|
79
81
|
"react": "*",
|
|
80
82
|
"react-native": "*",
|
|
81
83
|
"react-native-gesture-handler": "*",
|
|
84
|
+
"react-native-localize": "*",
|
|
82
85
|
"react-native-svg": "*",
|
|
83
|
-
"react-native-video": "*"
|
|
84
|
-
"react-native-localize": "*"
|
|
86
|
+
"react-native-video": "*"
|
|
85
87
|
},
|
|
86
88
|
"jest": {
|
|
87
89
|
"preset": "react-native",
|
|
@@ -121,4 +123,4 @@
|
|
|
121
123
|
"node_modules/",
|
|
122
124
|
"lib/"
|
|
123
125
|
]
|
|
124
|
-
}
|
|
126
|
+
}
|