@cometchat/chat-uikit-react-native 5.0.0-beta.1 → 5.0.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 (98) hide show
  1. package/README.md +2 -3
  2. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  3. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  4. package/android/src/main/java/com/reactnativecometchatuikit/CometChatSoundModule.java +29 -44
  5. package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +12 -0
  6. package/ios/FileManager.m +26 -9
  7. package/package.json +11 -36
  8. package/src/CometChatConversations/CometChatConversations.tsx +287 -147
  9. package/src/CometChatConversations/Skeleton.tsx +116 -73
  10. package/src/CometChatConversations/style.ts +17 -22
  11. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +439 -227
  12. package/src/CometChatGroupMembers/style.ts +2 -4
  13. package/src/CometChatGroups/CometChatGroups.tsx +239 -135
  14. package/src/CometChatGroups/GroupsStyle.ts +20 -17
  15. package/src/CometChatGroups/Skeleton.tsx +198 -288
  16. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +208 -73
  17. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +97 -43
  18. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +4 -2
  19. package/src/CometChatMessageList/CometChatMessageList.tsx +200 -76
  20. package/src/CometChatMessageList/style.ts +4 -4
  21. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +77 -11
  22. package/src/CometChatThreadHeader/style.ts +2 -2
  23. package/src/CometChatUsers/CometChatUsers.tsx +203 -51
  24. package/src/CometChatUsers/Skeleton.tsx +174 -159
  25. package/src/CometChatUsers/style.ts +21 -18
  26. package/src/calls/CallingConfiguration.ts +4 -3
  27. package/src/calls/CallingExtensionDecorator.tsx +5 -3
  28. package/src/calls/CometChatCallButtons/CometChatCallButtonConfiguration.ts +4 -2
  29. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +10 -8
  30. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +240 -97
  31. package/src/calls/CometChatCallLogs/Skeleton.tsx +175 -91
  32. package/src/calls/CometChatCallLogs/index.ts +1 -0
  33. package/src/calls/CometChatCallLogs/style.ts +85 -43
  34. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +42 -29
  35. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +36 -10
  36. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +39 -12
  37. package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +5 -4
  38. package/src/extensions/Polls/PollsDecorator.tsx +30 -9
  39. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +34 -16
  40. package/src/index.ts +3 -1
  41. package/src/shared/base/Types.ts +31 -1
  42. package/src/shared/framework/DataSource.ts +64 -20
  43. package/src/shared/framework/DataSourceDecorator.tsx +46 -37
  44. package/src/shared/framework/MessageDataSource.tsx +518 -316
  45. package/src/shared/index.ts +3 -1
  46. package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +3 -2
  47. package/src/shared/resources/CometChatLocalize/resources/de/translation.json +3 -2
  48. package/src/shared/resources/CometChatLocalize/resources/en/translation.json +3 -2
  49. package/src/shared/resources/CometChatLocalize/resources/es/translation.json +3 -2
  50. package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +3 -2
  51. package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +3 -2
  52. package/src/shared/resources/CometChatLocalize/resources/hu/translation.json +3 -2
  53. package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +3 -2
  54. package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +3 -2
  55. package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +3 -2
  56. package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +3 -2
  57. package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +3 -2
  58. package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +3 -2
  59. package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +3 -2
  60. package/src/shared/utils/MessageUtils.tsx +41 -20
  61. package/src/shared/utils/conversationUtils.ts +2 -2
  62. package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +22 -1
  63. package/src/shared/views/CometChatBadge/CometChatBadge.tsx +20 -8
  64. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +177 -123
  65. package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +76 -10
  66. package/src/shared/views/CometChatConfirmDialog/style.ts +2 -2
  67. package/src/shared/views/CometChatDate/CometChatDate.tsx +26 -18
  68. package/src/shared/views/CometChatDateSeperator/CometChatDateSeparator.tsx +22 -16
  69. package/src/shared/views/CometChatDeletedBubble/CometChatDeletedBubble.tsx +17 -5
  70. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +65 -35
  71. package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +22 -11
  72. package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +47 -18
  73. package/src/shared/views/CometChatList/CometChatList.tsx +70 -46
  74. package/src/shared/views/CometChatList/Header.tsx +122 -37
  75. package/src/shared/views/CometChatList/styles.ts +1 -0
  76. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +116 -30
  77. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +52 -30
  78. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +36 -22
  79. package/src/shared/views/CometChatQuickReactions/CometChatQuickReactions.tsx +41 -13
  80. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +132 -17
  81. package/src/shared/views/CometChatReactions/CometChatReactions.tsx +30 -2
  82. package/src/shared/views/CometChatReceipt/CometChatReceipt.tsx +10 -6
  83. package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +20 -13
  84. package/src/shared/views/CometChatStatusIndicator/styles.ts +26 -13
  85. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +25 -2
  86. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +94 -14
  87. package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +52 -16
  88. package/src/shared/views/CometChatTooltipMenu/index.ts +2 -1
  89. package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +29 -9
  90. package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +20 -2
  91. package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +29 -14
  92. package/src/shared/views/index.ts +2 -0
  93. package/src/theme/default/index.ts +5 -5
  94. package/src/theme/type.ts +2 -2
  95. package/src/shared/views/CometChatPanel/CometChatPanel.tsx +0 -57
  96. package/src/shared/views/CometChatPanel/PanelStyle.tsx +0 -43
  97. package/src/shared/views/CometChatPanel/resources/CloseIcon.png +0 -0
  98. package/src/shared/views/CometChatPanel/resources/index.ts +0 -3
