@cometchat/chat-uikit-react-native 5.3.10 → 5.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +52 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
  3. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +95 -8
  4. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +300 -7
  5. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +2 -1
  6. package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +85 -47
  7. package/ios/CometChatClipboardModule.m +11 -0
  8. package/ios/CometChatClipboardModule.swift +41 -0
  9. package/ios/FileManager.m +201 -39
  10. package/ios/RichTextEditorView.swift +367 -8
  11. package/ios/RichTextEditorViewManager.m +1 -0
  12. package/ios/SoundPlayer.m +18 -6
  13. package/package.json +10 -7
  14. package/react-native-cometchat-ui-kit.podspec +1 -0
  15. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +692 -107
  16. package/src/CometChatConversations/CometChatConversations.tsx +19 -6
  17. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +649 -49
  18. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +23 -4
  19. package/src/CometChatMessageList/CometChatMessageList.tsx +463 -54
  20. package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +313 -0
  21. package/src/CometChatMessageList/components/MessageListItem.tsx +30 -17
  22. package/src/CometChatMessageList/style.ts +33 -5
  23. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +13 -0
  24. package/src/CometChatRichTextEditor/index.tsx +25 -0
  25. package/src/CometChatSearch/CometChatSearch.tsx +296 -154
  26. package/src/calls/CallingExtension.tsx +19 -13
  27. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +20 -1
  28. package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +20 -9
  29. package/src/index.ts +39 -0
  30. package/src/shared/CometChatUiKit/CometChatUIKit.ts +40 -34
  31. package/src/shared/base/Types.ts +3 -0
  32. package/src/shared/constants/UIKitConstants.ts +15 -1
  33. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +3 -2
  34. package/src/shared/framework/DataSource.ts +14 -4
  35. package/src/shared/framework/DataSourceDecorator.tsx +17 -8
  36. package/src/shared/framework/MessageDataSource.tsx +307 -60
  37. package/src/shared/helper/useToast.tsx +29 -0
  38. package/src/shared/icons/components/audio-file-type.tsx +11 -22
  39. package/src/shared/icons/components/document-file-type.tsx +11 -24
  40. package/src/shared/icons/components/image-file-type.tsx +12 -21
  41. package/src/shared/icons/components/link-file-type.tsx +25 -0
  42. package/src/shared/icons/components/pdf-file-type.tsx +11 -22
  43. package/src/shared/icons/components/presentation-file-type.tsx +11 -24
  44. package/src/shared/icons/components/spreadsheet-file-type.tsx +11 -24
  45. package/src/shared/icons/components/text-file-type.tsx +11 -21
  46. package/src/shared/icons/components/unknown-file-type.tsx +21 -25
  47. package/src/shared/icons/components/video-file-type.tsx +11 -24
  48. package/src/shared/icons/components/zip-file-type.tsx +11 -24
  49. package/src/shared/icons/icon-mapping.tsx +2 -0
  50. package/src/shared/index.ts +28 -0
  51. package/src/shared/modals/AttachmentPickerConfiguration.ts +13 -0
  52. package/src/shared/modals/SelectedAttachment.ts +65 -0
  53. package/src/shared/modals/UploadState.ts +10 -0
  54. package/src/shared/modals/index.ts +4 -0
  55. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +42 -1
  56. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +42 -1
  57. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +43 -2
  58. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +43 -2
  59. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +43 -2
  60. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +43 -2
  61. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +43 -2
  62. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +43 -2
  63. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +43 -2
  64. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +43 -2
  65. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +43 -2
  66. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +43 -2
  67. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +43 -2
  68. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +43 -2
  69. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +43 -2
  70. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +43 -2
  71. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +43 -2
  72. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +43 -2
  73. package/src/shared/services/UploadQueueService.ts +145 -0
  74. package/src/shared/services/index.ts +2 -0
  75. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +44 -19
  76. package/src/shared/utils/MessageUtils.tsx +13 -4
  77. package/src/shared/utils/attachmentLimits.ts +156 -0
  78. package/src/shared/utils/audioPlaybackCoordinator.ts +28 -0
  79. package/src/shared/utils/batchMediaContext.tsx +30 -0
  80. package/src/shared/utils/conversationUtils.ts +26 -4
  81. package/src/shared/utils/elementType.tsx +38 -0
  82. package/src/shared/utils/groupAttachments.ts +93 -0
  83. package/src/shared/utils/index.ts +8 -0
  84. package/src/shared/utils/openMultiFileChooser.ts +123 -0
  85. package/src/shared/utils/partitionAttachmentsByKind.ts +44 -0
  86. package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +28 -0
  87. package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +16 -0
  88. package/src/shared/views/ClipboardPasteHandler/index.ts +2 -0
  89. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +1 -0
  90. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +32 -0
  91. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.tsx +90 -0
  92. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +276 -0
  93. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +827 -0
  94. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTray.tsx +110 -0
  95. package/src/shared/views/CometChatAttachmentPreview/StagedVideoDurationProbe.tsx +53 -0
  96. package/src/shared/views/CometChatAttachmentPreview/index.ts +8 -0
  97. package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +305 -0
  98. package/src/shared/views/CometChatAttachmentViewer/index.ts +2 -0
  99. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +71 -74
  100. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +587 -0
  101. package/src/shared/views/CometChatAudiosBubble/index.ts +2 -0
  102. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +31 -20
  103. package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +182 -0
  104. package/src/shared/views/CometChatCaptionText/index.ts +2 -0
  105. package/src/shared/views/CometChatComposerErrorBanner.tsx +83 -0
  106. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +141 -0
  107. package/src/shared/views/CometChatConversationStarter/index.ts +2 -0
  108. package/src/shared/views/CometChatConversationSummary/CometChatConversationSummary.tsx +155 -0
  109. package/src/shared/views/CometChatConversationSummary/index.ts +2 -0
  110. package/src/shared/views/CometChatFileBubble/style.ts +6 -4
  111. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +316 -0
  112. package/src/shared/views/CometChatFilesBubble/index.ts +2 -0
  113. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +323 -0
  114. package/src/shared/views/CometChatImagesBubble/index.ts +2 -0
  115. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +425 -0
  116. package/src/shared/views/CometChatMediaViewer/index.ts +2 -0
  117. package/src/shared/views/CometChatMediaViewer/mediaViewerUtils.ts +30 -0
  118. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +14 -4
  119. package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +1 -0
  120. package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +172 -0
  121. package/src/shared/views/CometChatSmartReplies/index.ts +2 -0
  122. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +4 -3
  123. package/src/shared/views/CometChatVideoBubble/style.ts +3 -3
  124. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +441 -0
  125. package/src/shared/views/CometChatVideosBubble/index.ts +2 -0
  126. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +78 -0
  127. package/src/shared/views/CometChatVoiceNoteBubble/index.ts +2 -0
  128. package/src/shared/views/index.ts +37 -1
  129. package/src/theme/CometChatThemeHelper.ts +8 -0
  130. package/src/theme/default/color/dark.ts +9 -0
  131. package/src/theme/default/color/light.ts +10 -0
  132. package/src/theme/type.ts +73 -0
