@cometchat/chat-uikit-react-native 5.3.5 → 5.3.7

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 (76) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +18 -1
  2. package/ios/FileManager.m +14 -3
  3. package/ios/SoundPlayer.m +24 -1
  4. package/package.json +2 -1
  5. package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +8 -3
  6. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +14 -11
  7. package/src/CometChatConversations/CometChatConversations.tsx +89 -51
  8. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +10 -11
  9. package/src/CometChatGroups/CometChatGroups.tsx +49 -42
  10. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +10 -7
  11. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +12 -10
  12. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +4 -3
  13. package/src/CometChatMessageList/CometChatMessageList.tsx +398 -144
  14. package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +478 -0
  15. package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +613 -0
  16. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +4 -1
  17. package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +811 -0
  18. package/src/CometChatNotificationFeed/Skeleton.tsx +43 -0
  19. package/src/CometChatNotificationFeed/index.ts +19 -0
  20. package/src/CometChatNotificationFeed/style.ts +333 -0
  21. package/src/CometChatNotificationFeed/utils.ts +124 -0
  22. package/src/CometChatSearch/CometChatSearch.tsx +8 -6
  23. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +4 -3
  24. package/src/CometChatUsers/CometChatUsers.tsx +56 -43
  25. package/src/calls/CallingExtensionDecorator.tsx +1 -1
  26. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +3 -2
  27. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +7 -6
  28. package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +2 -1
  29. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +2 -1
  30. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +4 -4
  31. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +5 -3
  32. package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +1 -1
  33. package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +5 -5
  34. package/src/extensions/Polls/PollsBubble.tsx +1 -1
  35. package/src/extensions/Polls/PollsDecorator.tsx +1 -1
  36. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -2
  37. package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +9 -5
  38. package/src/index.ts +7 -0
  39. package/src/shared/CometChatUiKit/CometChatUIKit.ts +48 -20
  40. package/src/shared/events/ListenerInitializer.ts +2 -1
  41. package/src/shared/framework/MessageDataSource.tsx +19 -15
  42. package/src/shared/helper/helperFunctions.ts +5 -4
  43. package/src/shared/icons/components/notification-empty.tsx +27 -0
  44. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +8 -1
  45. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +8 -1
  46. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +8 -1
  47. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +8 -1
  48. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +8 -1
  49. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +8 -1
  50. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +8 -1
  51. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +8 -1
  52. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +8 -1
  53. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +8 -1
  54. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +8 -1
  55. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +8 -1
  56. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +8 -1
  57. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +8 -1
  58. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +8 -1
  59. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +8 -1
  60. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +8 -1
  61. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +8 -1
  62. package/src/shared/services/stream-message.service.ts +0 -1
  63. package/src/shared/utils/CommonUtils.ts +1 -1
  64. package/src/shared/utils/MessageUtils.tsx +15 -13
  65. package/src/shared/utils/conversationUtils.ts +2 -2
  66. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +2 -2
  67. package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +17 -5
  68. package/src/shared/views/CometChatList/CometChatList.tsx +11 -15
  69. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +3 -3
  70. package/src/shared/views/CometChatReactions/CometChatReactions.tsx +2 -1
  71. package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +15 -4
  72. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +3 -3
  73. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +15 -1
  74. package/src/theme/default/default.ts +6 -0
  75. package/src/theme/provider.tsx +12 -12
  76. package/src/theme/type.ts +2 -0
@@ -77,6 +77,7 @@ export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
77
77
  const [isLoaded, setIsLoaded] = useState(false);
78
78
  const [isVisible, setIsVisible] = useState(false);
79
79
  const [imageSource, setImageSource] = useState<ImageSourcePropType>();
80
+ const isUpgraded = useRef(false);
80
81
 
81
82
  // Ref to record touch press time for detecting quick taps
82
83
  const pressTime = useRef<number | null>(0);
@@ -110,17 +111,27 @@ export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
110
111
  };
111
112
 