@@ -20,25 +20,48 @@ import { getFileTypeIcon } from "../../constants/UIKitConstants";
20
20
  const { FileManager } = NativeModules;
21
21
  const eventEmitter = new NativeEventEmitter(FileManager);
22
22
 
23
+ /**
24
+ * Props for the CometChatFileBubble component.
25
+ */
23
26
  export interface CometChatFileBubbleInterface {
24
27
  /**
25
- * url of file
28
+ * URL of the file to be displayed/downloaded.
26
29
  */
27
30
  fileUrl: string;
28
31
  /**
29
- * file title
32
+ * Title of the file.
30
33
  */
31
34
  title: string;
32
35
  /**
33
- * description for file
36
+ * Subtitle or description for the file.
34
37
  */
35
38
  subtitle?: string;
39
+ /**
40
+ * Custom style for the title text.
41
+ */
36
42
  titleStyle?: TextStyle;
43
+ /**
44
+ * Custom style for the subtitle text.
45
+ */
37
46
  subtitleStyle?: TextStyle;
47
+ /**
48
+ * Custom icon for download. Can be an image source or a JSX element.
49
+ */
38
50
  downloadIcon?: ImageSourcePropType | JSX.Element;
51
+ /**
52
+ * Custom style for the download icon.
53
+ */
39
54
  downloadIconStyle?: ImageStyle;
40
55
  }
41
56
 