@@ -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 URL-on-selected-text → create styled hyperlink
578
- /// (matches Android onTextContextMenuItem paste handling).
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
@@ -598,9 +613,6 @@ class RichTextView: UITextView {
598
613
  }
599
614
 
600
615
  private func disableAutofill() {
601
- autocorrectionType = .no
602
- autocapitalizationType = .none
603
- spellCheckingType = .no
604
616
  smartQuotesType = .no
605
617
  smartDashesType = .no
606
618
  smartInsertDeleteType = .no
@@ -622,6 +634,15 @@ class RichTextView: UITextView {
622
634
 
623
635
  isSecureTextEntry = true
624
636
  isSecureTextEntry = false
637
+
638
+ // The secure round-trip above rebuilds the input traits and leaves autocorrect
639
+ // and spell check suppressed, so the typing traits have to be re-asserted AFTER
640
+ // it — assigning them earlier in this method does not survive. `.default` and
641
+ // `.sentences` are the "let the platform decide" values, the same ones a plain
642
+ // UITextView / RN TextInput starts from; nothing is pinned on or off here.
643
+ autocorrectionType = .default
644
+ autocapitalizationType = .sentences
645
+ spellCheckingType = .default
625
646
  }
626
647
 
627
648
  /// Custom drawing for blockquote vertical bars (matches Android onDraw implementation).
@@ -782,9 +803,12 @@ class RichTextView: UITextView {
782
803
  }
783
804
 
784
805
  override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
785
- // Allow paste so clipboard content can be inserted and placeholder hides correctly
806
+ // Allow paste so clipboard content can be inserted and placeholder hides correctly.
807
+ // Also enable paste when the clipboard carries file item providers (e.g. a file
808
+ // copied from Files/another app) so media paste can be triggered.
786
809
  if action == #selector(UIResponderStandardEditActions.paste(_:)) {
787
- return UIPasteboard.general.hasStrings || UIPasteboard.general.hasImages || UIPasteboard.general.hasURLs
810
+ let pb = UIPasteboard.general
811
+ return pb.hasStrings || pb.hasImages || pb.hasURLs || !pb.itemProviders.isEmpty
788
812
  }
