@cometchat/chat-uikit-react-native 5.5.4 → 5.7.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.
Files changed (215) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/CometChatKeyboardModule.kt +101 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
  3. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
  4. package/android/src/main/java/com/reactnativecometchatuikit/KeyboardDirectionWatcher.kt +64 -0
  5. package/android/src/main/java/com/reactnativecometchatuikit/KeyboardLanguageDirection.kt +44 -0
  6. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +287 -49
  7. package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
  8. package/ios/CCLocalFileGuard.h +19 -0
  9. package/ios/CCLocalFileGuard.m +34 -0
  10. package/ios/CometChatKeyboardModule.m +9 -0
  11. package/ios/CometChatKeyboardModule.swift +71 -0
  12. package/ios/FileManager.m +70 -6
  13. package/ios/KeyboardLanguageDirection.swift +24 -0
  14. package/ios/RichTextEditorView.swift +253 -51
  15. package/ios/RichTextEditorViewManager.m +1 -0
  16. package/ios/VideoManager.m +1 -1
  17. package/package.json +18 -3
  18. package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +41 -57
  19. package/src/CometChatAIAssistantChatHistory/Skeleton.tsx +4 -1
  20. package/src/CometChatAIAssistantChatHistory/style.ts +5 -2
  21. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +145 -63
  22. package/src/CometChatCompactMessageComposer/styles.ts +7 -7
  23. package/src/CometChatConversations/CometChatConversations.tsx +276 -147
  24. package/src/CometChatConversations/Skeleton.tsx +4 -1
  25. package/src/CometChatConversations/style.ts +1 -1
  26. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +39 -18
  27. package/src/CometChatGroupMembers/Skeleton.tsx +4 -1
  28. package/src/CometChatGroupMembers/style.ts +6 -4
  29. package/src/CometChatGroups/CometChatGroups.tsx +74 -58
  30. package/src/CometChatGroups/GroupsStyle.ts +1 -1
  31. package/src/CometChatGroups/Skeleton.tsx +4 -1
  32. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +190 -96
  33. package/src/CometChatMessageComposer/styles.tsx +1 -1
  34. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +28 -15
  35. package/src/CometChatMessageHeader/listners.ts +76 -56
  36. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +8 -1
  37. package/src/CometChatMessageInformation/Skeleton.tsx +4 -1
  38. package/src/CometChatMessageList/CometChatMessageList.tsx +1465 -313
  39. package/src/CometChatMessageList/SwipeToReplyView.tsx +61 -0
  40. package/src/CometChatMessageList/style.ts +32 -32
  41. package/src/CometChatMessageList/swipeToReply.ts +25 -0
  42. package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +81 -10
  43. package/src/CometChatNotificationFeed/style.ts +1 -1
  44. package/src/CometChatNotificationFeed/utils.ts +17 -18
  45. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +82 -3
  46. package/src/CometChatPinnedMessages/style.ts +5 -5
  47. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +2 -0
  48. package/src/CometChatRichTextEditor/index.tsx +3 -0
  49. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +83 -15
  50. package/src/CometChatSavedMessages/style.ts +3 -3
  51. package/src/CometChatSearch/CometChatSearch.tsx +391 -136
  52. package/src/CometChatSearch/Skeleton.tsx +4 -1
  53. package/src/CometChatSearch/searchLabels.ts +26 -0
  54. package/src/CometChatSearch/style.ts +7 -7
  55. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +34 -8
  56. package/src/CometChatThreadHeader/Header.tsx +2 -2
  57. package/src/CometChatUsers/CometChatUsers.tsx +10 -1
  58. package/src/CometChatUsers/Skeleton.tsx +4 -1
  59. package/src/CometChatUsers/style.ts +1 -1
  60. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +27 -1
  61. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +16 -4
  62. package/src/calls/CometChatCallLogs/Skeleton.tsx +4 -1
  63. package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +11 -3
  64. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +10 -2
  65. package/src/extensions/CollaborativeBubble/style.ts +4 -4
  66. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +1 -1
  67. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +1 -1
  68. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +11 -6
  69. package/src/extensions/LinkPreview/style.ts +6 -6
  70. package/src/extensions/Polls/Header.tsx +1 -1
  71. package/src/extensions/Polls/Polls.tsx +25 -12
  72. package/src/extensions/Polls/PollsBubble.tsx +10 -6
  73. package/src/extensions/Polls/style.ts +4 -4
  74. package/src/extensions/Stickers/CometChatStickerKeyboard/CometChatStickerKeyboard.tsx +2 -2
  75. package/src/extensions/Stickers/CometChatStickerKeyboard/Skeleton.tsx +1 -1
  76. package/src/extensions/Stickers/CometChatStickerKeyboard/style.ts +1 -1
  77. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +4 -2
  78. package/src/index.ts +11 -1
  79. package/src/shared/CometChatUiKit/CometChatUIKit.ts +102 -2
  80. package/src/shared/CometChatUiKit/UIKitSettings.ts +28 -0
  81. package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
  82. package/src/shared/events/index.ts +4 -0
  83. package/src/shared/events/offline.ts +28 -0
  84. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +18 -13
  85. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +15 -7
  86. package/src/shared/formatters/CometChatTextFormatter.ts +11 -0
  87. package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +7 -4
  88. package/src/shared/framework/MessageDataSource.tsx +51 -108
  89. package/src/shared/helper/LocalizedDateHelper.ts +64 -4
  90. package/src/shared/helper/helperFunctions.ts +71 -4
  91. package/src/shared/helper/keyboardDirection.ts +54 -0
  92. package/src/shared/helper/layoutDirection.ts +205 -0
  93. package/src/shared/helper/pluralRules.ts +67 -0
  94. package/src/shared/helper/textDirection.ts +118 -0
  95. package/src/shared/icons/Icon.tsx +37 -2
  96. package/src/shared/icons/components/format-list-numbered-rtl.tsx +15 -0
  97. package/src/shared/index.ts +2 -0
  98. package/src/shared/offline/OfflineHub.ts +651 -0
  99. package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
  100. package/src/shared/offline/OfflineViews.tsx +222 -0
  101. package/src/shared/offline/conversationPins.ts +137 -0
  102. package/src/shared/offline/conversations.ts +325 -0
  103. package/src/shared/offline/frameProbe.ts +24 -0
  104. package/src/shared/offline/gate.ts +94 -0
  105. package/src/shared/offline/groupActions.ts +81 -0
  106. package/src/shared/offline/identity.ts +162 -0
  107. package/src/shared/offline/index.ts +76 -0
  108. package/src/shared/offline/media.ts +247 -0
  109. package/src/shared/offline/notices.ts +84 -0
  110. package/src/shared/offline/reconcile.ts +296 -0
  111. package/src/shared/offline/searchOutcome.ts +62 -0
  112. package/src/shared/offline/send.ts +430 -0
  113. package/src/shared/offline/stateContract.ts +85 -0
  114. package/src/shared/offline/threadReplies.ts +125 -0
  115. package/src/shared/offline/twoPhase.ts +372 -0
  116. package/src/shared/offline/unsentActions.ts +168 -0
  117. package/src/shared/offline/useOfflineMediaUri.ts +87 -0
  118. package/src/shared/offline/useOfflineReconnect.ts +25 -0
  119. package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
  120. package/src/shared/offline/useOfflineUploadTray.ts +76 -0
  121. package/src/shared/offline/usePresenceHidden.ts +33 -0
  122. package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +2 -0
  123. package/src/shared/resources/CometChatLocalizeNew/resources/ar/translation.json +720 -0
  124. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -3
  125. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +75 -4
  126. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +74 -3
  127. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +75 -4
  128. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +74 -3
  129. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +74 -3
  130. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +74 -3
  131. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +74 -3
  132. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +74 -3
  133. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +82 -3
  134. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +74 -3
  135. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +74 -3
  136. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +74 -3
  137. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +90 -3
  138. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +74 -3
  139. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +74 -3
  140. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +74 -3
  141. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +74 -3
  142. package/src/shared/services/UploadQueueService.ts +106 -1
  143. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +13 -12
  144. package/src/shared/utils/CometChatMessagePreview/style.ts +1 -1
  145. package/src/shared/utils/MessageReceiptUtils.ts +8 -0
  146. package/src/shared/utils/MessageUtils.tsx +14 -14
  147. package/src/shared/utils/PermissionUtil.ts +16 -5
  148. package/src/shared/utils/SavedMessagesHelper.ts +18 -1
  149. package/src/shared/utils/attachmentLimits.ts +3 -2
  150. package/src/shared/utils/catchUpCursor.ts +36 -0
  151. package/src/shared/utils/conversationUtils.ts +3 -5
  152. package/src/shared/utils/failedMessageRetry.ts +73 -0
  153. package/src/shared/utils/fileIconFontSize.ts +10 -0
  154. package/src/shared/utils/fileSizeLabel.ts +16 -0
  155. package/src/shared/utils/groupActionText.ts +75 -0
  156. package/src/shared/utils/messageIdentity.ts +38 -0
  157. package/src/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.tsx +12 -8
  158. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +1 -1
  159. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +5 -3
  160. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +22 -17
  161. package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +45 -12
  162. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +16 -10
  163. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +20 -8
  164. package/src/shared/views/CometChatBadge/CometChatBadge.tsx +8 -4
  165. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +6 -2
  166. package/src/shared/views/CometChatComposerErrorBanner.tsx +3 -1
  167. package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +8 -3
  168. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +2 -2
  169. package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +5 -3
  170. package/src/shared/views/CometChatEmojiKeyboard/emojis.ts +8 -8
  171. package/src/shared/views/CometChatEmojiKeyboard/style.ts +2 -2
  172. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
  173. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +65 -15
  174. package/src/shared/views/CometChatImageViewerModal/ImageViewerModal.tsx +7 -3
  175. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +56 -25
  176. package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +41 -21
  177. package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +7 -3
  178. package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +7 -3
  179. package/src/shared/views/CometChatList/CometChatList.tsx +478 -21
  180. package/src/shared/views/CometChatList/Header.tsx +5 -2
  181. package/src/shared/views/CometChatList/sectionLetter.ts +44 -0
  182. package/src/shared/views/CometChatList/styles.ts +7 -7
  183. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +6 -4
  184. package/src/shared/views/CometChatMediaRecorder/CometChatAudioPlayer.tsx +16 -10
  185. package/src/shared/views/CometChatMediaRecorder/Timer.tsx +5 -1
  186. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +43 -16
  187. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +24 -4
  188. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +19 -2
  189. package/src/shared/views/CometChatNewMessageIndicator/CometChatNewMessageIndicator.tsx +3 -2
  190. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +59 -12
  191. package/src/shared/views/CometChatReactionList/ReactionListStyle.tsx +2 -2
  192. package/src/shared/views/CometChatReactionList/Skeleton.tsx +4 -1
  193. package/src/shared/views/CometChatReactions/CometChatReactions.tsx +6 -2
  194. package/src/shared/views/CometChatReportDialog/CometChatReportDialog.tsx +7 -3
  195. package/src/shared/views/CometChatReportDialog/style.ts +1 -1
  196. package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +1 -1
  197. package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
  198. package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +20 -13
  199. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +3 -2
  200. package/src/shared/views/CometChatSuggestionList/Skeleton.tsx +1 -1
  201. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +29 -3
  202. package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +20 -30
  203. package/src/shared/views/CometChatTooltipMenu/tooltipPosition.ts +43 -0
  204. package/src/shared/views/CometChatVideoBubble/style.ts +2 -2
  205. package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +4 -1
  206. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +58 -24
  207. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
  208. package/src/shared/views/SenderLabel.tsx +41 -0
  209. package/src/theme/default/default.ts +1 -1
  210. package/src/theme/type.ts +17 -0
  211. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  212. package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
  213. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  214. package/android/.gradle/7.4/gc.properties +0 -0
  215. package/android/.gradle/vcs-1/gc.properties +0 -0