57
+ /**
58
+ * CometChatFileBubble is a component that displays a file bubble with title,
59
+ * subtitle and an icon indicating the file type. It handles file download,
60
+ * existence check and opening of the file.
61
+ *
62
+ * Props for the component.
63
+ * The rendered file bubble.
64
+ */
42
65
  export const CometChatFileBubble = ({
43
66
  fileUrl,
44
67
  title,
@@ -53,25 +76,28 @@ export const CometChatFileBubble = ({
53
76
  const theme = useTheme();
54
77
  let listener: EmitterSubscription;
55
78
 
56
- /********Android Specific********/
79
+ // Android-specific download identifier
57
80
  const downloadIdRef = useRef(0);
58
- /********************************/
81
+ // Flag to indicate if file should be opened after downloading
59
82
  const openFileAfterDownloading = useRef(false);
60
83
 
61
84
  useEffect(() => {
62
85
  checkFileExists();
63
86
 
64
87
  if (Platform.OS == "android") {
65
- listener = eventEmitter.addListener("downloadComplete", (data: { downloadId: number }) => {
66
- if (data.downloadId && downloadIdRef.current && data.downloadId == downloadIdRef.current) {
67
- setProcessing(false);
68
- setFileExists(true);
69
- if (openFileAfterDownloading.current) {
70
- openFile();
71
- openFileAfterDownloading.current = false;
88
+ listener = eventEmitter.addListener(
89
+ "downloadComplete",
90
+ (data: { downloadId: number }) => {
91
+ if (data.downloadId && downloadIdRef.current && data.downloadId == downloadIdRef.current) {
92
+ setProcessing(false);
93
+ setFileExists(true);
94
+ if (openFileAfterDownloading.current) {
95
+ openFile();
96
+ openFileAfterDownloading.current = false;
97
+ }
72
98
  }
73
99
  }
74
- });
100
+ );
75
101
  }
76
102
  return () => {
77
103
  if (Platform.OS == "android") {
@@ -80,6 +106,11 @@ export const CometChatFileBubble = ({
80
106
  };
81
107
  }, [fileUrl]);
82
108
 
109
+ /**
110
+ * Checks if the file exists locally.
111
+ *
112
+ * If true, download and open the file if it doesn't exist.
113
+ */
83
114
  const checkFileExists = async (downloadAndOpenFile = false) => {
84
115
  if (!fileUrl) return;
85
116
 
@@ -102,6 +133,9 @@ export const CometChatFileBubble = ({
102
133
  });
103
134
  };
104
135
 
136
+ /**
137
+ * Initiates the file download if it is not already processed or exists.
138
+ */
105
139
  const downloadFile = () => {
106
140
  if (processing || fileExists) return; // Do not process if file already exists
107
141
 
@@ -125,9 +159,11 @@ export const CometChatFileBubble = ({
125
159
  });
126
160
  };
127
161
 
162
+ /**
163
+ * Opens the file using the FileManager.
164
+ */
128
165
  const openFile = () => {
129
166
  if (processing) return;
130
-
131
167
  if (!fileUrl) return;
132
168
 
133
169
  setProcessing(true);
@@ -136,12 +172,17 @@ export const CometChatFileBubble = ({
136
172
  });
137
173
  };
138
174
 
175
+ /**
176
+ * Extracts the file name from the file URL.
177
+ *
178
+ * The file name.
179
+ */
139
180
  const getFileName = () => {
140
181
  return fileUrl.substring(fileUrl.lastIndexOf("/") + 1).replace(" ", "_");
141
182
  };
142
183
 
184
+ // Touch handling for iOS
143
185
  const wrapperPressTime = useRef<number | null>(0);
144
- //toDoLater
145
186
  const viewProps = useMemo(() => {
146
187
  return Platform.OS === "ios"
147
188
  ? {
@@ -163,8 +204,9 @@ export const CometChatFileBubble = ({
163
204
  : {};
164
205
  }, []);
165
206
 
207
+ // Touch handling for Android
166
208
  const pressTimeOnAndroid = useRef(0);
167
- let viewPropsForAndroid = useMemo(() => {
209
+ const viewPropsForAndroid = useMemo(() => {
168
210
  return Platform.OS === "android"
169
211
  ? {
170
212
  onTouchStart: () => {
@@ -181,6 +223,11 @@ export const CometChatFileBubble = ({
181
223
  : {};
182
224
  }, []);
183
225
 
226
+ /**
227
+ * Handler to download the file when the download icon is pressed.
228
+ *
229
+ * @param {NativeSyntheticEvent<NativeTouchEvent>} e - The touch event.
230
+ */
184
231
  const shouldDownload = (e: NativeSyntheticEvent<NativeTouchEvent>) => {
185
232
  e.stopPropagation();
186
233
  setProcessing(true);
@@ -207,26 +254,9 @@ export const CometChatFileBubble = ({
207
254
  </Text>
208
255
  )}
209
256
  </View>
210
- {/* Show download button only if file does not exist */}
211
- {/* {!processing && !fileExists && (
212
- <View
213
- {...viewPropsForAndroid}
214
- onTouchEnd={shouldDownload}
215
- style={{ padding: 4, paddingBottom: 0 }}
216
- >
217
- <Icon
218
- name='download'
219
- height={downloadIconStyle?.height}
220
- width={downloadIconStyle?.width}
221
- icon={downloadIcon}
222
- imageStyle={downloadIconStyle}
223
- color={downloadIconStyle?.tintColor}
224
- />
225
- </View>
226
- )} */}
227
257
  {processing && !fileExists && (
228
- <ActivityIndicator color={downloadIconStyle?.tintColor}></ActivityIndicator>
258
+ <ActivityIndicator color={downloadIconStyle?.tintColor} />
229
259
  )}
230
260
  </View>
231
261
  );
232
- };
262
+ };
@@ -1,41 +1,52 @@
1
1
  import React from "react";
2
2
  import {
3
- EmitterSubscription,
4
3
  ImageSourcePropType,
5
4
  ImageStyle,
6
- NativeEventEmitter,
7
- NativeModules,
8
5
  } from "react-native";
9
6
  import { CometChatImageLoader } from "./CometChatImageLoader";
10
7
 
8
+ /**
9
+ * Props for the CometChatImageBubble component.
10
+ */
11
11
  export interface CometChatImageBubbleInterface {
12
12
  /**
13
- * image url pass as {uri: "dummyUrl"}
13
+ * Image URL to be displayed.
14
+ * Pass as an object with a `uri` property, e.g., `{ uri: "dummyUrl" }`.
14
15
  */
15
16
  imageUrl: ImageSourcePropType;
16
17
  /**
17
- *
18
+ * Thumbnail image URL.
18
19
  *
19
20
  * @type {ImageSourcePropType}
20
- * @description thumbnail image
21
21
  */
22
22
  thumbnailUrl?: ImageSourcePropType;
23
23
  /**
24
- * place holder image
24
+ * Placeholder image to display while the main image is loading.
25
25
  */
26
26
  placeHolderImage?: ImageSourcePropType;
27
27
  /**
28
- * custom logic on touch of image
28
+ * Callback function to execute when the image is pressed.
29
29
  */
30
30
  onPress?: Function;
31
+ /**
32
+ * Custom style for the image.
33
+ */
31
34
  style?: ImageStyle;
32
35
  /**
33
- * resizeMode of image
36
+ * Resize mode for the image.
37
+ *
34
38
  * @default "cover"
35
39
  */
36
40
  resizeMode?: "cover" | "contain" | "stretch" | "repeat" | "center";
37
41
  }
38
42
 
43
+ /**
44
+ * CometChatImageBubble is a component that displays an image with support for thumbnails,
45
+ * placeholders, and custom styling. It uses the CometChatImageLoader component internally.
46
+ *
47
+ * Props for the image bubble component.
48
+ * The rendered image bubble.
49
+ */
39
50
  export const CometChatImageBubble = (props: CometChatImageBubbleInterface) => {
40
51
  const { thumbnailUrl, imageUrl, placeHolderImage, style, resizeMode } = props;
41
52
 
@@ -56,7 +67,7 @@ export const CometChatImageBubble = (props: CometChatImageBubbleInterface) => {
56
67
  placeHolderImage={placeHolderImage}
57
68
  style={style}
58
69
  imageResizeMode={resizeMode || "cover"}
59
- ></CometChatImageLoader>
70
+ />
60
71
  </>
61
72
  );
62
- };
73
+ };
@@ -12,38 +12,58 @@ import {
12
12
  import { ImageViewerModal } from "../CometChatImageViewerModal";
13
13
  import { CommonUtils } from "../../utils/CommonUtils";
14
14
 
15
+ /**
16
+ * Props for the CometChatImageLoader component.
17
+ */
15
18
  export interface CometChatImageLoaderPropType {
16
19
  /**
17
- * image url pass as {uri: "dummyUrl"}
20
+ * Image URL passed as an object with a `uri` property.
21
+ * Example: `{ uri: "dummyUrl" }`
18
22
  */
19
23
  imageUrl: ImageSourcePropType;
20
24
  /**
21
- *
25
+ * Thumbnail image URL.
22
26
  *
23
27
  * @type {ImageSourcePropType}
24
- * @description thumbnail image
28
+ * @description Thumbnail image to display while the full image loads.
25
29
  */
26
30
  thumbnailUrl?: ImageSourcePropType;
27
31
  /**
28
- * place holder image
32
+ * Placeholder image to display while loading.
29
33
  */
30
34
  placeHolderImage?: ImageSourcePropType;
31
35
  /**
32
- * custom logic on touch of image
36
+ * Custom callback function to execute when the image is pressed.
33
37
  */
34
38
  onPress?: Function;
39
+ /**
40
+ * Custom style for the image.
41
+ */
35
42
  style?: ImageStyle;
36
43
  /**
37
- * resizeMode of image
44
+ * Resize mode for the image.
45
+ *
38
46
  * @default "cover"
39
47
  */
40
48
  imageResizeMode?: "cover" | "contain" | "stretch" | "repeat" | "center";
41
-
49
+ /**
50
+ * Size of the activity indicator.
51
+ */
42
52
  activityIndicatorSize: number;
43
-
53
+ /**
54
+ * Custom style for the view containing the activity indicator.
55
+ */
44
56
  activityIndicatorViewStyle: ViewStyle;
45
57
  }
46
58
 
59
+ /**
60
+ * CometChatImageLoader is a component that displays an image with an activity indicator
61
+ * until the image is loaded. It supports thumbnail prefetching and opens an image viewer
62
+ * modal on a quick tap.
63
+ *
64
+ * Props for the component.
65
+ * The rendered image loader component.
66
+ */
47
67
  export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
48
68
  const {
49
69
  thumbnailUrl,
@@ -58,12 +78,19 @@ export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
58
78
  const [isVisible, setIsVisible] = useState(false);
59
79
  const [imageSource, setImageSource] = useState<ImageSourcePropType>();
60
80
 
81
+ // Ref to record touch press time for detecting quick taps
61
82
  const pressTime = useRef<number | null>(0);
62
83
 
84
+ /**
85
+ * Handles the touch start event.
86
+ */
63
87
  const handleTouchStart = () => {
64
88
  pressTime.current = Date.now();
65
89
  };
66
90
 
91
+ /**
92
+ * Handles the touch end event and opens the image viewer if tap duration is short.
93
+ */
67
94
  const handleTouchEnd = () => {
68
95
  if (pressTime.current === null && Platform.OS === "ios") return;
69
96
  const endTime = Date.now();
@@ -73,14 +100,17 @@ export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
73
100
  }
74
101
  };
75
102
 
103
+ /**
104
+ * Handles the touch move event. On iOS, cancels the tap detection.
105
+ */
76
106
  const onTouchMove = () => {
77
107
  if (Platform.OS === "ios") {
78
108
  pressTime.current = null;
79
109
  }
80
110
  };
81
111
 
82
-
83
112
  useEffect(() => {
113
+ // Prefetch the thumbnail if available, else fallback to the full image
84
114
  if (thumbnailUrl && typeof thumbnailUrl === "object" && "uri" in thumbnailUrl) {
85
115
  CommonUtils.prefetchThumbnail(thumbnailUrl.uri!).then((success: any) => {
86
116
  if (success) {
@@ -117,15 +147,14 @@ export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
117
147
  width: style?.width,
118
148
  }}
119
149
  >
120
- {/* Image (initially hidden until loaded) */}
150
+ {/* Render the image. It is initially hidden until loaded. */}
121
151
  <Image
122
152
  resizeMode={imageResizeMode || "cover"}
123
153
  source={imageSource}
124
154
  style={[styles.image, style]}
125
155
  onLoad={() => setIsLoaded(true)}
126
156
  />
127
-
128
- {/* Activity Indicator (remains visible until image is loaded) */}
157
+ {/* Render the activity indicator until the image is loaded */}
129
158
  {!isLoaded && (
130
159
  <ActivityIndicator
131
160
  size={activityIndicatorSize || "large"}
@@ -137,18 +166,18 @@ export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
137
166
  );
138
167
  };
139
168
 
140
- // Default styles
169
+ // Default styles for the component
141
170
  const styles = StyleSheet.create({
142
171
  container: {
143
- position: "relative", // Use relative position for the container
172
+ position: "relative", // Use relative positioning for the container
144
173
  justifyContent: "center",
145
174
  alignItems: "center",
146
175
  },
147
176
  loader: {
148
- position: "absolute", // Keep the loader in the center of the View
149
- zIndex: 1, // Ensure it's above the image until the image loads
177
+ position: "absolute", // Keep the loader centered over the image
178
+ zIndex: 1, // Ensure it is rendered above the image until the image loads
150
179
  },
151
180
  image: {
152
- position: "absolute", // The image stays in place while loading
181
+ position: "absolute", // The image remains fixed in place while loading
153
182
  },
154
- });
183
+ });
@@ -6,7 +6,6 @@ import {
6
6
  GestureResponderEvent,
7
7
  ImageSourcePropType,
8
8
  ImageStyle,
9
- ListRenderItem,
10
9
  StyleProp,
11
10
  Text,
12
11
  TextStyle,
@@ -28,7 +27,6 @@ import {
28
27
  StatusIndicatorStyles,
29
28
  } from "../CometChatStatusIndicator";
30
29
  import Header from "./Header";
31
- import { ICONS } from "./resources";
32
30
  import styles from "./styles";
33
31
 
34
32
  export interface CometChatListActionsInterface {
@@ -47,10 +45,16 @@ export interface CometChatListStylesInterface {
47
45
  separatorColor?: string;
48
46
  loadingIconTint?: ColorValue;
49
47
  sectionHeaderTextStyle?: TextStyle;
50
- selectionIcon?: ImageSourcePropType | JSX.Element;
51
- selectionIconStyle: ImageStyle;
52
- cancellationIcon?: ImageSourcePropType | JSX.Element;
53
- cancellationIconStyle?: ImageStyle;
48
+ confirmSelectionStyle: {
49
+ icon?: ImageSourcePropType | JSX.Element;
50
+ iconStyle?: ImageStyle;
51
+ iconContainerStyle?: ImageStyle;
52
+ };
53
+ selectionCancelStyle: {
54
+ icon?: ImageSourcePropType | JSX.Element;
55
+ iconStyle?: ImageStyle;
56
+ iconContainerStyle?: ImageStyle;
57
+ };
54
58
  titleSeparatorStyle: ViewStyle;
55
59
  searchStyle?: {
56
60
  textStyle: TextStyle;
@@ -105,6 +109,7 @@ export interface CometChatListProps {
105
109
  hideBackButton?: boolean;
106
110
  selectionMode?: "none" | "single" | "multiple";
107
111
  onSelection?: (list: any) => void;
112
+ onSubmit?: (list: any) => void;
108
113
  hideSearch?: boolean;
109
114
  hideHeader?: boolean;
110
115
  title?: string;
@@ -123,8 +128,13 @@ export interface CometChatListProps {
123
128
  listItemKey: "uid" | "guid" | "conversationId";
124
129
  listStyle?: DeepPartial<CometChatListStylesInterface>;
125
130
  hideSubmitButton?: boolean;
126
- statusIndicatorType?: (item: any) => CometChatStatusIndicatorInterface["type"];
131
+ statusIndicatorType?: (item: any) => CometChatStatusIndicatorInterface["type"] | null;
127
132
  hideStickyHeader?: boolean;
133
+ /**
134
+ * Called once the list has been fetched or updated.
135
+ * Returns the final array of items currently in the list.
136
+ */
137
+ onListFetched?: (fetchedList: any[]) => void;
128
138
  }
129
139
 
130
140
  let lastCall: any;
@@ -143,6 +153,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
143
153
  const connectionListenerId = "connectionListener_" + new Date().getTime();
144
154
  const theme = useTheme();
145
155
  const [isLoadingMore, setIsLoadingMore] = useState(false);
156
+ const [hasMoreData, setHasMoreData] = useState(true);
146
157
 
147
158
  const {
148
159
  LeadingView,
@@ -156,6 +167,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
156
167
  hideBackButton,
157
168
  selectionMode = "none",
158
169
  onSelection = () => {},
170
+ onSubmit,
159
171
  hideSearch = false,
160
172
  title = "Title",
161
173
  EmptyView,
@@ -192,38 +204,33 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
192
204
  });
193
205
 
194
206
  const [searchInput, setSearchInput] = useState(
195
- requestBuilder && searchRequestBuilder
196
- ? searchRequestBuilder.searchKeyword
197
- ? searchRequestBuilder.searchKeyword
198
- : ""
199
- : requestBuilder
207
+ requestBuilder
200
208
  ? requestBuilder.searchKeyword
201
209
  ? requestBuilder.searchKeyword
202
210
  : ""
203
211
  : searchRequestBuilder
204
- ? searchRequestBuilder.searchKeyword
205
212
  ? searchRequestBuilder.searchKeyword
213
+ ? searchRequestBuilder.searchKeyword
214
+ : ""
206
215
  : ""
207
- : ""
208
216
  );
217
+
209
218
  const searchInputRef = useRef(
210
- requestBuilder && searchRequestBuilder
211
- ? searchRequestBuilder.searchKeyword
212
- ? searchRequestBuilder.searchKeyword
213
- : ""
214
- : requestBuilder
219
+ requestBuilder
215
220
  ? requestBuilder.searchKeyword
216
221
  ? requestBuilder.searchKeyword
217
222
  : ""
218
223
  : searchRequestBuilder
219
- ? searchRequestBuilder.searchKeyword
220
224
  ? searchRequestBuilder.searchKeyword
225
+ ? searchRequestBuilder.searchKeyword
226
+ : ""
221
227
  : ""
222
- : ""
223
228
  );
224
229
 
225
230
  const [selectedItems, setSelectedItems] = useState<{ [key: string]: any }>({});
226
- const shouldSelect = props.selectionMode === "single" || props.selectionMode === "multiple";
231
+ const [shouldSelect, setShouldSelect] = useState(
232
+ props.selectionMode === "single" || props.selectionMode === "multiple"
233
+ );
227
234
 
228
235
  const listHandlerRef = useRef<any>(null);
229
236
  const initialRunRef = useRef(true);
@@ -241,6 +248,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
241
248
  // Debounced search handler
242
249
  const searchHandler = (searchText: string) => {
243
250
  setSearchInput(searchText);
251
+ setHasMoreData(true);
244
252
  let _searchRequestBuilder = searchRequestBuilder || requestBuilder;
245
253
  if (searchRequestBuilder && searchText) {
246
254
  _searchRequestBuilder = searchRequestBuilder.setSearchKeyword(searchText).build();
@@ -400,23 +408,39 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
400
408
  */
401
409
  const handleList = (throughKeyword?: boolean) => {
402
410
  // Prevent multiple fetches
403
- if (isLoadingMore) return;
404
-
411
+ if (isLoadingMore || (!throughKeyword && !hasMoreData)) return;
405
412
  setIsLoadingMore(true);
406
413
 
407
414
  getList(listHandlerRef.current)
408
415
  .then((newlist: any[] = []) => {
409
- if ((throughKeyword || list.length === 0) && newlist.length === 0) {
410
- setDataLoadingStatus(NO_DATA_FOUND);
411
- } else {
412
- setDataLoadingStatus("");
413
- }
414
- if (throughKeyword === true) {
415
- setList(newlist);
416
+ let finalList: any[] = [];
417
+
418
+ if (throughKeyword || list.length === 0) {
419
+ // If we're resetting the list or there is no existing list
420
+ if (throughKeyword) setHasMoreData(true);
421
+ else if (newlist.length === 0) setHasMoreData(false);
422
+
423
+ finalList = newlist;
424
+ if (finalList.length === 0) {
425
+ setDataLoadingStatus(NO_DATA_FOUND);
426
+ } else {
427
+ setDataLoadingStatus("");
428
+ }
429
+ setList(finalList);
416
430
  } else {
417
- setList([...list, ...newlist]);
431
+ // Append to existing list
432
+ finalList = [...list, ...newlist];
433
+ setList(finalList);
434
+
435
+ // When the backend returns nothing more, mark the end of data
436
+ if (newlist.length === 0) setHasMoreData(false);
418
437
  }
419
- setIsLoadingMore(false); // Fetch complete
438
+
439
+ // If we *did* get results but less than a full “page”, also stop further loads
440
+ if (newlist.length === 0) setHasMoreData(false);
441
+
442
+ props.onListFetched?.(finalList);
443
+ setIsLoadingMore(false);
420
444
  })
421
445
  .catch((error) => {
422
446
  if (error && error["message"] === "Promise cancelled") {
@@ -425,18 +449,18 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
425
449
  setDataLoadingStatus(SOMETHING_WRONG);
426
450
  errorHandler(error);
427
451
  }
428
- setIsLoadingMore(false); // Fetch complete or errored
452
+ setIsLoadingMore(false);
429
453
  });
430
454
  };
431
455
 
432
- const renderFooter = () => {
433
- if (!isLoadingMore) return null;
456
+ const renderFooter = useCallback(() => {
457
+ if (!isLoadingMore || !hasMoreData) return null;
434
458
  return (
435
459
  <View style={styles.footerContainer}>
436
460
  <ActivityIndicator size='small' color={theme.color.primary} />
437
461
  </View>
438
462
  );
439
- };
463
+ }, [isLoadingMore, hasMoreData]);
440
464
 
441
465
  /**
442
466
  * Handle errors
@@ -489,7 +513,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
489
513
  * Handle Confirm action
490
514
  */
491
515
  const handleConfirmSelection = () => {
492
- onSelection(Object.values(selectedItems));
516
+ onSubmit && onSubmit(Object.values(selectedItems));
493
517
  // Optionally, you might want to clear the selection after confirmation
494
518
  setSelectedItems({});
495
519
  };
@@ -525,7 +549,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
525
549
  }
526
550
  return (
527
551
  <CometChatListItem
528
- statusIndicatorType={statusIndicatorType ? statusIndicatorType(item.value) : undefined}
552
+ statusIndicatorType={statusIndicatorType ? statusIndicatorType(item.value) : null}
529
553
  id={item.value[listItemKey]}
530
554
  avatarName={item.value.name}
531
555
  selected={!!selectedItems[item.value[listItemKey]]}
@@ -590,7 +614,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
590
614
  /**
591
615
  * Gets the list of users
592
616
  */
593
- const getList = (props: any): Promise<any[]> => {
617
+ const getList = (reqBuilder: any): Promise<any[]> => {
594
618
  const promise = new Promise<any[]>((resolve, reject) => {
595
619
  const cancel = () => {
596
620
  clearTimeout(lastCall);
@@ -601,7 +625,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
601
625
  }
602
626
 
603
627
  lastCall = setTimeout(() => {
604
- props
628
+ reqBuilder
605
629
  ?.fetchNext()
606
630
  .then((listItems: any) => {
607
631
  resolve(listItems);
@@ -663,7 +687,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
663
687
  <View style={styles.listContainerStyle}>
664
688
  <FlatList
665
689
  data={listWithHeaders}
666
- extraData={{ selectedItems, theme, list }}
690
+ extraData={{ selectedItems, theme, list, selectionMode }}
667
691
  renderItem={
668
692
  ItemView
669
693
  ? ({ item, index, separators }) => {
@@ -693,6 +717,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
693
717
  }}
694
718
  showsVerticalScrollIndicator={false}
695
719
  ListFooterComponent={renderFooter}
720
+ keyboardShouldPersistTaps='always'
696
721
  />
697
722
  </View>
698
723
  );
@@ -700,7 +725,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
700
725
  }
701
726
 
702
727
  return messageContainer;
703
- }, [list, selectedItems, theme, dataLoadingStatus]);
728
+ }, [list, selectedItems, theme, dataLoadingStatus, isLoadingMore, hasMoreData, shouldSelect]);
704
729
 
705
730
  /**
706
731
  * Handle the rendering based on loading status
@@ -732,9 +757,8 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
732
757
  searchHandler={searchHandler}
733
758
  searchInput={searchInput}
734
759
  onSubmitEditing={() => searchHandler(searchInput)}
735
- selectionIcon={listStyle?.selectionIcon}
736
- selectionIconStyle={listStyle?.selectionIconStyle}
737
- cancellationIconStyle={listStyle?.cancellationIconStyle}
760
+ selectionCancelStyle={listStyle?.selectionCancelStyle}
761
+ confirmSelectionStyle={listStyle?.confirmSelectionStyle}
738
762
  searchStyle={listStyle?.searchStyle}
739
763
  selectedCount={selectedCount}
740
764
  />