@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.
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatKeyboardModule.kt +101 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
- package/android/src/main/java/com/reactnativecometchatuikit/KeyboardDirectionWatcher.kt +64 -0
- package/android/src/main/java/com/reactnativecometchatuikit/KeyboardLanguageDirection.kt +44 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +287 -49
- package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
- package/ios/CCLocalFileGuard.h +19 -0
- package/ios/CCLocalFileGuard.m +34 -0
- package/ios/CometChatKeyboardModule.m +9 -0
- package/ios/CometChatKeyboardModule.swift +71 -0
- package/ios/FileManager.m +70 -6
- package/ios/KeyboardLanguageDirection.swift +24 -0
- package/ios/RichTextEditorView.swift +253 -51
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/VideoManager.m +1 -1
- package/package.json +18 -3
- package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +41 -57
- package/src/CometChatAIAssistantChatHistory/Skeleton.tsx +4 -1
- package/src/CometChatAIAssistantChatHistory/style.ts +5 -2
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +145 -63
- package/src/CometChatCompactMessageComposer/styles.ts +7 -7
- package/src/CometChatConversations/CometChatConversations.tsx +276 -147
- package/src/CometChatConversations/Skeleton.tsx +4 -1
- package/src/CometChatConversations/style.ts +1 -1
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +39 -18
- package/src/CometChatGroupMembers/Skeleton.tsx +4 -1
- package/src/CometChatGroupMembers/style.ts +6 -4
- package/src/CometChatGroups/CometChatGroups.tsx +74 -58
- package/src/CometChatGroups/GroupsStyle.ts +1 -1
- package/src/CometChatGroups/Skeleton.tsx +4 -1
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +190 -96
- package/src/CometChatMessageComposer/styles.tsx +1 -1
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +28 -15
- package/src/CometChatMessageHeader/listners.ts +76 -56
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +8 -1
- package/src/CometChatMessageInformation/Skeleton.tsx +4 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +1465 -313
- package/src/CometChatMessageList/SwipeToReplyView.tsx +61 -0
- package/src/CometChatMessageList/style.ts +32 -32
- package/src/CometChatMessageList/swipeToReply.ts +25 -0
- package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +81 -10
- package/src/CometChatNotificationFeed/style.ts +1 -1
- package/src/CometChatNotificationFeed/utils.ts +17 -18
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +82 -3
- package/src/CometChatPinnedMessages/style.ts +5 -5
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +2 -0
- package/src/CometChatRichTextEditor/index.tsx +3 -0
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +83 -15
- package/src/CometChatSavedMessages/style.ts +3 -3
- package/src/CometChatSearch/CometChatSearch.tsx +391 -136
- package/src/CometChatSearch/Skeleton.tsx +4 -1
- package/src/CometChatSearch/searchLabels.ts +26 -0
- package/src/CometChatSearch/style.ts +7 -7
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +34 -8
- package/src/CometChatThreadHeader/Header.tsx +2 -2
- package/src/CometChatUsers/CometChatUsers.tsx +10 -1
- package/src/CometChatUsers/Skeleton.tsx +4 -1
- package/src/CometChatUsers/style.ts +1 -1
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +27 -1
- package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +16 -4
- package/src/calls/CometChatCallLogs/Skeleton.tsx +4 -1
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +11 -3
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +10 -2
- package/src/extensions/CollaborativeBubble/style.ts +4 -4
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +1 -1
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +1 -1
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +11 -6
- package/src/extensions/LinkPreview/style.ts +6 -6
- package/src/extensions/Polls/Header.tsx +1 -1
- package/src/extensions/Polls/Polls.tsx +25 -12
- package/src/extensions/Polls/PollsBubble.tsx +10 -6
- package/src/extensions/Polls/style.ts +4 -4
- package/src/extensions/Stickers/CometChatStickerKeyboard/CometChatStickerKeyboard.tsx +2 -2
- package/src/extensions/Stickers/CometChatStickerKeyboard/Skeleton.tsx +1 -1
- package/src/extensions/Stickers/CometChatStickerKeyboard/style.ts +1 -1
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +4 -2
- package/src/index.ts +11 -1
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +102 -2
- package/src/shared/CometChatUiKit/UIKitSettings.ts +28 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
- package/src/shared/events/index.ts +4 -0
- package/src/shared/events/offline.ts +28 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +18 -13
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +15 -7
- package/src/shared/formatters/CometChatTextFormatter.ts +11 -0
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +7 -4
- package/src/shared/framework/MessageDataSource.tsx +51 -108
- package/src/shared/helper/LocalizedDateHelper.ts +64 -4
- package/src/shared/helper/helperFunctions.ts +71 -4
- package/src/shared/helper/keyboardDirection.ts +54 -0
- package/src/shared/helper/layoutDirection.ts +205 -0
- package/src/shared/helper/pluralRules.ts +67 -0
- package/src/shared/helper/textDirection.ts +118 -0
- package/src/shared/icons/Icon.tsx +37 -2
- package/src/shared/icons/components/format-list-numbered-rtl.tsx +15 -0
- package/src/shared/index.ts +2 -0
- package/src/shared/offline/OfflineHub.ts +651 -0
- package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
- package/src/shared/offline/OfflineViews.tsx +222 -0
- package/src/shared/offline/conversationPins.ts +137 -0
- package/src/shared/offline/conversations.ts +325 -0
- package/src/shared/offline/frameProbe.ts +24 -0
- package/src/shared/offline/gate.ts +94 -0
- package/src/shared/offline/groupActions.ts +81 -0
- package/src/shared/offline/identity.ts +162 -0
- package/src/shared/offline/index.ts +76 -0
- package/src/shared/offline/media.ts +247 -0
- package/src/shared/offline/notices.ts +84 -0
- package/src/shared/offline/reconcile.ts +296 -0
- package/src/shared/offline/searchOutcome.ts +62 -0
- package/src/shared/offline/send.ts +430 -0
- package/src/shared/offline/stateContract.ts +85 -0
- package/src/shared/offline/threadReplies.ts +125 -0
- package/src/shared/offline/twoPhase.ts +372 -0
- package/src/shared/offline/unsentActions.ts +168 -0
- package/src/shared/offline/useOfflineMediaUri.ts +87 -0
- package/src/shared/offline/useOfflineReconnect.ts +25 -0
- package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
- package/src/shared/offline/useOfflineUploadTray.ts +76 -0
- package/src/shared/offline/usePresenceHidden.ts +33 -0
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +2 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/ar/translation.json +720 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +75 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +75 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +82 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +90 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +74 -3
- package/src/shared/services/UploadQueueService.ts +106 -1
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +13 -12
- package/src/shared/utils/CometChatMessagePreview/style.ts +1 -1
- package/src/shared/utils/MessageReceiptUtils.ts +8 -0
- package/src/shared/utils/MessageUtils.tsx +14 -14
- package/src/shared/utils/PermissionUtil.ts +16 -5
- package/src/shared/utils/SavedMessagesHelper.ts +18 -1
- package/src/shared/utils/attachmentLimits.ts +3 -2
- package/src/shared/utils/catchUpCursor.ts +36 -0
- package/src/shared/utils/conversationUtils.ts +3 -5
- package/src/shared/utils/failedMessageRetry.ts +73 -0
- package/src/shared/utils/fileIconFontSize.ts +10 -0
- package/src/shared/utils/fileSizeLabel.ts +16 -0
- package/src/shared/utils/groupActionText.ts +75 -0
- package/src/shared/utils/messageIdentity.ts +38 -0
- package/src/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.tsx +12 -8
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +1 -1
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +5 -3
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +22 -17
- package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +45 -12
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +16 -10
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +20 -8
- package/src/shared/views/CometChatBadge/CometChatBadge.tsx +8 -4
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +6 -2
- package/src/shared/views/CometChatComposerErrorBanner.tsx +3 -1
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +8 -3
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +2 -2
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +5 -3
- package/src/shared/views/CometChatEmojiKeyboard/emojis.ts +8 -8
- package/src/shared/views/CometChatEmojiKeyboard/style.ts +2 -2
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +65 -15
- package/src/shared/views/CometChatImageViewerModal/ImageViewerModal.tsx +7 -3
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +56 -25
- package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +41 -21
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +7 -3
- package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +7 -3
- package/src/shared/views/CometChatList/CometChatList.tsx +478 -21
- package/src/shared/views/CometChatList/Header.tsx +5 -2
- package/src/shared/views/CometChatList/sectionLetter.ts +44 -0
- package/src/shared/views/CometChatList/styles.ts +7 -7
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +6 -4
- package/src/shared/views/CometChatMediaRecorder/CometChatAudioPlayer.tsx +16 -10
- package/src/shared/views/CometChatMediaRecorder/Timer.tsx +5 -1
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +43 -16
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +24 -4
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +19 -2
- package/src/shared/views/CometChatNewMessageIndicator/CometChatNewMessageIndicator.tsx +3 -2
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +59 -12
- package/src/shared/views/CometChatReactionList/ReactionListStyle.tsx +2 -2
- package/src/shared/views/CometChatReactionList/Skeleton.tsx +4 -1
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +6 -2
- package/src/shared/views/CometChatReportDialog/CometChatReportDialog.tsx +7 -3
- package/src/shared/views/CometChatReportDialog/style.ts +1 -1
- package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +1 -1
- package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
- package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +20 -13
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +3 -2
- package/src/shared/views/CometChatSuggestionList/Skeleton.tsx +1 -1
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +29 -3
- package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +20 -30
- package/src/shared/views/CometChatTooltipMenu/tooltipPosition.ts +43 -0
- package/src/shared/views/CometChatVideoBubble/style.ts +2 -2
- package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +4 -1
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +58 -24
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
- package/src/shared/views/SenderLabel.tsx +41 -0
- package/src/theme/default/default.ts +1 -1
- package/src/theme/type.ts +17 -0
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Language } from "../resources/CometChatLocalizeNew/type";
|
|
2
|
-
import { getCometChatTranslation } from "../resources/CometChatLocalizeNew/LocalizationManager";
|
|
2
|
+
import { getCometChatTranslation, getCurrentLanguage } from "../resources/CometChatLocalizeNew/LocalizationManager";
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import 'dayjs/locale/en'; // English
|
|
5
5
|
import 'dayjs/locale/hi'; // Hindi
|
|
@@ -19,6 +19,8 @@ import 'dayjs/locale/sv'; // Swedish
|
|
|
19
19
|
import 'dayjs/locale/lt'; // Lithuanian
|
|
20
20
|
import 'dayjs/locale/hu'; // Hungarian
|
|
21
21
|
import 'dayjs/locale/nl'; // Dutch
|
|
22
|
+
import 'dayjs/locale/ar'; // Arabic (ENG-41314)
|
|
23
|
+
import 'dayjs/locale/he'; // Hebrew (ENG-41314)
|
|
22
24
|
// Import other languages as needed
|
|
23
25
|
|
|
24
26
|
// Dayjs plugins
|
|
@@ -42,6 +44,7 @@ export class LocalizedDateHelper {
|
|
|
42
44
|
callLogs: "callLogs",
|
|
43
45
|
relativeMinutes: "relativeMinutes",
|
|
44
46
|
conversationDate: "conversationDate",
|
|
47
|
+
monthYear: "monthYear",
|
|
45
48
|
} as const;
|
|
46
49
|
|
|
47
50
|
/**
|
|
@@ -96,7 +99,8 @@ export class LocalizedDateHelper {
|
|
|
96
99
|
const twelveHourLocales = [
|
|
97
100
|
'en-US', 'en-GB', 'en',
|
|
98
101
|
'hi-IN', 'hi',
|
|
99
|
-
'ms-MY', 'ms'
|
|
102
|
+
'ms-MY', 'ms',
|
|
103
|
+
'ar'
|
|
100
104
|
];
|
|
101
105
|
|
|
102
106
|
const { localeCode, dayJsLocale } = this.getLocaleConfig(locale);
|
|
@@ -163,6 +167,10 @@ export class LocalizedDateHelper {
|
|
|
163
167
|
'sv': 'sv-SE',
|
|
164
168
|
'lt': 'lt-LT',
|
|
165
169
|
'hu': 'hu-HU',
|
|
170
|
+
// ENG-41314: bare 'ar' resolves to Western digits in current ICU and 'ar-SA' switches
|
|
171
|
+
// to the Hijri calendar; ar-EG is Gregorian with Arabic-Indic digits (٤:٥٦ م).
|
|
172
|
+
'ar': 'ar-EG',
|
|
173
|
+
'he': 'he-IL',
|
|
166
174
|
};
|
|
167
175
|
|
|
168
176
|
// Return the mapped region or construct a default one
|
|
@@ -213,6 +221,28 @@ export class LocalizedDateHelper {
|
|
|
213
221
|
}
|
|
214
222
|
}
|
|
215
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Month and year ("November 2026", "نوفمبر ٢٠٢٦"), in the locale's own order (ja "2026年11月").
|
|
226
|
+
* It is a section title, so the first letter is capitalised (Intl gives es "noviembre de 2026").
|
|
227
|
+
*/
|
|
228
|
+
private formatMonthYear(date: Date, locale: Language): string {
|
|
229
|
+
const { dateFormattingLocale, dayJsLocale } = this.getLocaleConfig(locale);
|
|
230
|
+
let label: string;
|
|
231
|
+
try {
|
|
232
|
+
label = new Intl.DateTimeFormat(dateFormattingLocale, { month: 'long', year: 'numeric' }).format(date);
|
|
233
|
+
} catch {
|
|
234
|
+
dayjs.locale(dayJsLocale);
|
|
235
|
+
label = dayjs(date).format('MMMM YYYY');
|
|
236
|
+
}
|
|
237
|
+
let first: string;
|
|
238
|
+
try {
|
|
239
|
+
first = label.charAt(0).toLocaleUpperCase(dateFormattingLocale);
|
|
240
|
+
} catch {
|
|
241
|
+
first = label.charAt(0).toUpperCase();
|
|
242
|
+
}
|
|
243
|
+
return first + label.slice(1);
|
|
244
|
+
}
|
|
245
|
+
|
|
216
246
|
/**
|
|
217
247
|
* Format date for date separators (more detailed than conversation list)
|
|
218
248
|
*/
|
|
@@ -285,7 +315,10 @@ export class LocalizedDateHelper {
|
|
|
285
315
|
* Public method to get formatted date according to pattern
|
|
286
316
|
*/
|
|
287
317
|
getFormattedDate(timestamp: number, pattern: string, locale: Language = "en"): string {
|
|
288
|
-
|
|
318
|
+
return localizeDigits(this.formatByPattern(new Date(timestamp), pattern, locale), locale);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private formatByPattern(date: Date, pattern: string, locale: Language): string {
|
|
289
322
|
|
|
290
323
|
switch (pattern) {
|
|
291
324
|
case LocalizedDateHelper.patterns.timeFormat:
|
|
@@ -301,6 +334,9 @@ export class LocalizedDateHelper {
|
|
|
301
334
|
case LocalizedDateHelper.patterns.conversationDate:
|
|
302
335
|
return this.formatConversationDate(date, locale);
|
|
303
336
|
|
|
337
|
+
case LocalizedDateHelper.patterns.monthYear:
|
|
338
|
+
return this.formatMonthYear(date, locale);
|
|
339
|
+
|
|
304
340
|
case LocalizedDateHelper.patterns.callBubble:
|
|
305
341
|
case LocalizedDateHelper.patterns.callLogs:
|
|
306
342
|
const { dayJsLocale } = this.getLocaleConfig(locale);
|
|
@@ -314,4 +350,28 @@ export class LocalizedDateHelper {
|
|
|
314
350
|
}
|
|
315
351
|
}
|
|
316
352
|
|
|
317
|
-
export const localizedDateHelperInstance = new LocalizedDateHelper();
|
|
353
|
+
export const localizedDateHelperInstance = new LocalizedDateHelper();
|
|
354
|
+
|
|
355
|
+
// ENG-41314 part 3: the locale's own digits (Arabic-Indic for ar, Persian for fa), read from
|
|
356
|
+
// Intl so no table is kept here; null for locales that write 0-9, which leaves them untouched.
|
|
357
|
+
const digitCache: Record<string, string[] | null> = {};
|
|
358
|
+
function nativeDigits(locale: string): string[] | null {
|
|
359
|
+
if (!(locale in digitCache)) {
|
|
360
|
+
let digits: string[] | null = null;
|
|
361
|
+
try {
|
|
362
|
+
const nf = new Intl.NumberFormat(locale, { useGrouping: false });
|
|
363
|
+
const d = Array.from({ length: 10 }, (_, i) => nf.format(i));
|
|
364
|
+
if (d[1] !== "1") digits = d;
|
|
365
|
+
} catch {
|
|
366
|
+
// No Intl data for this locale: keep 0-9.
|
|
367
|
+
}
|
|
368
|
+
digitCache[locale] = digits;
|
|
369
|
+
}
|
|
370
|
+
return digitCache[locale];
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** Rewrites 0-9 in a date, time or count into the kit language's digits. */
|
|
374
|
+
export function localizeDigits(text: string, language: Language = getCurrentLanguage()): string {
|
|
375
|
+
const digits = nativeDigits(LocalizedDateHelper.getFullLocaleForDateFormatting(language));
|
|
376
|
+
return digits ? text.replace(/[0-9]/g, (c) => digits[Number(c)]) : text;
|
|
377
|
+
}
|
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { DeepPartial } from "./types";
|
|
3
3
|
import { useCometChatTranslation } from "../resources/CometChatLocalizeNew";
|
|
4
|
-
import { localizedDateHelperInstance } from "./LocalizedDateHelper";
|
|
4
|
+
import { localizedDateHelperInstance, localizeDigits } from "./LocalizedDateHelper";
|
|
5
|
+
import { pluralCategory } from "./pluralRules";
|
|
5
6
|
import dayjs from "dayjs";
|
|
6
7
|
|
|
8
|
+
// ENG-41311: kit default styles use start/end so they mirror under RTL. Yoga gives start/end
|
|
9
|
+
// priority over left/right, so an override written as left/right would be ignored. Margin,
|
|
10
|
+
// padding and border keys are always written as start/end (same result in LTR and under
|
|
11
|
+
// forceRTL, which already swaps left/right). Bare left/right are also used by hitSlop and
|
|
12
|
+
// plain data, so they move only when the target already holds start/end.
|
|
13
|
+
const BARE_EDGE: Record<string, string> = { left: "start", right: "end" };
|
|
14
|
+
const LOGICAL_EDGE: Record<string, string> = {
|
|
15
|
+
marginLeft: "marginStart",
|
|
16
|
+
marginRight: "marginEnd",
|
|
17
|
+
paddingLeft: "paddingStart",
|
|
18
|
+
paddingRight: "paddingEnd",
|
|
19
|
+
borderLeftWidth: "borderStartWidth",
|
|
20
|
+
borderRightWidth: "borderEndWidth",
|
|
21
|
+
borderLeftColor: "borderStartColor",
|
|
22
|
+
borderRightColor: "borderEndColor",
|
|
23
|
+
borderTopLeftRadius: "borderTopStartRadius",
|
|
24
|
+
borderTopRightRadius: "borderTopEndRadius",
|
|
25
|
+
borderBottomLeftRadius: "borderBottomStartRadius",
|
|
26
|
+
borderBottomRightRadius: "borderBottomEndRadius",
|
|
27
|
+
};
|
|
28
|
+
|
|
7
29
|
export function deepMerge<
|
|
8
30
|
T extends Record<string, any>,
|
|
9
31
|
U extends DeepPartial<T> & Record<string, any>
|
|
@@ -30,7 +52,11 @@ export function deepMerge<
|
|
|
30
52
|
output[key] = merge({}, source[key]);
|
|
31
53
|
}
|
|
32
54
|
} else if (source[key] !== undefined) {
|
|
33
|
-
|
|
55
|
+
const bare = BARE_EDGE[key];
|
|
56
|
+
const twin = LOGICAL_EDGE[key] ?? (bare !== undefined && bare in output ? bare : undefined);
|
|
57
|
+
if (twin === undefined) output[key] = source[key];
|
|
58
|
+
// An explicit start/end in the same override wins over its left/right twin.
|
|
59
|
+
else if (source[twin] === undefined) output[twin] = source[key];
|
|
34
60
|
}
|
|
35
61
|
}
|
|
36
62
|
|
|
@@ -74,6 +100,38 @@ export function deepClone<T>(obj: T, seen = new WeakMap()): T {
|
|
|
74
100
|
return clone as T;
|
|
75
101
|
}
|
|
76
102
|
|
|
103
|
+
// ENG-57310: dayjs's ar locale writes one plural for every count ("%d ساعات"), so 17 hours read
|
|
104
|
+
// "17 ساعات". Arabic takes the dual for 2, the plural for 3-10 and the singular from 11. These
|
|
105
|
+
// forms go in a kit-only copy of the locale, so dayjs's own "ar" (a host app may use it) is untouched.
|
|
106
|
+
const KIT_ARABIC_LOCALE = "ar-x-cometchat";
|
|
107
|
+
const arabicCount = (dual: string, plural: string, singular: string) => (n: number) => {
|
|
108
|
+
const category = pluralCategory(n, "ar");
|
|
109
|
+
return category === "two" ? dual : `${n} ${category === "few" ? plural : singular}`;
|
|
110
|
+
};
|
|
111
|
+
function arabicRelativeTimeLocale(): string {
|
|
112
|
+
if (!dayjs.Ls[KIT_ARABIC_LOCALE]) {
|
|
113
|
+
const ar = dayjs.Ls.ar as any;
|
|
114
|
+
dayjs.locale(
|
|
115
|
+
{
|
|
116
|
+
...ar,
|
|
117
|
+
name: KIT_ARABIC_LOCALE,
|
|
118
|
+
// No digit hooks: with a host app's preParsePostFormat plugin, relativeTime would hand
|
|
119
|
+
// mm / hh the count as "٥" (NaN to pluralCategory). localizeDigits converts afterwards.
|
|
120
|
+
postformat: undefined,
|
|
121
|
+
preparse: undefined,
|
|
122
|
+
relativeTime: {
|
|
123
|
+
...ar.relativeTime,
|
|
124
|
+
mm: arabicCount("دقيقتين", "دقائق", "دقيقة"),
|
|
125
|
+
hh: arabicCount("ساعتين", "ساعات", "ساعة"),
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
undefined,
|
|
129
|
+
true
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return KIT_ARABIC_LOCALE;
|
|
133
|
+
}
|
|
134
|
+
|
|
77
135
|
export function getLastSeenTime(timestamp: number | null | undefined): string {
|
|
78
136
|
try {
|
|
79
137
|
// Hook must be called unconditionally (Rules of Hooks)
|
|
@@ -98,17 +156,26 @@ export function getLastSeenTime(timestamp: number | null | undefined): string {
|
|
|
98
156
|
const diffInMinutes = now.diff(lastSeenTime, "minute");
|
|
99
157
|
const diffInHours = now.diff(lastSeenTime, "hour");
|
|
100
158
|
const diffInDays = now.diff(lastSeenTime, "day");
|
|
159
|
+
// "X minutes ago" in the kit language's digits, with the Arabic plural forms (ENG-57310).
|
|
160
|
+
const fromNow = () =>
|
|
161
|
+
localizeDigits(
|
|
162
|
+
(language.split("-")[0].toLowerCase() === "ar"
|
|
163
|
+
? lastSeenTime.locale(arabicRelativeTimeLocale())
|
|
164
|
+
: lastSeenTime
|
|
165
|
+
).fromNow(),
|
|
166
|
+
language
|
|
167
|
+
);
|
|
101
168
|
|
|
102
169
|
// For very recent times (< 1 min) → "a few seconds ago"
|
|
103
170
|
if (diffInMinutes < 1) {
|
|
104
|
-
const relativeTimeString =
|
|
171
|
+
const relativeTimeString = fromNow();
|
|
105
172
|
// Day.js will give "a few seconds ago" localized
|
|
106
173
|
return `${t("LAST_SEEN")} ${relativeTimeString}`;
|
|
107
174
|
}
|
|
108
175
|
|
|
109
176
|
// For times less than 24 hours → relative ("X minutes ago", "X hours ago")
|
|
110
177
|
if (diffInHours < 24) {
|
|
111
|
-
const relativeTimeString =
|
|
178
|
+
const relativeTimeString = fromNow();
|
|
112
179
|
return `${t("LAST_SEEN")} ${relativeTimeString}`;
|
|
113
180
|
}
|
|
114
181
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { NativeEventEmitter, NativeModules } from "react-native";
|
|
3
|
+
|
|
4
|
+
type Direction = "ltr" | "rtl";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Native CometChatKeyboardModule (ios/CometChatKeyboardModule.swift, android CometChatKeyboardModule.kt):
|
|
8
|
+
* the direction of the current keyboard's language. `null` when the keyboard gives no language
|
|
9
|
+
* (emoji keyboard, dictation, a keyboard that reports none).
|
|
10
|
+
*/
|
|
11
|
+
interface NativeCometChatKeyboardModuleSpec {
|
|
12
|
+
getKeyboardDirection(): Promise<string | null>;
|
|
13
|
+
addListener(eventName: string): void;
|
|
14
|
+
removeListeners(count: number): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Sent with `{ direction: "ltr" | "rtl" | null }` when the user switches keyboards. */
|
|
18
|
+
export const KEYBOARD_DIRECTION_EVENT = "keyboardDirectionChange";
|
|
19
|
+
|
|
20
|
+
const asDirection = (value: unknown): Direction | undefined =>
|
|
21
|
+
value === "ltr" || value === "rtl" ? value : undefined;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ENG-57281: the direction of the keyboard's language, for putting an empty composer's caret on that
|
|
25
|
+
* side. JS cannot see the keyboard, so it asks the native module, and listens only while `active`
|
|
26
|
+
* (the input is focused and has no letter yet): on Android the module polls while someone listens.
|
|
27
|
+
* A keyboard with no language (emoji panel, dictation) keeps the last direction seen, so opening
|
|
28
|
+
* the emoji keyboard doesn't move the caret. `undefined` while inactive, before any language was
|
|
29
|
+
* reported, or when the module is missing (an older native build, Expo Go); callers then keep the
|
|
30
|
+
* kit's start edge.
|
|
31
|
+
*/
|
|
32
|
+
export function useKeyboardDirection(active: boolean): Direction | undefined {
|
|
33
|
+
const [direction, setDirection] = useState<Direction>();
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const native = NativeModules.CometChatKeyboardModule as NativeCometChatKeyboardModuleSpec | undefined;
|
|
36
|
+
if (!active || !native?.getKeyboardDirection) return;
|
|
37
|
+
let live = true;
|
|
38
|
+
// No language (null, or anything unexpected) keeps what we had.
|
|
39
|
+
const keep = (value: unknown) => {
|
|
40
|
+
const next = asDirection(value);
|
|
41
|
+
if (live && next) setDirection(next);
|
|
42
|
+
};
|
|
43
|
+
const subscription = new NativeEventEmitter(native as any).addListener(
|
|
44
|
+
KEYBOARD_DIRECTION_EVENT,
|
|
45
|
+
(event?: { direction?: unknown }) => keep(event?.direction)
|
|
46
|
+
);
|
|
47
|
+
native.getKeyboardDirection().then(keep).catch(() => {});
|
|
48
|
+
return () => {
|
|
49
|
+
live = false;
|
|
50
|
+
subscription.remove();
|
|
51
|
+
};
|
|
52
|
+
}, [active]);
|
|
53
|
+
return active ? direction : undefined;
|
|
54
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { createContext, isValidElement, useContext, useMemo, useRef, useState, type ComponentRef, type ReactNode } from "react";
|
|
2
|
+
import { I18nManager, Platform, type LayoutChangeEvent, type ScrollView } from "react-native";
|
|
3
|
+
import { messageDirection } from "./textDirection";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The kit's direction setting (ENG-41333, names locked by F2 / ENG-41244).
|
|
7
|
+
* Global: `'auto'` (default, follow the app) | `'ltr'` | `'rtl'`. A component prop takes only
|
|
8
|
+
* `'ltr'` | `'rtl'`; not set = inherit.
|
|
9
|
+
*/
|
|
10
|
+
export type CometChatLayoutDirection = "auto" | "ltr" | "rtl";
|
|
11
|
+
type Direction = "ltr" | "rtl";
|
|
12
|
+
|
|
13
|
+
const asDirection = (value?: string): Direction | undefined =>
|
|
14
|
+
value === "ltr" || value === "rtl" ? value : undefined;
|
|
15
|
+
|
|
16
|
+
let globalDirection: CometChatLayoutDirection = "auto";
|
|
17
|
+
|
|
18
|
+
/** Set by `CometChatUIKit.init({ layoutDirection })` and `CometChatUIKit.setLayoutDirection()`. */
|
|
19
|
+
export function setGlobalLayoutDirection(value?: CometChatLayoutDirection): void {
|
|
20
|
+
globalDirection = asDirection(value) ?? "auto";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getGlobalLayoutDirection(): CometChatLayoutDirection {
|
|
24
|
+
return globalDirection;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The nearest kit component's direction. `undefined` = nothing set above (global `'auto'`). */
|
|
28
|
+
export const LayoutDirectionContext = createContext<Direction | undefined>(undefined);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* §4.1 resolution after the media rule (players pin LTR themselves, see PLAYER_DIRECTION):
|
|
32
|
+
* own setting → nearest enclosing component → global `'ltr'`/`'rtl'`. `undefined` means leave
|
|
33
|
+
* `direction` unset so Yoga inherits the app's direction (global `'auto'`, today's behaviour).
|
|
34
|
+
*/
|
|
35
|
+
export function resolveLayoutDirection(
|
|
36
|
+
own: string | undefined,
|
|
37
|
+
enclosing: Direction | undefined,
|
|
38
|
+
global: CometChatLayoutDirection
|
|
39
|
+
): Direction | undefined {
|
|
40
|
+
return asDirection(own) ?? enclosing ?? asDirection(global);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* For a public component's root and for overlays (Modal content starts a new native root, but
|
|
45
|
+
* React context still reaches it). The global value is read once, when the component is created
|
|
46
|
+
* (F2 decision 3: the runtime setter applies to components created afterwards).
|
|
47
|
+
*/
|
|
48
|
+
export function useComponentLayoutDirection(own?: string): Direction | undefined {
|
|
49
|
+
const enclosing = useContext(LayoutDirectionContext);
|
|
50
|
+
const [global] = useState(getGlobalLayoutDirection);
|
|
51
|
+
return resolveLayoutDirection(own, enclosing, global);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Style for a component root or overlay content; nothing when the direction is inherited. */
|
|
55
|
+
export const directionStyle = (direction?: Direction) =>
|
|
56
|
+
direction ? { direction } : undefined;
|
|
57
|
+
|
|
58
|
+
const appOrGlobal = (): Direction =>
|
|
59
|
+
asDirection(globalDirection) ?? (I18nManager.isRTL ? "rtl" : "ltr");
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Public (F2 decision 5): the direction kit content around the caller lays out in, for an
|
|
63
|
+
* integrator's own views in slots. Read it instead of `I18nManager.isRTL`.
|
|
64
|
+
*/
|
|
65
|
+
export function useCometChatLayoutDirection(): Direction {
|
|
66
|
+
return useContext(LayoutDirectionContext) ?? appOrGlobal();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Internal (F2 decision 7): icon mirroring, tooltip placement, swipe-to-reply. */
|
|
70
|
+
export function useKitRTL(): boolean {
|
|
71
|
+
return useCometChatLayoutDirection() === "rtl";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* ENG-41382: UI text (names, subtitles, titles, labels) starts at the layout's start edge in any
|
|
76
|
+
* script. iOS natural alignment follows the string's first letter ("John" left in an RTL list);
|
|
77
|
+
* React Native resolves `textAlign: "left"` against the Yoga direction, i.e. the start edge.
|
|
78
|
+
* Android text already follows the layout. Not for message bodies: they align by their own
|
|
79
|
+
* language (messageDirection). Put it first so a caller's own textAlign still wins.
|
|
80
|
+
*/
|
|
81
|
+
export const TEXT_START = Platform.OS === "ios" ? ({ textAlign: "left" } as const) : undefined;
|
|
82
|
+
|
|
83
|
+
const INPUT_LEFT = { textAlign: "left" } as const;
|
|
84
|
+
const INPUT_RIGHT = { textAlign: "right" } as const;
|
|
85
|
+
/**
|
|
86
|
+
* ENG-41384: typed text and placeholder start at the kit's start edge. TextInput ignores Yoga
|
|
87
|
+
* `direction` on both platforms and treats textAlign as absolute (Android maps it straight to
|
|
88
|
+
* Gravity.LEFT/RIGHT; iOS TextInput carries no layout direction), so the side is spelled out.
|
|
89
|
+
* Put it first so a caller's own textAlign still wins.
|
|
90
|
+
*/
|
|
91
|
+
export function useInputTextAlign() {
|
|
92
|
+
return useKitRTL() ? INPUT_RIGHT : INPUT_LEFT;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const NATURAL: { textAlign?: "left" | "right" } = {};
|
|
96
|
+
|
|
97
|
+
/** The text a formatted node shows: its strings, in order (mention chips included). */
|
|
98
|
+
function textContent(node: ReactNode): string {
|
|
99
|
+
if (typeof node === "string" || typeof node === "number") return String(node);
|
|
100
|
+
if (Array.isArray(node)) return node.map(textContent).join("");
|
|
101
|
+
if (isValidElement<{ children?: ReactNode }>(node)) return textContent(node.props.children);
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* ENG-57281: whether the composer's text has a letter yet. Pass the raw input string where there is
|
|
107
|
+
* one: the standard composer's formatters turn ANY non-empty input into an element, digits and emoji
|
|
108
|
+
* too. For an element, its shown text is read instead.
|
|
109
|
+
*/
|
|
110
|
+
export function composerHasLetters(text: ReactNode): boolean {
|
|
111
|
+
return messageDirection(typeof text === "string" ? text : textContent(text)) !== null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* ENG-57281: the composer's typed text aligns by its own language, like a message bubble: English
|
|
116
|
+
* starts on the left in an RTL screen, Arabic on the right in an LTR one. A TextInput takes one
|
|
117
|
+
* textAlign for all its lines, so with letters the alignment is left unset (natural): each line then
|
|
118
|
+
* follows its own first strong letter on iOS and Android. With no letter yet, the caret goes on the
|
|
119
|
+
* side of the keyboard's language (`keyboard`, see useKeyboardDirection): an English keyboard starts
|
|
120
|
+
* at the left of an RTL screen. No keyboard language, the kit's start edge (ENG-41384). A TextInput
|
|
121
|
+
* draws its placeholder with the same textAlign, so while focused it moves with the caret.
|
|
122
|
+
* `hasLetters`: composerHasLetters() of the raw input, computed once by the caller.
|
|
123
|
+
*/
|
|
124
|
+
export function useComposerTextAlign(
|
|
125
|
+
hasLetters: boolean,
|
|
126
|
+
keyboard?: Direction
|
|
127
|
+
): { textAlign?: "left" | "right" } {
|
|
128
|
+
const start = useInputTextAlign();
|
|
129
|
+
if (hasLetters) return NATURAL;
|
|
130
|
+
return keyboard === "rtl" ? INPUT_RIGHT : keyboard === "ltr" ? INPUT_LEFT : start;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* ENG-41390: for drawings with fixed x positions (SVG loading skeletons). Flex layouts mirror by
|
|
135
|
+
* themselves; an SVG doesn't, so it is flipped as a whole in RTL.
|
|
136
|
+
*/
|
|
137
|
+
const MIRROR_X = { transform: [{ scaleX: -1 }] } as const;
|
|
138
|
+
export function useRtlMirror() {
|
|
139
|
+
return useKitRTL() ? MIRROR_X : undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* ENG-41316: audio and video players read left to right in every language — play at the left, the
|
|
144
|
+
* waveform or seek bar filling from the left (design: Audio Bubble, Media Recorder, RTL). The one
|
|
145
|
+
* place the kit pins a direction; everything else follows the layout.
|
|
146
|
+
*/
|
|
147
|
+
export const PLAYER_DIRECTION = { direction: "ltr" } as const;
|
|
148
|
+
/** Player times (elapsed/total) align under the player's left end; iOS text ignores `direction`. */
|
|
149
|
+
export const PLAYER_TIME_ALIGN = { textAlign: "left", writingDirection: "ltr" } as const;
|
|
150
|
+
/**
|
|
151
|
+
* ENG-41314: code reads left to right in every language (as on Android and Flutter). For a code
|
|
152
|
+
* block's Text, before any integrator style: `textAlign: "left"` resolves against the node's own
|
|
153
|
+
* direction (see ownLanguageTextStyle), and iOS text ignores `direction`, hence writingDirection.
|
|
154
|
+
*/
|
|
155
|
+
export const CODE_DIRECTION = { direction: "ltr", writingDirection: "ltr", textAlign: "left" } as const;
|
|
156
|
+
|
|
157
|
+
type ScrollViewRef = ComponentRef<typeof ScrollView>;
|
|
158
|
+
type ScrollStartProps = {
|
|
159
|
+
ref?: (view: ScrollViewRef | null) => void;
|
|
160
|
+
onLayout?: (e: LayoutChangeEvent) => void;
|
|
161
|
+
onContentSizeChange?: (width: number, height: number) => void;
|
|
162
|
+
onScrollBeginDrag?: (e: unknown) => void;
|
|
163
|
+
};
|
|
164
|
+
const NO_SCROLL_START: ScrollStartProps = {};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* ENG-41342: a horizontal ScrollView opens at its start edge in RTL on iOS. RN iOS mirrors an RTL
|
|
168
|
+
* ScrollView with scaleX(-1) on the UIScrollView and on its zoom view; when the native view is
|
|
169
|
+
* recycled (a remount, e.g. the Messages screen's composer key), prepareForRecycle sets zoomScale 1
|
|
170
|
+
* after resetting the offset, UIKit reads the mirrored zoom view as zoom -1 and moves the offset to
|
|
171
|
+
* the END, and reuse keeps it. So until the user drags, scroll back to the start whenever either
|
|
172
|
+
* width changes. RN takes an RTL scrollTo x as contentWidth - width - x natively, so the start is
|
|
173
|
+
* x = contentWidth - width. The state lives as long as one ScrollView: a new one (the toolbar
|
|
174
|
+
* remounted after the voice recorder) starts undragged and unmeasured. Spread the result on the
|
|
175
|
+
* ScrollView; LTR and Android get nothing.
|
|
176
|
+
*/
|
|
177
|
+
export function useIosRtlScrollStart(direction?: Direction): ScrollStartProps {
|
|
178
|
+
const rtl = (direction ?? (I18nManager.isRTL ? "rtl" : "ltr")) === "rtl";
|
|
179
|
+
const active = Platform.OS === "ios" && rtl;
|
|
180
|
+
const size = useRef({ view: null as ScrollViewRef | null, content: 0, viewport: 0, dragged: false });
|
|
181
|
+
return useMemo(() => {
|
|
182
|
+
if (!active) return NO_SCROLL_START;
|
|
183
|
+
const toStart = () => {
|
|
184
|
+
const { content, viewport, dragged } = size.current;
|
|
185
|
+
if (dragged || !viewport || content <= viewport) return;
|
|
186
|
+
size.current.view?.scrollTo({ x: content - viewport, animated: false });
|
|
187
|
+
};
|
|
188
|
+
return {
|
|
189
|
+
ref: (view) => {
|
|
190
|
+
if (view !== size.current.view) size.current = { view, content: 0, viewport: 0, dragged: false };
|
|
191
|
+
},
|
|
192
|
+
onLayout: (e) => {
|
|
193
|
+
size.current.viewport = e.nativeEvent.layout.width;
|
|
194
|
+
toStart();
|
|
195
|
+
},
|
|
196
|
+
onContentSizeChange: (width) => {
|
|
197
|
+
size.current.content = width;
|
|
198
|
+
toStart();
|
|
199
|
+
},
|
|
200
|
+
onScrollBeginDrag: () => {
|
|
201
|
+
size.current.dragged = true;
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}, [active]);
|
|
205
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Language } from "../resources/CometChatLocalizeNew/type";
|
|
2
|
+
import { getCurrentLanguage } from "../resources/CometChatLocalizeNew/LocalizationManager";
|
|
3
|
+
import { localizeDigits } from "./LocalizedDateHelper";
|
|
4
|
+
|
|
5
|
+
export type PluralCategory = "zero" | "one" | "two" | "few" | "many" | "other";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* CLDR cardinal plural category of a whole count below a million in the kit language.
|
|
9
|
+
* Hermes has no Intl.PluralRules, so the rules are written out for the shipped languages;
|
|
10
|
+
* any other language gets one / other.
|
|
11
|
+
*/
|
|
12
|
+
export function pluralCategory(count: number, language: Language): PluralCategory {
|
|
13
|
+
const n = Math.abs(Math.trunc(count));
|
|
14
|
+
const n10 = n % 10;
|
|
15
|
+
const n100 = n % 100;
|
|
16
|
+
switch (language.split("-")[0].toLowerCase()) {
|
|
17
|
+
case "ar":
|
|
18
|
+
if (n === 0) return "zero";
|
|
19
|
+
if (n === 1) return "one";
|
|
20
|
+
if (n === 2) return "two";
|
|
21
|
+
if (n100 >= 3 && n100 <= 10) return "few";
|
|
22
|
+
if (n100 >= 11) return "many";
|
|
23
|
+
return "other";
|
|
24
|
+
case "ru":
|
|
25
|
+
if (n10 === 1 && n100 !== 11) return "one";
|
|
26
|
+
if (n10 >= 2 && n10 <= 4 && (n100 < 12 || n100 > 14)) return "few";
|
|
27
|
+
return "many";
|
|
28
|
+
case "lt":
|
|
29
|
+
if (n100 >= 11 && n100 <= 19) return "other";
|
|
30
|
+
if (n10 === 1) return "one";
|
|
31
|
+
if (n10 >= 2) return "few";
|
|
32
|
+
return "other";
|
|
33
|
+
case "fr":
|
|
34
|
+
case "hi":
|
|
35
|
+
case "pt":
|
|
36
|
+
return n <= 1 ? "one" : "other";
|
|
37
|
+
case "ja":
|
|
38
|
+
case "ko":
|
|
39
|
+
case "ms":
|
|
40
|
+
case "zh":
|
|
41
|
+
return "other";
|
|
42
|
+
default:
|
|
43
|
+
return n === 1 ? "one" : "other";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* "{count} …" from the translation key `<key>_<CATEGORY>` (e.g. SEARCH_FILE_COUNT_FEW), with the
|
|
49
|
+
* count in that language's digits. Every bundle has `_ONE` and `_OTHER`; a language whose rule
|
|
50
|
+
* uses more categories (ar, ru, lt) also has those forms. Pass the language `t` translates into
|
|
51
|
+
* (useCometChatTranslation's `language`): CometChatI18nProvider swaps `t` during render but sets
|
|
52
|
+
* the global language in an effect, so the default can still be the previous language. A form the
|
|
53
|
+
* bundle lacks (t returns the key) falls back to `_OTHER`, never a raw key.
|
|
54
|
+
*/
|
|
55
|
+
export function pluralCountLabel(
|
|
56
|
+
t: (key: string) => string,
|
|
57
|
+
key: string,
|
|
58
|
+
count: number,
|
|
59
|
+
language: Language = getCurrentLanguage()
|
|
60
|
+
): string {
|
|
61
|
+
const formKey = `${key}_${pluralCategory(count, language).toUpperCase()}`;
|
|
62
|
+
const form = t(formKey);
|
|
63
|
+
return (form === formKey ? t(`${key}_OTHER`) : form).replace(
|
|
64
|
+
/\{count\}/g,
|
|
65
|
+
localizeDigits(String(count), language)
|
|
66
|
+
);
|
|
67
|
+
}
|