@@ -17,6 +17,7 @@ import { SearchStyle, getSearchStyleLight, getSearchStyleDark } from './style';
17
17
  import { deepMerge } from '../shared/helper/helperFunctions';
18
18
  import { DeepPartial } from '../shared/helper/types';
19
19
  import { getCometChatTranslation } from '../shared/resources/CometChatLocalizeNew/LocalizationManager';
20
+ import { fileIconFontSize } from "../shared/utils/fileIconFontSize";
20
21
  import { CommonUtils } from '../shared/utils/CommonUtils';
21
22
  import { selectLinkPreview } from "../shared/utils/linkPreviewSelection";
22
23
  import { unescapeTypedMentionTokens } from "../shared/utils/mentionTokens";
@@ -26,6 +27,20 @@ import { CometChatTextFormatter } from '../shared/formatters/CometChatTextFormat
26
27
  import { applyRawFormatters } from '../shared/formatters/applyRawFormatters';
27
28
  import { ExtensionConstants } from '../extensions/ExtensionConstants';
28
29
  import { getExtensionData } from '../extensions/ExtensionModerator';
30
+ import { LayoutDirectionContext, directionStyle, useComponentLayoutDirection, TEXT_START, useInputTextAlign } from "../shared/helper/layoutDirection";
31
+ import { SenderLabel } from "../shared/views/SenderLabel";
32
+ import { stripBidiControls } from "../shared/helper/textDirection";
33
+ import { mediaCountLabel, monthHeaderLabel } from "./searchLabels";
34
+ import { readListPage } from "../shared/offline/twoPhase";
35
+ import { useOfflineSessionEnded } from "../shared/offline/useOfflineSessionEnded";
36
+ import { useOfflineReconnect } from "../shared/offline/useOfflineReconnect";
37
+ import { isOfflineOn } from "../shared/offline/gate";
38
+ import { ConnectStateView } from "../shared/offline/OfflineViews";
39
+ import { searchOfflineOutcome, type SearchRead } from "../shared/offline/searchOutcome";
40
+ import { OFFLINE_STRING_KEYS } from "../shared/offline/notices";
41
+ import { CONTRACT_IDS } from "../shared/offline/stateContract";
42
+ import { ErrorEmptyView } from "../shared/views/ErrorEmptyView/ErrorEmptyView";
43
+ import { CometChatRetryButton } from "../shared/views/CometChatRetryButton/CometChatRetryButton";
29
44
 