789
813
  // Allow standard text editing actions (matching Android system context menu)
790
814
  if action == #selector(UIResponderStandardEditActions.cut(_:)) ||
@@ -874,6 +898,11 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
874
898
  tv.textContainerInset = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 4)
875
899
  tv.translatesAutoresizingMaskIntoConstraints = false
876
900
  tv.backgroundColor = .clear
901
+ #if DEBUG
902
+ // e2e only: expose the inner UITextView to UI automation (Detox) so tests can type a caption.
903
+ // DEBUG-gated → not present in release builds.
904
+ tv.accessibilityIdentifier = "rich-text-editor-input"
905
+ #endif
877
906
 
878
907
  // Set default paragraph style with consistent line height
879
908
  let paragraphStyle = NSMutableParagraphStyle()
@@ -946,6 +975,48 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
946
975
 
947
976
  @objc var showToolbar: Bool = true
948
977
 
978
+ // MARK: - Typing traits
979
+ // Autocorrect / autocapitalization / spell check are never pinned to a fixed value.
980
+ // In prose the text view is left at the UIKit defaults — the same behaviour a plain
981
+ // RN `TextInput` gets for free, so the keyboard's own language and user settings
982
+ // decide — and the editor drops all three by itself while the caret sits in code
983
+ // (see `isCodeContext`), so autocorrect never rewrites a code sample.
984
+ private var isCodeContext = false
985
+
986
+
987
+ private func applyTypingTraits() {
988
+ let correction: UITextAutocorrectionType
989
+ let capitalization: UITextAutocapitalizationType
990
+ let spellChecking: UITextSpellCheckingType
991
+
992
+ if isCodeContext {
993
+ correction = .no
994
+ capitalization = .none
995
+ spellChecking = .no
996
+ } else {
997
+ correction = .default
998
+ capitalization = .sentences
999
+ spellChecking = .default
1000
+ }
1001
+
1002
+ guard textView.autocorrectionType != correction
1003
+ || textView.autocapitalizationType != capitalization
1004
+ || textView.spellCheckingType != spellChecking else { return }
1005
+
1006
+ textView.autocorrectionType = correction
1007
+ textView.autocapitalizationType = capitalization
1008
+ textView.spellCheckingType = spellChecking
1009
+ if textView.isFirstResponder {
1010
+ textView.reloadInputViews()
1011
+ }
1012
+ }
1013
+
1014
+ private func setCodeContext(_ inCode: Bool) {
1015
+ guard inCode != isCodeContext else { return }
1016
+ isCodeContext = inCode
1017
+ applyTypingTraits()
1018
+ }
1019
+
949
1020
  /// When true, Bold/Italic/Underline/Strikethrough appear in the text selection context menu.