112
113
  useEffect(() => {
113
- // Prefetch the thumbnail if available, else fallback to the full image
114
+ isUpgraded.current = false;
115
+ // Show thumbnail quickly as placeholder, then upgrade to full-resolution image
114
116
  if (thumbnailUrl && typeof thumbnailUrl === "object" && "uri" in thumbnailUrl) {
117
+ // Start with thumbnail for fast display
115
118
  CommonUtils.prefetchThumbnail(thumbnailUrl.uri!).then((success: any) => {
116
- if (success) {
119
+ if (success && !isUpgraded.current) {
117
120
  setImageSource(thumbnailUrl);
118
- } else {
119
- setImageSource(imageUrl); // Fallback to original imageUrl if prefetch fails
120
121
  }
121
122
  });
123
+
124
+ // Prefetch the full-resolution image and upgrade once ready
125
+ if (imageUrl && typeof imageUrl === "object" && "uri" in imageUrl && imageUrl.uri) {
126
+ CommonUtils.prefetchThumbnail(imageUrl.uri!).then((success: any) => {
127
+ if (success) {
128
+ isUpgraded.current = true;
129
+ setImageSource(imageUrl);
130
+ }
131
+ });
132
+ }
122
133
  } else {
123
- setImageSource(imageUrl); // No thumbnail available, fallback to imageUrl
134
+ setImageSource(imageUrl); // No thumbnail available, use full image directly
124
135
  }
125
136
  }, [thumbnailUrl, imageUrl]);
126
137
 
@@ -152,6 +163,7 @@ export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
152
163
  {/* Render the image. It is initially hidden until loaded. */}
153
164
  <Image
154
165
  resizeMode={imageResizeMode || "cover"}
166
+ resizeMethod="scale"
155
167
  source={imageSource}
156
168
  style={[styles.image, style]}
157
169
  onLoad={() => setIsLoaded(true)}
@@ -1,3 +1,4 @@
1
+ let __listenerIdCounter = 0;
1
2
  import React, { JSX, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
2
3
  import {
3
4
  ActivityIndicator,
@@ -160,7 +161,7 @@ let lastReject: Function;
160
161
 
161
162
  export const CometChatList = React.forwardRef<CometChatListActionsInterface, CometChatListProps>(
162
163
  (props, ref) => {
163
- const connectionListenerId = "connectionListener_" + new Date().getTime();
164
+ const connectionListenerId = "connectionListener_" + Date.now() + "_" + (++__listenerIdCounter);
164
165
  const theme = useTheme();
165
166
  const { t } = useCometChatTranslation();
166
167
  const [isLoadingMore, setIsLoadingMore] = useState(false);
@@ -344,6 +345,8 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
344
345
  .then((newlist: any[]) => {
345
346
  setDataLoadingStatus(NO_DATA_FOUND);
346
347
  setList(newlist);
348
+ setHasMoreData(true); // Reset pagination since we rebuilt the request
349
+ props.onListFetched?.(newlist);
347
350
  })
348
351
  .catch((error) => {
349
352
  if (error && error["message"] === "Promise cancelled") {
@@ -496,8 +499,10 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
496
499
  }
497
500
  setList(finalList);
498
501
  } else {
499
- // Append to existing list
500
- finalList = [...list, ...newlist];
502
+ // Append to existing list, deduplicating by listItemKey
503
+ const existingKeys = new Set(list.map((item: any) => item[listItemKey]));
504
+ const uniqueNewItems = newlist.filter((item: any) => !existingKeys.has(item[listItemKey]));
505
+ finalList = [...list, ...uniqueNewItems];
501
506
  setList(finalList);
502
507
 
503
508
  // When the backend returns nothing more, mark the end of data
@@ -643,8 +648,8 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
643
648
  TitleView={TitleView && TitleView(item.value)}
644
649
  title={
645
650
  item.value.uid &&
646
- item.value.uid === CometChatUIKit.loggedInUser!.getUid() &&
647
- item.value.name === CometChatUIKit.loggedInUser!.getName()
651
+ item.value.uid === CometChatUIKit.loggedInUser?.getUid() &&
652
+ item.value.name === CometChatUIKit.loggedInUser?.getName()
648
653
  ? t("YOU")
649
654
  : item.value.name
650
655
  }
@@ -669,11 +674,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
669
674
  onPress={() => {
670
675
  onListItemPress(item);
671
676
  }}
672
- // onLongPress={() => {
673
- // onListItemLongPress(item);
674
- // }}
675
677
  onLongPress={(id: any, e: any) => {
676
- // const listItem = getListItem(id);
677
678
  onListItemLongPress(item, e);
678
679
  }}
679
680
  />
@@ -813,12 +814,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
813
814
  return messageContainer;
814
815
  }, [list, selectedItems, theme, dataLoadingStatus, isLoadingMore, hasMoreData, shouldSelect]);
815
816
 
816
- /**
817
- * Handle the rendering based on loading status
818
- */
819
- // if (list.length === 0 && dataLoadingStatus.toLowerCase() === LOADING) {
820
- // if (LoadingView) return <LoadingView />;
821
- // } else {
817
+
822
818
  return (
823
819
  <View style={{ flex: 1 }}>
824
820
  <Header
@@ -269,7 +269,7 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
269
269
  );
270
270
 
271
271
  const removeReaction = (reactionObj: CometChat.Reaction) => {
272
- let reactedByMe = loggedInUser.current!.getUid() === reactionObj?.getReactedBy()?.getUid();
272
+ let reactedByMe = loggedInUser.current?.getUid() === reactionObj?.getReactedBy()?.getUid();
273
273
  if (onPress) {
274
274
  onPress(reactionObj, newMessageObj.current);
275
275
  return;
@@ -332,7 +332,7 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
332
332
  };
333
333
 
334
334
  const subtitleView = useCallback((item: any) => {
335
- let reactedByMe = loggedInUser.current!.getUid() === item?.reactedBy?.uid;
335
+ let reactedByMe = loggedInUser.current?.getUid() === item?.reactedBy?.uid;
336
336
  return reactedByMe ? (
337
337
  <Text style={reactionListStyleFromTheme.subtitleStyle}>{t("TAP_TO_REMOVE")}</Text>
338
338
  ) : null;
@@ -340,7 +340,7 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
340
340
 
341
341
  const _render = ({ item, index }: { item: any; index: number }) => {
342
342
  function getName() {
343
- let reactedByMe = loggedInUser.current!.getUid() === item?.reactedBy?.uid;
343
+ let reactedByMe = loggedInUser.current?.getUid() === item?.reactedBy?.uid;
344
344
  return reactedByMe ? t("YOU") : item?.reactedBy?.name;
345
345
  }
346
346
 
@@ -1,3 +1,4 @@
1
+ let __listenerIdCounter = 0;
1
2
  import React, { JSX, useLayoutEffect } from "react";
2
3
  import { PixelRatio, Text, TouchableOpacity, View } from "react-native";
3
4
  import { CometChat } from "@cometchat/chat-sdk-react-native";
@@ -106,7 +107,7 @@ const CometChatReactions = (props: CometChatReactionsInterface) => {
106
107
  onLongPress={() => {
107
108
  onReactionLongPress && onReactionLongPress(AllObj, messageObject);
108
109
  }}
109
- key={new Date().getTime()}
110
+ key={"extra_reactions_view"}
110
111
  style={
111
112
  reactedByMe
112
113
  ? style?.extraReactionStyle?.activeContainerStyle
@@ -164,14 +164,25 @@ const CometChatStreamMessageBubble: React.FC<CometChatStreamMessageBubbleProps>
164
164
  }, []);
165
165
 
166
166
  useEffect(() => {
167
+ let disconnectTimeout: ReturnType<typeof setTimeout> | null = null;
167
168
  const sub = streamConnection$.subscribe(({ status, error }) => {
168
169
  setConnectionStatus(status);
169
- if (status === 'disconnected' || status === 'error') {
170
- setHasError(true);
171
- stopStreamingForRunId();
170
+ if (status === 'connected') {
171
+ if (disconnectTimeout) {
172
+ clearTimeout(disconnectTimeout);
173
+ disconnectTimeout = null;
174
+ }
175
+ setHasError(false);
176
+ } else if (status === 'disconnected' || status === 'error') {
177
+ disconnectTimeout = setTimeout(() => {
178
+ setHasError(true);
179
+ }, 5000);
172
180
  }
173
181
  });
174
- return () => sub.unsubscribe();
182
+ return () => {
183
+ sub.unsubscribe();
184
+ if (disconnectTimeout) clearTimeout(disconnectTimeout);
185
+ };
175
186
  }, []);
176
187
 
177
188
  // Create markdown styles based on theme
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from "react";
1
+ import React, { useCallback, useEffect, useState } from "react";
2
2
  import { ActivityIndicator, FlatList, ListRenderItemInfo, View, Text } from "react-native";
3
3
  import { CometChatListItem } from "../CometChatListItem";
4
4
  import { SuggestionItem } from "./SuggestionItem";
@@ -52,7 +52,7 @@ export const CometChatSuggestionList = (props: CometChatSuggestionListInterface)
52
52
  }, 800);
53
53
  }, []);
54
54
 
55
- const _render = ({ item, index }: ListRenderItemInfo<SuggestionItem>) => {
55
+ const _render = useCallback(({ item, index }: ListRenderItemInfo<SuggestionItem>) => {
56
56
  let shouldLoadAvatarName = item.hideLeadingIcon ? {} : { avatarName: item.name };
57
57
  const isAllAlias = item.underlyingText?.startsWith?.('<@all:');
58
58
  const TitleView = isAllAlias ? (
@@ -82,7 +82,7 @@ export const CometChatSuggestionList = (props: CometChatSuggestionListInterface)
82
82
  {...shouldLoadAvatarName}
83
83
  />
84
84
  );
85
- };
85
+ }, [listStyle, theme, t, onPress]);
86
86
 
87
87
  return (
88
88
  <View>
@@ -1,4 +1,4 @@
1
- import React, { useLayoutEffect, useState, useRef, useCallback, useMemo, JSX } from "react";
1
+ import React, { useLayoutEffect, useEffect, useState, useRef, useCallback, useMemo, JSX } from "react";
2
2
  import {
3
3
  StyleProp,
4
4
  Text,
@@ -8,6 +8,7 @@ import {
8
8
  TouchableOpacity,
9
9
  LayoutChangeEvent,
10
10
  TextLayoutEvent,
11
+ Platform,
11
12
  } from "react-native";
12
13
  import {
13
14
  CometChatMentionsFormatter,
@@ -120,6 +121,19 @@ export const CometChatTextBubbleText = (
120
121
  }
121
122
  }, [text]);
122
123
 
124
+ // Android fallback: onTextLayout doesn't fire reliably for short texts.
125
+ // If measurement hasn't completed after 100ms, force it to resolve.
126
+ useEffect(() => {
127
+ if (Platform.OS === 'android' && !measurementComplete && containerWidth != null) {
128
+ const timeout = setTimeout(() => {
129
+ if (!measurementComplete) {
130
+ setMeasurementComplete(true);
131
+ }
132
+ }, 100);
133
+ return () => clearTimeout(timeout);
134
+ }
135
+ }, [text, containerWidth, measurementComplete]);
136
+
123
137
  // Handler to capture container width - use functional update to avoid dependency
124
138
  const onContainerLayout = useCallback((e: LayoutChangeEvent) => {
125
139
  const w = Math.round(e.nativeEvent.layout.width);
@@ -6,6 +6,10 @@ import {
6
6
  getConversationStyleDark,
7
7
  getConversationStyleLight,
8
8
  } from "../../CometChatConversations/style";
9
+ import {
10
+ getNotificationFeedStyleDark,
11
+ getNotificationFeedStyleLight,
12
+ } from "../../CometChatNotificationFeed/style";
9
13
  import {
10
14
  getGroupMemberStyleDark,
11
15
  getGroupMemberStyleLight,
@@ -130,6 +134,7 @@ export const lightThemeMaker = (
130
134
  dateStyles: getDateStyleLight(color, spacing, typography),
131
135
  dateSeparatorStyles: getDateSeparatorStyleLight(color, spacing, typography),
132
136
  conversationStyles: getConversationStyleLight(color, spacing, typography),
137
+ notificationFeedStyles: getNotificationFeedStyleLight(color, spacing, typography),
133
138
  confirmDialogStyles: getConfirmDialogStyleLight(color, spacing, typography),
134
139
  reportDialogStyles: getReportDialogStyleLight(color, spacing, typography),
135
140
  messageHeaderStyles: getMessageHeaderStyle(color, spacing, typography),
@@ -171,6 +176,7 @@ export const darkThemeMaker = (
171
176
  dateStyles: getDateStyleDark(color, spacing, typography),
172
177
  dateSeparatorStyles: getDateSeparatorStyleDark(color, spacing, typography),
173
178
  conversationStyles: getConversationStyleDark(color, spacing, typography),
179
+ notificationFeedStyles: getNotificationFeedStyleDark(color, spacing, typography),
174
180
  confirmDialogStyles: getConfirmDialogStyleDark(color, spacing, typography),
175
181
  reportDialogStyles: getReportDialogStyleDark(color, spacing, typography),
176
182
  messageHeaderStyles: getMessageHeaderStyle(color, spacing, typography),
@@ -42,10 +42,9 @@ export const CometChatThemeProvider = ({
42
42
  theme = {} as any,
43
43
  }: PropsWithChildren<CometChatThemeProviderProps>) => {
44
44
  const rawScheme = useColorScheme();
45
- // For iOS, debounce the scheme value (300ms delay in this example).
46
- // For Android, use the raw value.
47
- const scheme =
48
- Platform.OS === "ios" ? useDebounce(rawScheme, 300) : rawScheme;
45
+ // Always call the hook unconditionally (Rules of Hooks), use result conditionally
46
+ const debouncedScheme = useDebounce(rawScheme, 300);
47
+ const scheme = Platform.OS === "ios" ? debouncedScheme : rawScheme;
49
48
 
50
49
  const parentProviderTheme = useThemeInternal();
51
50
  const {
@@ -113,15 +112,15 @@ export const CometChatThemeProvider = ({
113
112
  return parentProviderTheme.dark;
114
113
  }, [dark, parentProviderTheme.dark]);
115
114
 
116
- const themeValue = {
115
+ const resolvedMode = mode === "auto"
116
+ ? (typeof scheme === "string" ? scheme : "light")
117
+ : mode;
118
+
119
+ const themeValue = useMemo(() => ({
117
120
  light: lightTheme,
118
121
  dark: darkTheme,
119
- // Use the (conditionally) debounced scheme when determining the mode
120
- mode:
121
- mode === "auto"
122
- ? (typeof scheme === "string" ? scheme : "light")
123
- : mode,
124
- };
122
+ mode: resolvedMode,
123
+ }), [lightTheme, darkTheme, resolvedMode]);
125
124
 
126
125
  return (
127
126
  <ThemeContext.Provider value={themeValue}>
@@ -138,8 +137,9 @@ export const CometChatCompThemeProvider = ({
138
137
  children,
139
138
  theme = {} as any,
140
139
  }: PropsWithChildren<CometChatCompThemeProviderProps>) => {
140
+ const stableTheme = useMemo(() => theme, [theme]);
141
141
  return (
142
- <CompThemeContext.Provider value={theme}>
142
+ <CompThemeContext.Provider value={stableTheme}>
143
143
  {children}
144
144
  </CompThemeContext.Provider>
145
145
  );
package/src/theme/type.ts CHANGED
@@ -24,6 +24,7 @@ import { DateSeparatorStyle } from "../shared/views/CometChatDateSeperator/style
24
24
  import { JSX } from "react";
25
25
  import { ChatHistoryStyle } from "../CometChatAIAssistantChatHistory/style";
26
26
  import { ReportDialogStyle } from "../shared/views/CometChatReportDialog/style";
27
+ import { NotificationFeedStyle } from "../CometChatNotificationFeed/style";
27
28
 
28
29
  export type BubbleStyles = {
29
30
  containerStyle: ViewStyle;
@@ -468,6 +469,7 @@ export interface CometChatTheme {
468
469
  badgeStyle: BadgeStyle;
469
470
  callLogsStyles: CallLogsStyle;
470
471
  conversationStyles: ConversationStyle;
472
+ notificationFeedStyles: NotificationFeedStyle;
471
473
  confirmDialogStyles: ConfirmDialogStyle;
472
474
  reportDialogStyles: ReportDialogStyle;
473
475
  quickReactionStyle: {