30
45
 
31
46
  /** Module-level formatter for search previews — reused across renders (no GC churn). */
@@ -123,6 +138,85 @@ function hasValidMessageSearchCriteria(searchKeyword: string, filters: CometChat
123
138
  return filters.some(filter => validMessageFilters.includes(filter));
124
139
  }
125
140
 
141
+ const CONVERSATION_SCOPE_FILTERS = [CometChatSearchFilter.Unread, CometChatSearchFilter.Groups];
142
+ const MESSAGE_SCOPE_FILTERS = [
143
+ CometChatSearchFilter.Photos,
144
+ CometChatSearchFilter.Videos,
145
+ CometChatSearchFilter.Documents,
146
+ CometChatSearchFilter.Audio,
147
+ CometChatSearchFilter.Links
148
+ ];
149
+
150
+ interface SearchScopeContext {
151
+ searchText: string;
152
+ activeFilters: CometChatSearchFilter[];
153
+ searchIn: CometChatSearchScope[];
154
+ uid?: string;
155
+ guid?: string;
156
+ }
157
+
158
+ /**
159
+ * Whether the conversations scope is part of the search. It decides both what is shown and what is read,
160
+ * so a scope that is not shown is never read and cannot leave a stale state behind (as Android's
161
+ * getSearchMode: a keyword with only message filters searches messages only).
162
+ */
163
+ function isConversationScopeActive({ searchText, activeFilters, searchIn, uid, guid }: SearchScopeContext): boolean {
164
+ // If searchIn is empty, search in both conversations and messages
165
+ const effectiveSearchIn = searchIn.length === 0
166
+ ? [CometChatSearchScope.Conversations, CometChatSearchScope.Messages]
167
+ : searchIn;
168
+
169
+ // Don't render conversations if searchIn doesn't include conversations scope
170
+ if (!effectiveSearchIn.includes(CometChatSearchScope.Conversations)) {
171
+ return false;
172
+ }
173
+
174
+ // Don't render conversations if uid or guid is present (searching within specific user/group)
175
+ if (uid || guid) {
176
+ return false;
177
+ }
178
+
179
+ if (searchText && searchText.trim() !== "" && activeFilters.length === 0) {
180
+ return true;
181
+ }
182
+
183
+ if (activeFilters.length > 0) {
184
+ return activeFilters.some(filter => CONVERSATION_SCOPE_FILTERS.includes(filter));
185
+ }
186
+
187
+ return false;
188
+ }
189
+
190
+ /** Whether the messages scope is part of the search; see isConversationScopeActive. */
191
+ function isMessageScopeActive({ searchText, activeFilters, searchIn, uid, guid }: SearchScopeContext): boolean {
192
+ // If searchIn is empty, search in both conversations and messages
193
+ const effectiveSearchIn = searchIn.length === 0
194
+ ? [CometChatSearchScope.Conversations, CometChatSearchScope.Messages]
195
+ : searchIn;
196
+
197
+ // Don't render messages if searchIn doesn't include messages scope
198
+ if (!effectiveSearchIn.includes(CometChatSearchScope.Messages)) {
199
+ return false;
200
+ }
201
+
202
+ // Always render messages if uid or guid is present (searching within specific user/group)
203
+ if (uid || guid) {
204
+ return true;
205
+ }
206
+
207
+ if (searchText && searchText.trim() !== "" && activeFilters.length === 0) {
208
+ return true;
209
+ }
210
+
211
+ if (activeFilters.length > 0) {
212
+ // Show messages if any message filter is selected and no conversation filter is selected
213
+ return activeFilters.some(filter => MESSAGE_SCOPE_FILTERS.includes(filter)) &&
214
+ !activeFilters.some(filter => CONVERSATION_SCOPE_FILTERS.includes(filter));
215
+ }
216
+
217
+ return false;
218
+ }
219
+
126
220
  interface SearchState {
127
221
  searchText: string;
128
222
  conversations: CometChat.Conversation[];
@@ -244,6 +338,8 @@ function searchStateReducer(state: SearchState, action: SearchAction): SearchSta
244
338
  * Props for the CometChatSearch component
245
339
  */
246
340
  interface CometChatSearchProps {
341
+ /** Lays this component out `"ltr"` or `"rtl"`, overriding the kit's global `layoutDirection`. Not set = inherit. */
342
+ layoutDirection?: "ltr" | "rtl";
247
343
  /**
248
344
  * Callback triggered when the back button is clicked
249
345
  * Use this to handle navigation when user clicks the back button
@@ -445,8 +541,8 @@ const DocumentTypeIcon = ({ width = 48, height = 48 }: { width?: number; height?
445
541
  d='M55.6667 23.332L67 23.332L50.3333 6.66536L50.3333 17.9987C50.3333 20.9442 52.7212 23.332 55.6667 23.332Z'
446
542
  fill='#ACA0E8'
447
543
  />
448
- <SvgText x={40} y={59} textAnchor='middle' fontSize={15} fontWeight='700' fill='#FFFFFF'>
449
- FILE
544
+ <SvgText x={40} y={59} textAnchor='middle' fontSize={fileIconFontSize(t('MESSAGE_FILE').toUpperCase())} fontWeight='700' fill='#FFFFFF'>
545
+ {t('MESSAGE_FILE').toUpperCase()}
450
546
  </SvgText>
451
547
  </G>
452
548
  </Svg>
@@ -703,10 +799,10 @@ const ConversationItem = React.memo<ConversationItemProps>((
703
799
  >
704
800
  {renderLeadingView()}
705
801
  <View style={mergedStyles.conversationItemStyle?.contentStyle}>
706
- <Text style={mergedStyles.conversationItemStyle?.titleStyle} numberOfLines={1}>
707
- {conversation.getConversationWith().getName()}
802
+ <Text style={[TEXT_START, mergedStyles.conversationItemStyle?.titleStyle]} numberOfLines={1}>
803
+ {stripBidiControls(conversation.getConversationWith().getName())}
708
804
  </Text>
709
- <Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
805
+ <Text style={[TEXT_START, mergedStyles.conversationItemStyle?.subtitleStyle]} numberOfLines={2}>
710
806
  {formatPreviewText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage(), textFormatters)}
711
807
  </Text>
712
808
  </View>
@@ -757,13 +853,17 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
757
853
  audioMessageItemView,
758
854
  videoMessageItemView,
759
855
  documentMessageItemView,
760
- linkMessageItemView
856
+ linkMessageItemView,
857
+ layoutDirection,
761
858
  }) => {
859
+ // ENG-41333: own setting → enclosing component → global; drives the root and the context.
860
+ const direction = useComponentLayoutDirection(layoutDirection);
762
861
  const [searchState, dispatch] = useReducer(searchStateReducer, initialState);
763
862
  const [searchValue, setSearchValue] = useState("");
764
863
  const [loggedInUser, setLoggedInUser] = useState<CometChat.User | null>(null);
765
864
 
766
865
  const theme = useTheme();
866
+ const inputAlign = useInputTextAlign(); // ENG-41384
767
867
  const errorHandler = useCometChatErrorHandler(onError);
768
868
  const timeoutIdRef = useRef<any | null>(null);
769
869
  const searchInputRef = useRef<React.ComponentRef<typeof TextInput>>(null);
@@ -859,7 +959,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
859
959
  <View style={[mergedStyles.searchInputContainerStyle]}>
860
960
  <TextInput
861
961
  ref={searchInputRef}
862
- style={[mergedStyles.searchInputStyle]}
962
+ style={[inputAlign, mergedStyles.searchInputStyle]}
863
963
  value={searchValue}
864
964
  onChangeText={handleSearch}
865
965
  placeholder={searchPlaceholder}
@@ -869,7 +969,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
869
969
  <TouchableOpacity
870
970
  style={[mergedStyles.clearButtonStyle]}
871
971
  onPress={handleClearSearch}
872
- accessibilityLabel="Clear search"
972
+ accessibilityLabel={t("CLEAR_SEARCH")}
873
973
  >
874
974
  <Icon
875
975
  name='close'
@@ -1048,6 +1148,22 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1048
1148
  // ============================================================================
1049
1149
  // CONVERSATIONS SEARCH LOGIC (moved from useCometChatSearchConversationsList.ts)
1050
1150
  // ============================================================================
1151
+ // Offline ON (D84 rule 7, as Android's updateFinalStateIfCompleted): a scope whose read ended not connected
1152
+ // with nothing saved for it. Whether that shows "Connect to search" depends on both scopes (see
1153
+ // searchOfflineOutcome): a keyword that could not reach the server, or both scopes failed. A keyword
1154
+ // has no cache (BEH-SNAP-04); a filter may. `keyword` = the read carried one. Never set with offline off.
1155
+ type OfflineMiss = { keyword: boolean } | null;
1156
+ const [offlineSearchError, setOfflineSearchError] = useState<{ conversations: OfflineMiss; messages: OfflineMiss }>({
1157
+ conversations: null,
1158
+ messages: null,
1159
+ });
1160
+ // Offline ON: a real failure's onError is held until both scopes have ended, because Android reports it
1161
+ // only when both scopes failed or results stay on screen; one failing scope with nothing shown is the plain
1162
+ // empty state with no onError. Never filled with offline off (onError fires at once, as before).
1163
+ const pendingSearchErrorsRef = useRef<{
1164
+ conversations: { error: unknown; context: string } | null;
1165
+ messages: { error: unknown; context: string } | null;
1166
+ }>({ conversations: null, messages: null });
1051
1167
  const [conversationState, setConversationState] = useState({
1052
1168
  conversationList: [] as CometChat.Conversation[],
1053
1169
  fetchState: States.loaded,
@@ -1058,6 +1174,9 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1058
1174
  const lastConversationSearchKeyword = useRef<string>(searchState.searchText);
1059
1175
  const lastConversationActiveFilters = useRef<CometChatSearchFilter[]>(searchState.activeFilters);
1060
1176
  const isConversationMoreResultsLoading = useRef<boolean>(false);
1177
+ // Bumped by every new conversation search (and a session end): a read for an older keyword or filter
1178
+ // that answers late is dropped, so it never replaces or extends the newer search's results.
1179
+ const conversationSearchGenRef = useRef(0);
1061
1180
 
1062
1181
  // ============================================================================
1063
1182
  // MESSAGES SEARCH LOGIC (moved from useCometChatSearchMessagesList.ts)
@@ -1067,11 +1186,22 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1067
1186
  fetchState: States.loaded,
1068
1187
  hasMoreResults: false,
1069
1188
  });
1189
+ // Offline ON: nothing of the old session stays on screen (UIK-LIFE-01).
1190
+ useOfflineSessionEnded(() => {
1191
+ conversationSearchGenRef.current++;
1192
+ messageSearchGenRef.current++;
1193
+ conversationRequestRef.current = null;
1194
+ messageRequestRef.current = null;
1195
+ setOfflineSearchError({ conversations: null, messages: null });
1196
+ setConversationState({ conversationList: [], fetchState: States.loaded, hasMoreResults: false });
1197
+ setMessageState({ messageList: [], fetchState: States.loaded, hasMoreResults: false });
1198
+ });
1070
1199
 
1071
1200
  const messageRequestRef = useRef<CometChat.MessagesRequest | null>(null);
1072
1201
  const lastMessageSearchKeyword = useRef<string>(searchState.searchText);
1073
1202
  const lastMessageActiveFilters = useRef<CometChatSearchFilter[]>(searchState.activeFilters);
1074
1203
  const isMessageMoreResultsLoading = useRef<boolean>(false);
1204
+ const messageSearchGenRef = useRef(0); // as conversationSearchGenRef, for message results
1075
1205
 
1076
1206
  // ============================================================================
1077
1207
  // CONVERSATION SEARCH FUNCTIONS
@@ -1105,9 +1235,14 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1105
1235
  return;
1106
1236
  }
1107
1237
 
1238
+ const searchGen = conversationSearchGenRef.current;
1108
1239
  try {
1109
1240
  isConversationMoreResultsLoading.current = true;
1110
- const moreConversations = await conversationRequestRef.current.fetchNext();
1241
+ // Offline ON: two-phase (a filter is answered from the device); OFF: today's fetch.
1242
+ const page = await readListPage<CometChat.Conversation>(conversationRequestRef.current, "next");
1243
+ if (searchGen !== conversationSearchGenRef.current) return; // the search changed while it read
1244
+ const moreConversations = page.rows;
1245
+ if (page.offline && moreConversations.length === 0) return;
1111
1246
 
1112
1247
  if (moreConversations.length > 0) {
1113
1248
  setConversationState(prev => ({
@@ -1124,15 +1259,22 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1124
1259
  } catch (error) {
1125
1260
  errorHandler(error, "loadMoreConversations");
1126
1261
  } finally {
1127
- isConversationMoreResultsLoading.current = false;
1262
+ // A newer search reset the flag for its own reads: this stale one must not clear it.
1263
+ if (searchGen === conversationSearchGenRef.current) isConversationMoreResultsLoading.current = false;
1128
1264
  }
1129
1265
  }, [errorHandler, conversationState.hasMoreResults]);
1130
1266
 
1131
1267
  const searchConversations = useCallback(async () => {
1268
+ const searchGen = ++conversationSearchGenRef.current;
1269
+ isConversationMoreResultsLoading.current = false; // a load-more of the old search is dropped when it lands
1270
+ setOfflineSearchError(prev => (prev.conversations ? { ...prev, conversations: null } : prev));
1271
+ pendingSearchErrorsRef.current.conversations = null;
1132
1272
  try {
1133
1273
  setConversationState(prev => ({ ...prev, fetchState: States.loading }));
1134
1274
 
1135
- if (!hasValidConversationSearchCriteria(searchState.searchText, searchState.activeFilters)) {
1275
+ // A scope that is not part of this search (not shown) is not read, as on Android.
1276
+ if (!isConversationScopeActive({ searchText: searchState.searchText, activeFilters: searchState.activeFilters, searchIn, uid, guid }) ||
1277
+ !hasValidConversationSearchCriteria(searchState.searchText, searchState.activeFilters)) {
1136
1278
  setConversationState(prev => ({
1137
1279
  ...prev,
1138
1280
  conversationList: [],
@@ -1144,7 +1286,23 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1144
1286
 
1145
1287
  const request = buildConversationsRequest();
1146
1288
  conversationRequestRef.current = request;
1147
- const conversations = await request.fetchNext();
1289
+ // Offline ON: two-phase, so a filter is answered from the device; a keyword has no cache.
1290
+ // OFF: today's fetch.
1291
+ const page = await readListPage<CometChat.Conversation>(request, "next");
1292
+ if (searchGen !== conversationSearchGenRef.current) return; // a newer search owns the results
1293
+ const conversations = page.rows;
1294
+ // D84 rule 7 (as Android): not connected with nothing saved is a failed read when it carried a keyword
1295
+ // (no cache) or the SDK gave no cached phase. A filter read answered by its (empty) cached phase found
1296
+ // nothing: not a failure, so it falls through to the empty list below. What a failed read shows (no
1297
+ // onError) is decided across both scopes in searchOfflineOutcome.
1298
+ const conversationKeyword = searchState.searchText.trim() !== "";
1299
+ if (page.offline && conversations.length === 0 && (conversationKeyword || !page.cachedDelivered)) {
1300
+ setOfflineSearchError(prev => ({ ...prev, conversations: { keyword: conversationKeyword } }));
1301
+ setConversationState({ conversationList: [], fetchState: States.error, hasMoreResults: false });
1302
+ return;
1303
+ }
1304
+ // D84 rule 2: saved rows are shown and the server read could not be reached: the rows stay,
1305
+ // nothing is reported (not connected is not an error).
1148
1306
 
1149
1307
  if (conversations.length > 0) {
1150
1308
  const limit = (guid || uid || searchState.activeFilters.length > 0) ? 30 : 3;
@@ -1161,10 +1319,17 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1161
1319
  });
1162
1320
  }
1163
1321
  } catch (error) {
1164
- errorHandler(error, "searchConversations");
1165
- setConversationState(prev => ({ ...prev, fetchState: States.error }));
1322
+ if (isOfflineOn() && searchGen === conversationSearchGenRef.current) {
1323
+ // Offline ON: onError waits until both scopes have ended (see the flush effect below).
1324
+ pendingSearchErrorsRef.current.conversations = { error, context: "searchConversations" };
1325
+ } else {
1326
+ errorHandler(error, "searchConversations");
1327
+ }
1328
+ if (searchGen === conversationSearchGenRef.current) {
1329
+ setConversationState(prev => ({ ...prev, fetchState: States.error }));
1330
+ }
1166
1331
  }
1167
- }, [searchState.searchText, searchState.activeFilters, buildConversationsRequest, guid, uid, errorHandler]);
1332
+ }, [searchState.searchText, searchState.activeFilters, buildConversationsRequest, guid, uid, searchIn, errorHandler]);
1168
1333
 
1169
1334
  // ============================================================================
1170
1335
  // MESSAGE SEARCH FUNCTIONS
@@ -1228,9 +1393,14 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1228
1393
  return;
1229
1394
  }
1230
1395
 
1396
+ const searchGen = messageSearchGenRef.current;
1231
1397
  try {
1232
1398
  isMessageMoreResultsLoading.current = true;
1233
- const moreMessages = await messageRequestRef.current.fetchPrevious();
1399
+ // Offline ON: two-phase (a filter is answered from the device); OFF: today's fetch.
1400
+ const page = await readListPage<CometChat.BaseMessage>(messageRequestRef.current, "previous");
1401
+ if (searchGen !== messageSearchGenRef.current) return; // the search changed while it read
1402
+ const moreMessages = page.rows;
1403
+ if (page.offline && moreMessages.length === 0) return;
1234
1404
 
1235
1405
  if (moreMessages.length > 0) {
1236
1406
 
@@ -1254,15 +1424,21 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1254
1424
  } catch (error) {
1255
1425
  errorHandler(error, "loadMoreMessages");
1256
1426
  } finally {
1257
- isMessageMoreResultsLoading.current = false;
1427
+ if (searchGen === messageSearchGenRef.current) isMessageMoreResultsLoading.current = false;
1258
1428
  }
1259
1429
  }, [errorHandler, messageState.hasMoreResults]);
1260
1430
 
1261
1431
  const searchMessages = useCallback(async () => {
1432
+ const searchGen = ++messageSearchGenRef.current;
1433
+ isMessageMoreResultsLoading.current = false; // a load-more of the old search is dropped when it lands
1434
+ setOfflineSearchError(prev => (prev.messages ? { ...prev, messages: null } : prev));
1435
+ pendingSearchErrorsRef.current.messages = null;
1262
1436
  try {
1263
1437
  setMessageState(prev => ({ ...prev, fetchState: States.loading }));
1264
1438
 
1265
- if (!hasValidMessageSearchCriteria(searchState.searchText, searchState.activeFilters)) {
1439
+ // A scope that is not part of this search (not shown) is not read, as on Android.
1440
+ if (!isMessageScopeActive({ searchText: searchState.searchText, activeFilters: searchState.activeFilters, searchIn, uid, guid }) ||
1441
+ !hasValidMessageSearchCriteria(searchState.searchText, searchState.activeFilters)) {
1266
1442
  setMessageState(prev => ({
1267
1443
  ...prev,
1268
1444
  messageList: [],
@@ -1274,7 +1450,17 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1274
1450
 
1275
1451
  const request = buildMessagesRequest();
1276
1452
  messageRequestRef.current = request;
1277
- const messages = await request.fetchPrevious();
1453
+ // Offline ON: as for conversations above. OFF: today's fetch.
1454
+ const page = await readListPage<CometChat.BaseMessage>(request, "previous");
1455
+ if (searchGen !== messageSearchGenRef.current) return; // a newer search owns the results
1456
+ const messages = page.rows;
1457
+ const messageKeyword = searchState.searchText.trim() !== "";
1458
+ if (page.offline && messages.length === 0 && (messageKeyword || !page.cachedDelivered)) {
1459
+ setOfflineSearchError(prev => ({ ...prev, messages: { keyword: messageKeyword } }));
1460
+ setMessageState({ messageList: [], fetchState: States.error, hasMoreResults: false });
1461
+ return;
1462
+ }
1463
+ // D84 rule 2: saved rows stay, nothing is reported offline.
1278
1464
 
1279
1465
  if (messages.length > 0) {
1280
1466
  const reversedList = messages.reverse();
@@ -1299,10 +1485,16 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1299
1485
  });
1300
1486
  }
1301
1487
  } catch (error) {
1302
- errorHandler(error, "searchMessages");
1303
- setMessageState(prev => ({ ...prev, fetchState: States.error }));
1488
+ if (isOfflineOn() && searchGen === messageSearchGenRef.current) {
1489
+ pendingSearchErrorsRef.current.messages = { error, context: "searchMessages" };
1490
+ } else {
1491
+ errorHandler(error, "searchMessages");
1492
+ }
1493
+ if (searchGen === messageSearchGenRef.current) {
1494
+ setMessageState(prev => ({ ...prev, fetchState: States.error }));
1495
+ }
1304
1496
  }
1305
- }, [searchState.searchText, searchState.activeFilters, buildMessagesRequest, guid, uid, errorHandler]);
1497
+ }, [searchState.searchText, searchState.activeFilters, buildMessagesRequest, guid, uid, searchIn, errorHandler]);
1306
1498
 
1307
1499
  // ============================================================================
1308
1500
  // SEARCH EFFECTS - Trigger searches when search text or filters change
@@ -1329,76 +1521,62 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1329
1521
  }
1330
1522
  }, [searchState.searchText, searchState.activeFilters, searchMessages]);
1331
1523
 
1332
- const shouldRenderConversations = useCallback(() => {
1333
- // If searchIn is empty, search in both conversations and messages
1334
- const effectiveSearchIn = searchIn.length === 0
1335
- ? [CometChatSearchScope.Conversations, CometChatSearchScope.Messages]
1336
- : searchIn;
1337
-
1338
- // Don't render conversations if searchIn doesn't include conversations scope
1339
- if (!effectiveSearchIn.includes(CometChatSearchScope.Conversations)) {
1340
- return false;
1341
- }
1342
-
1343
- // Don't render conversations if uid or guid is present (searching within specific user/group)
1344
- if (uid || guid) {
1345
- return false;
1346
- }
1347
-
1348
- // Define conversation filters
1349
- const conversationFilters = [CometChatSearchFilter.Unread, CometChatSearchFilter.Groups];
1350
-
1351
- if (searchState.searchText && searchState.searchText.trim() !== "" && searchState.activeFilters.length === 0) {
1352
- return true;
1353
- }
1354
-
1355
- if (searchState.activeFilters.length > 0) {
1356
- return searchState.activeFilters.some(filter => conversationFilters.includes(filter));
1357
- }
1358
-
1359
- return false;
1360
- }, [searchState.activeFilters, searchState.searchText, uid, guid, searchIn]);
1361
-
1362
- const shouldRenderMessages = useCallback(() => {
1363
- // If searchIn is empty, search in both conversations and messages
1364
- const effectiveSearchIn = searchIn.length === 0
1365
- ? [CometChatSearchScope.Conversations, CometChatSearchScope.Messages]
1366
- : searchIn;
1367
-
1368
- // Don't render messages if searchIn doesn't include messages scope
1369
- if (!effectiveSearchIn.includes(CometChatSearchScope.Messages)) {
1370
- return false;
1371
- }
1372
-
1373
- // Always render messages if uid or guid is present (searching within specific user/group)
1374
- if (uid || guid) {
1375
- return true;
1376
- }
1524
+ // D84 rule 8: a search showing "Connect to search" runs again once, by itself, when the
1525
+ // connection is back. Only offline ON listens; any other error is not re-run.
1526
+ const searchConversationsRef = useRef(searchConversations);
1527
+ searchConversationsRef.current = searchConversations;
1528
+ const searchMessagesRef = useRef(searchMessages);
1529
+ searchMessagesRef.current = searchMessages;
1530
+ // Which scopes to read again: set on every render from what the screen shows (see renderResults).
1531
+ // "Connect to search" runs the whole search again, as Android's reconnect re-run does; an error view
1532
+ // that has a not-connected scope runs that scope again (as before); the plain empty state of a
1533
+ // filter-only search runs nothing.
1534
+ const reconnectRerunRef = useRef({ conversations: false, messages: false });
1535
+ useOfflineReconnect(() => {
1536
+ const rerun = reconnectRerunRef.current;
1537
+ if (rerun.conversations) void searchConversationsRef.current();
1538
+ if (rerun.messages) void searchMessagesRef.current();
1539
+ });
1377
1540
 
1378
- // Define message filters
1379
- const messageFilters = [
1380
- CometChatSearchFilter.Photos,
1381
- CometChatSearchFilter.Videos,
1382
- CometChatSearchFilter.Documents,
1383
- CometChatSearchFilter.Audio,
1384
- CometChatSearchFilter.Links
1385
- ];
1541
+ /** The error view's Retry: both searches again. */
1542
+ const retrySearch = () => {
1543
+ void searchConversations();
1544
+ void searchMessages();
1545
+ };
1386
1546
 
1387
- // Define conversation filters
1388
- const conversationFilters = [CometChatSearchFilter.Unread, CometChatSearchFilter.Groups];
1547
+ const shouldRenderConversations = useCallback(
1548
+ () => isConversationScopeActive({ searchText: searchState.searchText, activeFilters: searchState.activeFilters, searchIn, uid, guid }),
1549
+ [searchState.activeFilters, searchState.searchText, uid, guid, searchIn]
1550
+ );
1389
1551
 
1390
- if (searchState.searchText && searchState.searchText.trim() !== "" && searchState.activeFilters.length === 0) {
1391
- return true;
1392
- }
1552
+ const shouldRenderMessages = useCallback(
1553
+ () => isMessageScopeActive({ searchText: searchState.searchText, activeFilters: searchState.activeFilters, searchIn, uid, guid }),
1554
+ [searchState.activeFilters, searchState.searchText, uid, guid, searchIn]
1555
+ );
1393
1556
 
1394
- if (searchState.activeFilters.length > 0) {
1395
- // Show messages if any message filter is selected and no conversation filter is selected
1396
- return searchState.activeFilters.some(filter => messageFilters.includes(filter)) &&
1397
- !searchState.activeFilters.some(filter => conversationFilters.includes(filter));
1557
+ /**
1558
+ * Offline ON: report the held real failures once both scopes have ended (Android updateFinalStateIfCompleted).
1559
+ * One scope failed and nothing is on screen: the plain empty state, nothing reported. Both scopes failed, or
1560
+ * rows stay on screen: onError, as before.
1561
+ */
1562
+ useEffect(() => {
1563
+ const pending = pendingSearchErrorsRef.current;
1564
+ if (!pending.conversations && !pending.messages) return;
1565
+ if (conversationState.fetchState === States.loading || messageState.fetchState === States.loading) return;
1566
+ const conversationsRendered = shouldRenderConversations();
1567
+ const messagesRendered = shouldRenderMessages();
1568
+ const nothingShown = conversationState.conversationList.length === 0 && messageState.messageList.length === 0;
1569
+ const failedScopes =
1570
+ (conversationsRendered && conversationState.fetchState === States.error ? 1 : 0) +
1571
+ (messagesRendered && messageState.fetchState === States.error ? 1 : 0);
1572
+ const report = !(nothingShown && failedScopes < 2);
1573
+ const held = [pending.conversations, pending.messages];
1574
+ pendingSearchErrorsRef.current = { conversations: null, messages: null };
1575
+ if (!report) return;
1576
+ for (const entry of held) {
1577
+ if (entry) errorHandler(entry.error, entry.context);
1398
1578
  }
1399
-
1400
- return false;
1401
- }, [searchState.activeFilters, searchState.searchText, uid, guid, searchIn]);
1579
+ });
1402
1580
 
1403
1581
  // Handle scroll-based fetching for messages
1404
1582
  const handleScrollEnd = useCallback((event: any) => {
@@ -1500,19 +1678,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1500
1678
  const firstName =
1501
1679
  atts[0]?.getName?.() || (message.getAttachment?.() as any)?.getName?.() || "";
1502
1680
 
1503
- // Title-case labels (no localization keys exist for these — t() would echo the UPPERCASE
1504
- // key back, which is why the counts rendered as "1 IMAGE"/"7 IMAGES").
1505
- const plural =
1506
- type === "video" ? "Videos"
1507
- : type === "image" ? "Images"
1508
- : type === "audio" ? "Audios"
1509
- : "Files";
1510
- const singular =
1511
- type === "video" ? "Video"
1512
- : type === "image" ? "Image"
1513
- : type === "audio" ? "Audio"
1514
- : "File";
1515
- const countLabel = `${count} ${count === 1 ? singular : plural}`;
1681
+ const countLabel = mediaCountLabel(type, count);
1516
1682
 
1517
1683
  const hasThumbnail = type === "image" || type === "video"; // +N lives on the thumbnail
1518
1684
  const result = hasThumbnail
@@ -1573,7 +1739,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1573
1739
  };
1574
1740
  const renderMessageSubtitle = (message: CometChat.BaseMessage) => {
1575
1741
  const sentByMe = message.getSender?.()?.getUid?.() === loggedInUser?.getUid?.();
1576
- const senderLabel = sentByMe ? t("YOU") || "You" : message.getSender()?.getName?.() || "";
1742
+ const senderName = sentByMe ? t("YOU") || "You" : message.getSender()?.getName?.() || "";
1577
1743
  const iconName = attachmentSubtitleIcon[message.getType()];
1578
1744
  return (
1579
1745
  <View style={styles.row}>
@@ -1581,10 +1747,11 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1581
1747
  overridden here — otherwise the short sender name sits inside a 90%-wide box, leaving a
1582
1748
  big gap before the icon and shoving the caption off-screen. Sender hugs its own text
1583
1749
  (flexGrow:0) and only ellipsizes (flexShrink:2) when a name is genuinely long. */}
1584
- <Text
1585
- style={[mergedStyles.messageItemStyle?.subtitleStyle, { width: undefined, flexGrow: 0, flexShrink: 2 }]}
1586
- numberOfLines={1}
1587
- >{`${senderLabel}: `}</Text>
1750
+ <SenderLabel
1751
+ name={senderName}
1752
+ textStyle={mergedStyles.messageItemStyle?.subtitleStyle}
1753
+ containerStyle={{ flexGrow: 0, flexShrink: 2 }}
1754
+ />
1588
1755
  {iconName ? (
1589
1756
  <Icon
1590
1757
  name={iconName as any}
@@ -1596,8 +1763,9 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1596
1763
  ) : null}
1597
1764
  <Text
1598
1765
  style={[
1766
+ TEXT_START, // ENG-41391: flex:1 reaches the far edge; iOS would put English text there.
1599
1767
  mergedStyles.messageItemStyle?.subtitleStyle,
1600
- { marginLeft: iconName ? 4 : 0, width: undefined, flex: 1 },
1768
+ { marginStart: iconName ? 4 : 0, width: undefined, flex: 1 },
1601
1769
  ]}
1602
1770
  numberOfLines={1}
1603
1771
  ellipsizeMode="tail"
@@ -1764,13 +1932,73 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1764
1932
 
1765
1933
  // Helper to format date for headers
1766
1934
  const getDateHeaderDate = useCallback((timestamp: number) => {
1767
- return new Date(timestamp * 1000).toLocaleDateString('en-US', { month: 'long', year: 'numeric' });
1935
+ return monthHeaderLabel(timestamp);
1768
1936
  }, []);
1769
1937
 
1938
+ /** "No results found": the app's own empty view, or the kit's. */
1939
+ const renderNoResults = () => {
1940
+ if (emptyView) {
1941
+ return emptyView();
1942
+ }
1943
+
1944
+ return (
1945
+ <View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
1946
+ <Icon
1947
+ name="empty-search"
1948
+ size={120}
1949
+ height={120}
1950
+ width={120}
1951
+ imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
1952
+ containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
1953
+ />
1954
+ <Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
1955
+ {t("SEARCH_NO_RESULTS_FOUND_TITLE") || "No Results Found"}
1956
+ </Text>
1957
+ <Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
1958
+ {t("SEARCH_NO_RESULTS_FOUND_SUBTITLE") || "We couldn't find any matches. Please try a different search keyword."}
1959
+ </Text>
1960
+ </View>
1961
+ );
1962
+ };
1963
+
1770
1964
  const renderResults = () => {
1771
1965
  const conversationsRendered = shouldRenderConversations();
1772
1966
  const messagesRendered = shouldRenderMessages();
1773
1967
 
1968
+ // Offline ON, nothing to show and a scope that ended in an error (D84): what shows is decided across both
1969
+ // scopes, as Android does (searchOfflineOutcome). "Connect to search" (rule 7): a keyword that could not
1970
+ // reach the server, or both scopes failed, and every failure was not-connected: an offline state, not an
1971
+ // error (no onError). A filter-only search where only one scope failed is the plain empty state. Any real
1972
+ // failure (rule 4) is the error view. The app's own empty / error view wins over the kit's. Never over rows.
1973
+ const nothingShown = conversationState.conversationList.length === 0 && messageState.messageList.length === 0;
1974
+ const readOf = (
1975
+ rendered: boolean,
1976
+ fetchState: States,
1977
+ miss: OfflineMiss
1978
+ ): SearchRead => ({
1979
+ ran: rendered,
1980
+ failure: rendered && fetchState === States.error ? (miss ? "notConnected" : "error") : null,
1981
+ keyword: !!miss?.keyword,
1982
+ });
1983
+ const searchActive = searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0;
1984
+ const offlineOutcome = searchOfflineOutcome({
1985
+ offlineOn: isOfflineOn() && searchActive,
1986
+ nothingShown,
1987
+ conversations: readOf(conversationsRendered, conversationState.fetchState, offlineSearchError.conversations),
1988
+ messages: readOf(messagesRendered, messageState.fetchState, offlineSearchError.messages),
1989
+ });
1990
+ // Read again once on reconnect (D84 rule 8): the whole search for "Connect to search"; a not-connected
1991
+ // scope of an error view; nothing for the plain empty state.
1992
+ reconnectRerunRef.current =
1993
+ offlineOutcome === "connectToSearch"
1994
+ ? { conversations: conversationsRendered, messages: messagesRendered }
1995
+ : offlineOutcome === "error"
1996
+ ? {
1997
+ conversations: conversationsRendered && !!offlineSearchError.conversations,
1998
+ messages: messagesRendered && !!offlineSearchError.messages,
1999
+ }
2000
+ : { conversations: false, messages: false };
2001
+
1774
2002
  // Initial empty state - no search text and no filters
1775
2003
  if ((!searchState.searchText || searchState.searchText.trim() === "") && searchState.activeFilters.length === 0) {
1776
2004
  if (emptyView) {
@@ -1805,6 +2033,52 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1805
2033
  return loadingView ? loadingView() : <Skeleton />;
1806
2034
  }
1807
2035
 
2036
+ if (offlineOutcome === "connectToSearch") {
2037
+ if (emptyView) {
2038
+ return emptyView();
2039
+ }
2040
+ return (
2041
+ <ConnectStateView
2042
+ testID={CONTRACT_IDS.emptyConnectToSearch}
2043
+ title={t(OFFLINE_STRING_KEYS.connectToSearchMessages)}
2044
+ subtitle={t(OFFLINE_STRING_KEYS.connectToSearchSubtitle)}
2045
+ containerStyle={mergedStyles.errorStateStyle?.containerStyle}
2046
+ titleStyle={mergedStyles.errorStateStyle?.titleStyle}
2047
+ subtitleStyle={mergedStyles.errorStateStyle?.subtitleStyle}
2048
+ />
2049
+ );
2050
+ }
2051
+ if (offlineOutcome === "empty") {
2052
+ return renderNoResults();
2053
+ }
2054
+ if (offlineOutcome === "error") {
2055
+ if (errorView) {
2056
+ return errorView();
2057
+ }
2058
+
2059
+ return (
2060
+ <ErrorEmptyView
2061
+ testID="CometChatSearch.error"
2062
+ title={t("OOPS")}
2063
+ subTitle={t("SOMETHING_WENT_WRONG")}
2064
+ tertiaryTitle={t("WRONG_TEXT_TRY_AGAIN")}
2065
+ Icon={
2066
+ <Icon
2067
+ name="error-state"
2068
+ size={theme.spacing.margin.m15 << 1}
2069
+ icon={mergedStyles.errorStateStyle?.icon}
2070
+ imageStyle={mergedStyles.errorStateStyle?.iconStyle}
2071
+ containerStyle={mergedStyles.errorStateStyle?.iconContainerStyle}
2072
+ />
2073
+ }
2074
+ containerStyle={mergedStyles.errorStateStyle?.containerStyle}
2075
+ titleStyle={mergedStyles.errorStateStyle?.titleStyle}
2076
+ subTitleStyle={mergedStyles.errorStateStyle?.subtitleStyle}
2077
+ RetryView={<CometChatRetryButton onPress={retrySearch} />}
2078
+ />
2079
+ );
2080
+ }
2081
+
1808
2082
  // Check if we have search text or filters but no actual results
1809
2083
  if ((searchState.searchText.trim() !== "" || searchState.activeFilters.length > 0) &&
1810
2084
  conversationState.conversationList.length === 0 &&
@@ -1814,28 +2088,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1814
2088
  conversationState.fetchState !== States.error &&
1815
2089
  messageState.fetchState !== States.error) {
1816
2090
  // No results found state
1817
- if (emptyView) {
1818
- return emptyView();
1819
- }
1820
-
1821
- return (
1822
- <View style={[mergedStyles.emptyStateStyle?.containerStyle]}>
1823
- <Icon
1824
- name="empty-search"
1825
- size={120}
1826
- height={120}
1827
- width={120}
1828
- imageStyle={mergedStyles.emptyStateStyle?.iconStyle}
1829
- containerStyle={mergedStyles.emptyStateStyle?.iconContainerStyle}
1830
- />
1831
- <Text style={[mergedStyles.emptyStateStyle?.titleStyle]}>
1832
- {t("SEARCH_NO_RESULTS_FOUND_TITLE") || "No Results Found"}
1833
- </Text>
1834
- <Text style={[mergedStyles.emptyStateStyle?.subtitleStyle]}>
1835
- {t("SEARCH_NO_RESULTS_FOUND_SUBTITLE") || "We couldn't find any matches. Please try a different search keyword."}
1836
- </Text>
1837
- </View>
1838
- );
2091
+ return renderNoResults();
1839
2092
  }
1840
2093
 
1841
2094
  // Show search results with actual item lists - USING SINGLE FLATLIST FOR VIRTUALIZATION
@@ -1881,7 +2134,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1881
2134
  const renderCombinedItem = ({ item }: { item: ListItem }) => {
1882
2135
  switch (item.type) {
1883
2136
  case 'conversation-header':
1884
- return <Text style={mergedStyles.sectionTitleStyle}>{t("CHATS") || "Chats"}</Text>;
2137
+ return <Text style={[TEXT_START, mergedStyles.sectionTitleStyle]}>{t("CHATS") || "Chats"}</Text>;
1885
2138
 
1886
2139
  case 'conversation':
1887
2140
  return (
@@ -1910,7 +2163,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1910
2163
  );
1911
2164
 
1912
2165
  case 'message-header':
1913
- return <Text style={mergedStyles.sectionTitleStyle}>{t("MESSAGES") || "Messages"}</Text>;
2166
+ return <Text style={[TEXT_START, mergedStyles.sectionTitleStyle]}>{t("MESSAGES") || "Messages"}</Text>;
1914
2167
 
1915
2168
  case 'message': {
1916
2169
  const message = item.data;
@@ -1931,7 +2184,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1931
2184
  timeStamp={sentAt * 1000}
1932
2185
  customDateString={currentDateStr}
1933
2186
  style={{
1934
- textStyle: mergedStyles.sectionTitleStyle
2187
+ textStyle: { ...TEXT_START, ...mergedStyles.sectionTitleStyle }
1935
2188
  }}
1936
2189
  />
1937
2190
  );
@@ -1989,8 +2242,8 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1989
2242
  mergedStyles.messageItemStyle?.contentStyle,
1990
2243
  (message.getType() === 'image' || message.getType() === 'video') && mergedStyles.messageItemStyle?.textContainerStyle
1991
2244
  ]}>
1992
- <Text style={mergedStyles.messageItemStyle?.titleStyle} numberOfLines={1}>
1993
- {getMessageChatTitle(message)}
2245
+ <Text style={[TEXT_START, mergedStyles.messageItemStyle?.titleStyle]} numberOfLines={1}>
2246
+ {stripBidiControls(getMessageChatTitle(message))}
1994
2247
  </Text>
1995
2248
  {renderMessageSubtitle(message)}
1996
2249
  </View>
@@ -2030,11 +2283,13 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
2030
2283
  };
2031
2284
 
2032
2285
  return (
2033
- <View style={[mergedStyles.containerStyle]}>
2286
+ <LayoutDirectionContext.Provider value={direction}>
2287
+ <View style={[mergedStyles.containerStyle, directionStyle(direction)]}>
2034
2288
  {renderHeader()}
2035
2289
  {renderFilters()}
2036
2290
  {renderResults()}
2037
2291
  </View>
2292
+ </LayoutDirectionContext.Provider>
2038
2293
  );
2039
2294
  };
2040
2295
 
@@ -2049,7 +2304,7 @@ const styles = StyleSheet.create({
2049
2304
  statusBadge: {
2050
2305
  position: 'absolute',
2051
2306
  bottom: 0,
2052
- right: 0,
2307
+ end: 0,
2053
2308
  },
2054
2309
  centerFill: {
2055
2310
  flex: 1,