950
1021
  @objc var showTextSelectionMenuItems: Bool = true {
951
1022
  didSet {
@@ -990,6 +1061,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
990
1061
  @objc var onSizeChange: RCTDirectEventBlock?
991
1062
  @objc var onActiveStylesChange: RCTDirectEventBlock?
992
1063
  @objc var onLinkTap: RCTDirectEventBlock?
1064
+ @objc var onPasteMedia: RCTDirectEventBlock?
993
1065
 
994
1066
  // Props sent from JS that need @objc declarations to avoid doesNotRecognizeSelector crash
995
1067
  @objc var toolbarMode: String?
@@ -1420,6 +1492,7 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
1420
1492
  let checkRange = range.length > 0 ? range : NSRange(location: max(0, range.location - 1), length: 1)
1421
1493
 
1422
1494
  guard checkRange.location >= 0, checkRange.location < attributedText.length else {
1495
+ setCodeContext(pendingStyles.contains("code") || pendingStyles.contains("codeBlock"))
1423
1496
  onActiveStylesChange?([
1424
1497
  "bold": pendingStyles.contains("bold") && !explicitlyOffStyles.contains("bold"),
1425
1498
  "italic": pendingStyles.contains("italic") && !explicitlyOffStyles.contains("italic"),
@@ -1550,13 +1623,15 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
1550
1623
  }
1551
1624
  }
1552
1625
  let codeBlockActive = hasCodeBlock || pendingStyles.contains("codeBlock")
1626
+ let codeActive = (hasCode || pendingStyles.contains("code") || pendingStyles.contains("codeBlock")) && !explicitlyOffStyles.contains("code")
1627
+ setCodeContext(codeActive || codeBlockActive)
1553
1628
 
1554
1629
  onActiveStylesChange?([
1555
1630
  "bold": (hasBold || pendingStyles.contains("bold")) && !explicitlyOffStyles.contains("bold"),
1556
1631
  "italic": (hasItalic || pendingStyles.contains("italic")) && !explicitlyOffStyles.contains("italic"),
1557
1632
  "underline": (hasUnderline || pendingStyles.contains("underline")) && !explicitlyOffStyles.contains("underline"),
1558
1633
  "strikethrough": (hasStrikethrough || pendingStyles.contains("strikethrough")) && !explicitlyOffStyles.contains("strikethrough"),
1559
- "code": (hasCode || pendingStyles.contains("code") || pendingStyles.contains("codeBlock")) && !explicitlyOffStyles.contains("code"),
1634
+ "code": codeActive,
1560
1635
  "codeBlock": codeBlockActive,
1561
1636
  "highlight": hasHighlight,
1562
1637
  "blockType": blockType,
@@ -2868,6 +2943,290 @@ class RichTextEditorView: UIView, UITextViewDelegate, UIGestureRecognizerDelegat
2868
2943
  ])
2869
2944
  }
2870
2945
 
2946
+ // MARK: - Paste Media (images / files)
2947
+
2948
+ /// Inspects `UIPasteboard.general` for media content (images and/or file item
2949
+ /// providers). If found, extracts each item to a temp file in NSTemporaryDirectory()
2950
+ /// and emits the `onPasteMedia` event to JS with an `items` array of
2951
+ /// `{ uri, mimeType, name, size }`. Returns `true` if media was detected and a
2952
+ /// paste-media flow was started (so the caller should NOT fall through to text paste).
2953
+ ///
2954
+ /// For text-only clipboards this returns `false` so normal text paste proceeds.
2955
+ ///
2956
+ /// Note: file representation loading is asynchronous; the event is emitted once all
2957
+ /// providers have finished loading. `true` is returned synchronously as soon as we
2958
+ /// know the clipboard carries media, so text paste is suppressed immediately.
2959
+ @objc func handlePasteMediaIfAvailable() -> Bool {
2960
+ let pb = UIPasteboard.general
2961
+
2962
+ // Prefer item providers (they carry real UTIs + file data for images AND files).
2963
+ let providers = pb.itemProviders
2964
+ if !providers.isEmpty {
2965
+ let mediaProviders = providers.filter { provider in
2966
+ // Consider it media if it can vend a file/data representation for any
2967
+ // non-plain-text type. Plain text / URLs alone should NOT be treated as media.
2968
+ return provider.registeredTypeIdentifiers.contains { typeId in
2969
+ return Self.isMediaTypeIdentifier(typeId)
2970
+ }
2971
+ }
2972
+ if !mediaProviders.isEmpty {
2973
+ extractItemProviders(mediaProviders)
2974
+ return true
2975
+ }
2976
+ }
2977
+
2978
+ // Fallback: raw images on the pasteboard with no item provider (rare, e.g. a
2979
+ // screenshot placed directly as a UIImage).
2980
+ if pb.hasImages, let images = pb.images, !images.isEmpty {
2981
+ extractRawImages(images)
2982
+ return true
2983
+ }
2984
+
2985
+ return false
2986
+ }
2987
+
2988
+ /// Returns true when a UTI represents pasteable media (image/video/audio/file),
2989
+ /// and false for plain text / URLs which should paste as text.
2990
+ private static func isMediaTypeIdentifier(_ typeId: String) -> Bool {
2991
+ if #available(iOS 14.0, *) {
2992
+ guard let type = UTType(typeId) else { return false }
2993
+ // Exclude plain text and URLs — those are handled by the text-paste path.
2994
+ if type.conforms(to: .plainText) || type.conforms(to: .url) || type.conforms(to: .text) {
2995
+ return false
2996
+ }
2997
+ return type.conforms(to: .image)
2998
+ || type.conforms(to: .movie)
2999
+ || type.conforms(to: .audio)
3000
+ || type.conforms(to: .fileURL)
3001
+ || type.conforms(to: .data)
3002
+ || type.conforms(to: .item)
3003
+ } else {
3004
+ // Pre-iOS 14 fallback using MobileCoreServices.
3005
+ let cf = typeId as CFString
3006
+ if UTTypeConformsTo(cf, kUTTypePlainText) || UTTypeConformsTo(cf, kUTTypeText) || UTTypeConformsTo(cf, kUTTypeURL) {
3007
+ return false
3008
+ }
3009
+ return UTTypeConformsTo(cf, kUTTypeImage)
3010
+ || UTTypeConformsTo(cf, kUTTypeMovie)
3011
+ || UTTypeConformsTo(cf, kUTTypeAudio)
3012
+ || UTTypeConformsTo(cf, kUTTypeData)
3013
+ || UTTypeConformsTo(cf, kUTTypeItem)
3014
+ }
3015
+ }
3016
+
3017
+ /// Loads each NSItemProvider's file representation to a temp file, then emits
3018
+ /// `onPasteMedia` once all providers finish. Robust: items that fail are skipped.
3019
+ private func extractItemProviders(_ providers: [NSItemProvider]) {
3020
+ let group = DispatchGroup()
3021
+ // Guard concurrent appends from provider completion handlers on different queues.
3022
+ let lock = NSLock()
3023
+ var items: [[String: Any]] = []
3024
+
3025
+ for provider in providers {
3026
+ // Pick the best (most specific media) type identifier this provider offers.
3027
+ guard let typeId = bestMediaTypeIdentifier(for: provider) else { continue }
3028
+
3029
+ group.enter()
3030
+ // loadFileRepresentation gives us a temp URL we must copy out of before the
3031
+ // completion handler returns (the vended URL is only valid inside the block).
3032
+ provider.loadFileRepresentation(forTypeIdentifier: typeId) { [weak self] (url, error) in
3033
+ defer { group.leave() }
3034
+ guard let self = self, let srcURL = url, error == nil else {
3035
+ if let error = error { print("[RichTextEditor] paste file load failed: \(error)") }
3036
+ return
3037
+ }
3038
+ if let item = self.copyToTempAndBuildItem(
3039
+ from: srcURL,
3040
+ typeIdentifier: typeId,
3041
+ suggestedName: provider.suggestedName
3042
+ ) {
3043
+ lock.lock()
3044
+ items.append(item)
3045
+ lock.unlock()
3046
+ }
3047
+ }
3048
+ }
3049
+
3050
+ group.notify(queue: .main) { [weak self] in
3051
+ guard let self = self, !items.isEmpty else { return }
3052
+ self.emitPasteMedia(items: items)
3053
+ }
3054
+ }
3055
+
3056
+ /// Chooses the most appropriate media type identifier from a provider's registered
3057
+ /// identifiers (prefers concrete image/movie/audio/file types over generic ones).
3058
+ private func bestMediaTypeIdentifier(for provider: NSItemProvider) -> String? {
3059
+ let ids = provider.registeredTypeIdentifiers.filter { Self.isMediaTypeIdentifier($0) }
3060
+ if ids.isEmpty { return nil }
3061
+ if #available(iOS 14.0, *) {
3062
+ // Prefer image, then movie, then audio, then any file/data.
3063
+ let preferenceOrder: [UTType] = [.image, .movie, .audio, .pdf, .fileURL, .data, .item]
3064
+ for pref in preferenceOrder {
3065
+ if let match = ids.first(where: { UTType($0)?.conforms(to: pref) == true }) {
3066
+ return match
3067
+ }
3068
+ }
3069
+ }
3070
+ return ids.first
3071
+ }
3072
+
3073
+ /// Copies the data at `srcURL` to a uniquely-named temp file in NSTemporaryDirectory()
3074
+ /// and returns the JS item dict { uri, mimeType, name, size }, or nil on failure.
3075
+ private func copyToTempAndBuildItem(from srcURL: URL, typeIdentifier: String, suggestedName: String?) -> [String: Any]? {
3076
+ let fm = FileManager.default
3077
+
3078
+ // Resolve the REAL mime type + preferred extension from the UTI (do NOT hardcode).
3079
+ let mimeType = Self.mimeType(forTypeIdentifier: typeIdentifier)
3080
+ ?? Self.mimeType(forPathExtension: srcURL.pathExtension)
3081
+ ?? "application/octet-stream"
3082
+ let preferredExt = Self.preferredExtension(forTypeIdentifier: typeIdentifier)
3083
+
3084
+ // Build a display name with an extension.
3085
+ let srcExt = srcURL.pathExtension
3086
+ let ext = !srcExt.isEmpty ? srcExt : (preferredExt ?? "")
3087
+ let baseName: String
3088
+ if let suggested = suggestedName, !suggested.isEmpty {
3089
+ if (suggested as NSString).pathExtension.isEmpty, !ext.isEmpty {
3090
+ baseName = "\(suggested).\(ext)"
3091
+ } else {
3092
+ baseName = suggested
3093
+ }
3094
+ } else {
3095
+ let srcNameNoExt = srcURL.deletingPathExtension().lastPathComponent
3096
+ let core = srcNameNoExt.isEmpty ? "pasted_media_\(Int(Date().timeIntervalSince1970 * 1000))" : srcNameNoExt
3097
+ baseName = ext.isEmpty ? core : "\(core).\(ext)"
3098
+ }
3099
+
3100
+ // Unique temp destination so multiple pasted items never collide.
3101
+ let uniquePrefix = "paste_\(UUID().uuidString)_"
3102
+ let destURL = URL(fileURLWithPath: NSTemporaryDirectory())
3103
+ .appendingPathComponent("\(uniquePrefix)\(baseName)")
3104
+
3105
+ do {
3106
+ if fm.fileExists(atPath: destURL.path) {
3107
+ try fm.removeItem(at: destURL)
3108
+ }
3109
+ try fm.copyItem(at: srcURL, to: destURL)
3110
+ } catch {
3111
+ // Fallback: try reading data then writing (handles providers whose URL
3112
+ // can't be copied directly).
3113
+ do {
3114
+ let data = try Data(contentsOf: srcURL)
3115
+ try data.write(to: destURL)
3116
+ } catch {
3117
+ print("[RichTextEditor] paste temp copy failed: \(error)")
3118
+ return nil
3119
+ }
3120
+ }
3121
+
3122
+ let size = Self.fileSize(atPath: destURL.path)
3123
+
3124
+ return [
3125
+ "uri": destURL.absoluteString, // file:///... (absoluteString yields file:// URL)
3126
+ "mimeType": mimeType,
3127
+ "name": baseName,
3128
+ "size": size
3129
+ ]
3130
+ }
3131
+
3132
+ /// Returns the byte size of the file at `path`, or 0 if it cannot be read.
3133
+ private static func fileSize(atPath path: String) -> Int {
3134
+ guard let attrs = try? FileManager.default.attributesOfItem(atPath: path),
3135
+ let size = attrs[.size] as? Int else {
3136
+ return 0
3137
+ }
3138
+ return size
3139
+ }
3140
+
3141
+ /// Handles raw UIImage(s) on the pasteboard that arrive without an item provider.
3142
+ private func extractRawImages(_ images: [UIImage]) {
3143
+ var items: [[String: Any]] = []
3144
+ for (idx, image) in images.enumerated() {
3145
+ // Prefer PNG to preserve transparency/quality; fall back to JPEG.
3146
+ let isPng: Bool
3147
+ let data: Data?
3148
+ if let png = image.pngData() {
3149
+ data = png; isPng = true
3150
+ } else {
3151
+ data = image.jpegData(compressionQuality: 0.9); isPng = false
3152
+ }
3153
+ guard let imageData = data else { continue }
3154
+ let ext = isPng ? "png" : "jpg"
3155
+ let mimeType = isPng ? "image/png" : "image/jpeg"
3156
+ let name = "pasted_image_\(Int(Date().timeIntervalSince1970 * 1000))_\(idx).\(ext)"
3157
+ let destURL = URL(fileURLWithPath: NSTemporaryDirectory())
3158
+ .appendingPathComponent("paste_\(UUID().uuidString)_\(name)")
3159
+ do {
3160
+ try imageData.write(to: destURL)
3161
+ let size = Self.fileSize(atPath: destURL.path)
3162
+ items.append([
3163
+ "uri": destURL.absoluteString,
3164
+ "mimeType": mimeType,
3165
+ "name": name,
3166
+ "size": size > 0 ? size : imageData.count
3167
+ ])
3168
+ } catch {
3169
+ print("[RichTextEditor] paste raw image write failed: \(error)")
3170
+ }
3171
+ }
3172
+ if !items.isEmpty {
3173
+ emitPasteMedia(items: items)
3174
+ }
3175
+ }
3176
+
3177
+ /// Emits the onPasteMedia event to JS on the main thread.
3178
+ private func emitPasteMedia(items: [[String: Any]]) {
3179
+ guard !items.isEmpty else { return }
3180
+ let payload: [String: Any] = ["items": items]
3181
+ if Thread.isMainThread {
3182
+ onPasteMedia?(payload)
3183
+ } else {
3184
+ DispatchQueue.main.async { [weak self] in
3185
+ self?.onPasteMedia?(payload)
3186
+ }
3187
+ }
3188
+ }
3189
+
3190
+ /// Resolves a mime type string from a UTI type identifier.
3191
+ private static func mimeType(forTypeIdentifier typeId: String) -> String? {
3192
+ if #available(iOS 14.0, *) {
3193
+ return UTType(typeId)?.preferredMIMEType
3194
+ } else {
3195
+ guard let mime = UTTypeCopyPreferredTagWithClass(typeId as CFString, kUTTagClassMIMEType)?.takeRetainedValue() else {
3196
+ return nil
3197
+ }
3198
+ return mime as String
3199
+ }
3200
+ }
3201
+
3202
+ /// Resolves a mime type string from a file path extension.
3203
+ private static func mimeType(forPathExtension ext: String) -> String? {
3204
+ guard !ext.isEmpty else { return nil }
3205
+ if #available(iOS 14.0, *) {
3206
+ return UTType(filenameExtension: ext)?.preferredMIMEType
3207
+ } else {
3208
+ guard let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, ext as CFString, nil)?.takeRetainedValue() else {
3209
+ return nil
3210
+ }
3211
+ guard let mime = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() else {
3212
+ return nil
3213
+ }
3214
+ return mime as String
3215
+ }
3216
+ }
3217
+
3218
+ /// Resolves the preferred filename extension for a UTI type identifier.
3219
+ private static func preferredExtension(forTypeIdentifier typeId: String) -> String? {
3220
+ if #available(iOS 14.0, *) {
3221
+ return UTType(typeId)?.preferredFilenameExtension
3222
+ } else {
3223
+ guard let ext = UTTypeCopyPreferredTagWithClass(typeId as CFString, kUTTagClassFilenameExtension)?.takeRetainedValue() else {
3224
+ return nil
3225
+ }
3226
+ return ext as String
3227
+ }
3228
+ }
3229
+
2871
3230
  /// Returns sub-ranges of the given range that do NOT overlap with any mention.
2872
3231
  /// Mirrors Android's `nonMentionRanges()` — formatting is applied only to these
2873
3232
  /// 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:@"https"]) {
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]; // Use fileURLWithPath for local files
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:@"https"]) {
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]; // Use fileURLWithPath for local files
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
- NSTimeInterval interval = (NSTimeInterval)atTime;
100
- bool res = [audioPlayer playAtTime:interval];
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.10",
3
+ "version": "5.4.1",
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,10 @@
79
81
  "react": "*",
80
82
  "react-native": "*",
81
83
  "react-native-gesture-handler": "*",
84
+ "react-native-localize": "*",
85
+ "react-native-safe-area-context": "*",
82
86
  "react-native-svg": "*",
83
- "react-native-video": "*",
84
- "react-native-localize": "*"
87
+ "react-native-video": "*"
85
88
  },
86
89
  "jest": {
87
90
  "preset": "react-native",
@@ -121,4 +124,4 @@
121
124
  "node_modules/",
122
125
  "lib/"
123
126
  ]
124
- }
127
+ }
@@ -18,6 +18,7 @@ Pod::Spec.new do |s|
18
18
  s.source_files = "ios/**/*.{h,m,mm,swift}"
19
19
 
20
20
  s.static_framework = true # Set static_framework for the main spec if needed
21
+ s.frameworks = ["PhotosUI"]
21
22
  s.dependency "React-Core"
22
23
 
23
24
  s.subspec "Video" do |ss|