@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.
- package/README.md +2 -3
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatSoundModule.java +29 -44
- package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +12 -0
- package/ios/FileManager.m +26 -9
- package/package.json +11 -36
- package/src/CometChatConversations/CometChatConversations.tsx +287 -147
- package/src/CometChatConversations/Skeleton.tsx +116 -73
- package/src/CometChatConversations/style.ts +17 -22
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +439 -227
- package/src/CometChatGroupMembers/style.ts +2 -4
- package/src/CometChatGroups/CometChatGroups.tsx +239 -135
- package/src/CometChatGroups/GroupsStyle.ts +20 -17
- package/src/CometChatGroups/Skeleton.tsx +198 -288
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +208 -73
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +97 -43
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +4 -2
- package/src/CometChatMessageList/CometChatMessageList.tsx +200 -76
- package/src/CometChatMessageList/style.ts +4 -4
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +77 -11
- package/src/CometChatThreadHeader/style.ts +2 -2
- package/src/CometChatUsers/CometChatUsers.tsx +203 -51
- package/src/CometChatUsers/Skeleton.tsx +174 -159
- package/src/CometChatUsers/style.ts +21 -18
- package/src/calls/CallingConfiguration.ts +4 -3
- package/src/calls/CallingExtensionDecorator.tsx +5 -3
- package/src/calls/CometChatCallButtons/CometChatCallButtonConfiguration.ts +4 -2
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +10 -8
- package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +240 -97
- package/src/calls/CometChatCallLogs/Skeleton.tsx +175 -91
- package/src/calls/CometChatCallLogs/index.ts +1 -0
- package/src/calls/CometChatCallLogs/style.ts +85 -43
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +42 -29
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +36 -10
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +39 -12
- package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +5 -4
- package/src/extensions/Polls/PollsDecorator.tsx +30 -9
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +34 -16
- package/src/index.ts +3 -1
- package/src/shared/base/Types.ts +31 -1
- package/src/shared/framework/DataSource.ts +64 -20
- package/src/shared/framework/DataSourceDecorator.tsx +46 -37
- package/src/shared/framework/MessageDataSource.tsx +518 -316
- package/src/shared/index.ts +3 -1
- package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/de/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/en/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/es/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/hu/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +3 -2
- package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +3 -2
- package/src/shared/utils/MessageUtils.tsx +41 -20
- package/src/shared/utils/conversationUtils.ts +2 -2
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +22 -1
- package/src/shared/views/CometChatBadge/CometChatBadge.tsx +20 -8
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +177 -123
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +76 -10
- package/src/shared/views/CometChatConfirmDialog/style.ts +2 -2
- package/src/shared/views/CometChatDate/CometChatDate.tsx +26 -18
- package/src/shared/views/CometChatDateSeperator/CometChatDateSeparator.tsx +22 -16
- package/src/shared/views/CometChatDeletedBubble/CometChatDeletedBubble.tsx +17 -5
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +65 -35
- package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +22 -11
- package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +47 -18
- package/src/shared/views/CometChatList/CometChatList.tsx +70 -46
- package/src/shared/views/CometChatList/Header.tsx +122 -37
- package/src/shared/views/CometChatList/styles.ts +1 -0
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +116 -30
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +52 -30
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +36 -22
- package/src/shared/views/CometChatQuickReactions/CometChatQuickReactions.tsx +41 -13
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +132 -17
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +30 -2
- package/src/shared/views/CometChatReceipt/CometChatReceipt.tsx +10 -6
- package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +20 -13
- package/src/shared/views/CometChatStatusIndicator/styles.ts +26 -13
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +25 -2
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +94 -14
- package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +52 -16
- package/src/shared/views/CometChatTooltipMenu/index.ts +2 -1
- package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +29 -9
- package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +20 -2
- package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +29 -14
- package/src/shared/views/index.ts +2 -0
- package/src/theme/default/index.ts +5 -5
- package/src/theme/type.ts +2 -2
- package/src/shared/views/CometChatPanel/CometChatPanel.tsx +0 -57
- package/src/shared/views/CometChatPanel/PanelStyle.tsx +0 -43
- package/src/shared/views/CometChatPanel/resources/CloseIcon.png +0 -0
- package/src/shared/views/CometChatPanel/resources/index.ts +0 -3
|
@@ -417,10 +417,8 @@ export const getGroupMemberStyleLight = (
|
|
|
417
417
|
marginBottom: 10,
|
|
418
418
|
},
|
|
419
419
|
},
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
cancellationIcon: undefined,
|
|
423
|
-
cancellationIconStyle: {},
|
|
420
|
+
confirmSelectionStyle: {},
|
|
421
|
+
selectionCancelStyle: {},
|
|
424
422
|
loadingIconTint: color.primary,
|
|
425
423
|
sectionHeaderTextStyle: {
|
|
426
424
|
marginHorizontal: spacing.spacing.s5,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
2
|
-
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
-
import {
|
|
2
|
+
import React, { useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
3
|
+
import { ColorValue, ImageSourcePropType, Text, View } from "react-native";
|
|
4
4
|
import { CometChatList, CometChatListActionsInterface, localize } from "../shared";
|
|
5
5
|
import { SelectionMode } from "../shared/base/Types";
|
|
6
6
|
import { CometChatUIEventHandler } from "../shared/events/CometChatUIEventHandler/CometChatUIEventHandler";
|
|
7
7
|
import { deepMerge } from "../shared/helper/helperFunctions";
|
|
8
8
|
import { DeepPartial } from "../shared/helper/types";
|
|
9
|
-
import { Icon } from "../shared/icons/Icon";
|
|
9
|
+
import { Icon, IconName } from "../shared/icons/Icon";
|
|
10
|
+
import { CometChatTooltipMenu, MenuItemInterface } from "../shared/views/CometChatTooltipMenu";
|
|
10
11
|
import { CometChatStatusIndicatorInterface } from "../shared/views/CometChatStatusIndicator";
|
|
11
12
|
import { ErrorEmptyView } from "../shared/views/ErrorEmptyView/ErrorEmptyView";
|
|
12
13
|
import { useTheme } from "../theme";
|
|
@@ -27,34 +28,28 @@ const uiEventListener = "uiEvents_" + new Date().getTime();
|
|
|
27
28
|
export interface CometChatGroupsInterface {
|
|
28
29
|
/**
|
|
29
30
|
* Custom title view for a group item.
|
|
30
|
-
* @param
|
|
31
|
+
* @param group - The group object.
|
|
31
32
|
* @returns JSX.Element to render as title.
|
|
32
33
|
*/
|
|
33
|
-
TitleView?: (
|
|
34
|
+
TitleView?: (group: CometChat.Group) => JSX.Element;
|
|
34
35
|
/**
|
|
35
36
|
* Custom subtitle view for a group item.
|
|
36
|
-
* @param item - The group object.
|
|
37
|
-
* @returns JSX.Element to render as subtitle.
|
|
38
37
|
*/
|
|
39
|
-
SubtitleView?: (
|
|
38
|
+
SubtitleView?: (group: CometChat.Group) => JSX.Element;
|
|
40
39
|
/**
|
|
41
|
-
* Custom
|
|
42
|
-
* @param item - The group object.
|
|
43
|
-
* @returns JSX.Element for the tail view.
|
|
40
|
+
* Custom trailing view for a group item.
|
|
44
41
|
*/
|
|
45
|
-
TrailingView?: (
|
|
42
|
+
TrailingView?: (group: CometChat.Group) => JSX.Element;
|
|
46
43
|
/**
|
|
47
|
-
* Custom list item view for
|
|
48
|
-
* @param item - The group object.
|
|
49
|
-
* @returns JSX.Element.
|
|
44
|
+
* Custom list item view for a group.
|
|
50
45
|
*/
|
|
51
|
-
ItemView?: (
|
|
46
|
+
ItemView?: (group: CometChat.Group) => JSX.Element;
|
|
52
47
|
/**
|
|
53
|
-
* Custom component for the AppBar options
|
|
48
|
+
* Custom component for the AppBar options.
|
|
54
49
|
*/
|
|
55
50
|
AppBarOptions?: () => JSX.Element;
|
|
56
51
|
/**
|
|
57
|
-
* Hide the submit (selection) button.
|
|
52
|
+
* Hide the "submit" (selection) button.
|
|
58
53
|
*/
|
|
59
54
|
hideSubmitButton?: boolean;
|
|
60
55
|
/**
|
|
@@ -68,18 +63,21 @@ export interface CometChatGroupsInterface {
|
|
|
68
63
|
/**
|
|
69
64
|
* Toggle back button visibility.
|
|
70
65
|
*/
|
|
71
|
-
|
|
66
|
+
showBackButton?: boolean;
|
|
72
67
|
/**
|
|
73
68
|
* Selection mode: "none" | "single" | "multiple".
|
|
74
69
|
*/
|
|
75
70
|
selectionMode?: SelectionMode;
|
|
76
71
|
/**
|
|
77
72
|
* Callback when group selection is completed.
|
|
78
|
-
* @param items - Array of selected groups.
|
|
79
73
|
*/
|
|
80
|
-
onSelection?: (
|
|
74
|
+
onSelection?: (list: Array<CometChat.Group>) => void;
|
|
81
75
|
/**
|
|
82
|
-
*
|
|
76
|
+
* Callback when submit selection button is pressed.
|
|
77
|
+
*/
|
|
78
|
+
onSubmit?: (list: Array<CometChat.Conversation>) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Hide the search box.
|
|
83
81
|
*/
|
|
84
82
|
hideSearch?: boolean;
|
|
85
83
|
/**
|
|
@@ -116,17 +114,14 @@ export interface CometChatGroupsInterface {
|
|
|
116
114
|
hideError?: boolean;
|
|
117
115
|
/**
|
|
118
116
|
* Callback when a group item is pressed.
|
|
119
|
-
* @param item - The group object.
|
|
120
117
|
*/
|
|
121
118
|
onItemPress?: (item: CometChat.Group) => void;
|
|
122
119
|
/**
|
|
123
120
|
* Callback when a group item is long pressed.
|
|
124
|
-
* @param item - The group object.
|
|
125
121
|
*/
|
|
126
122
|
onItemLongPress?: (item: CometChat.Group) => void;
|
|
127
123
|
/**
|
|
128
124
|
* Callback when an error occurs.
|
|
129
|
-
* @param e - The error object.
|
|
130
125
|
*/
|
|
131
126
|
onError?: (e: CometChat.CometChatException) => void;
|
|
132
127
|
/**
|
|
@@ -139,80 +134,124 @@ export interface CometChatGroupsInterface {
|
|
|
139
134
|
hideHeader?: boolean;
|
|
140
135
|
/**
|
|
141
136
|
* Custom leading view for a group item.
|
|
142
|
-
* @param item - The group object.
|
|
143
|
-
* @returns JSX.Element.
|
|
144
137
|
*/
|
|
145
|
-
LeadingView?: (
|
|
138
|
+
LeadingView?: (group: CometChat.Group) => JSX.Element;
|
|
139
|
+
/**
|
|
140
|
+
* Search Keyword.
|
|
141
|
+
*/
|
|
142
|
+
searchKeyword?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Callback triggered when the fetched list is empty.
|
|
145
|
+
*/
|
|
146
|
+
onEmpty?: () => void;
|
|
147
|
+
/**
|
|
148
|
+
* Callback triggered once the groups have loaded and are not empty.
|
|
149
|
+
*/
|
|
150
|
+
onLoad?: (list: CometChat.GroupMember[]) => void;
|
|
151
|
+
/**
|
|
152
|
+
* Hide the loading skeleton.
|
|
153
|
+
*/
|
|
154
|
+
hideLoadingState?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Hide the Group type (public/private/password).
|
|
157
|
+
*/
|
|
158
|
+
groupTypeVisibility?: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* A function to **append** more menu items on top of the default menu items for a group.
|
|
161
|
+
* @param group - The group object.
|
|
162
|
+
* @returns An array of menu items that will be appended to the default list
|
|
163
|
+
* (note: if you have no defaults, these become the entire set).
|
|
164
|
+
*/
|
|
165
|
+
addOptions?: (group: CometChat.Group) => MenuItemInterface[];
|
|
166
|
+
/**
|
|
167
|
+
* A function to **replace** the default menu items entirely for a group.
|
|
168
|
+
* @param group - The group object.
|
|
169
|
+
* @returns An array of menu items (with text, onPress, etc.).
|
|
170
|
+
*/
|
|
171
|
+
options?: (group: CometChat.Group) => MenuItemInterface[];
|
|
146
172
|
}
|
|
147
173
|
|
|
148
174
|
/**
|
|
149
|
-
* CometChatGroups renders a list of groups with
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @param props - Properties as defined in CometChatGroupsInterface.
|
|
153
|
-
* @param ref - Forwarded ref to allow external access to list methods.
|
|
154
|
-
* @returns JSX.Element rendering the groups list.
|
|
175
|
+
* CometChatGroups renders a list of groups with search, selection mode,
|
|
176
|
+
* error/empty/loading views, and a long-press tooltip menu (if you provide menu items).
|
|
155
177
|
*/
|
|
156
178
|
export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface, ref: any) => {
|
|
157
179
|
const {
|
|
158
|
-
AppBarOptions
|
|
159
|
-
hideSubmitButton,
|
|
180
|
+
AppBarOptions,
|
|
160
181
|
style = {},
|
|
161
182
|
searchPlaceholderText = localize("SEARCH"),
|
|
162
|
-
|
|
183
|
+
showBackButton = false,
|
|
163
184
|
selectionMode = "none",
|
|
164
185
|
onSelection = () => {},
|
|
186
|
+
onSubmit,
|
|
165
187
|
hideSearch = false,
|
|
166
|
-
EmptyView
|
|
167
|
-
ErrorView
|
|
168
|
-
LoadingView
|
|
169
|
-
groupsRequestBuilder
|
|
188
|
+
EmptyView,
|
|
189
|
+
ErrorView,
|
|
190
|
+
LoadingView,
|
|
191
|
+
groupsRequestBuilder,
|
|
170
192
|
searchRequestBuilder,
|
|
171
|
-
onError
|
|
172
|
-
onBack
|
|
173
|
-
onItemPress
|
|
174
|
-
onItemLongPress
|
|
175
|
-
SubtitleView
|
|
176
|
-
ItemView
|
|
193
|
+
onError,
|
|
194
|
+
onBack,
|
|
195
|
+
onItemPress,
|
|
196
|
+
onItemLongPress,
|
|
197
|
+
SubtitleView,
|
|
198
|
+
ItemView,
|
|
177
199
|
hideError = false,
|
|
200
|
+
searchKeyword = "",
|
|
201
|
+
hideLoadingState,
|
|
202
|
+
groupTypeVisibility = true,
|
|
203
|
+
addOptions,
|
|
204
|
+
options,
|
|
205
|
+
onEmpty,
|
|
206
|
+
onLoad,
|
|
178
207
|
hideHeader,
|
|
179
208
|
...newProps
|
|
180
209
|
} = props;
|
|
181
210
|
|
|
182
|
-
//
|
|
211
|
+
// Theme references.
|
|
183
212
|
const theme = useTheme();
|
|
184
213
|
const { mode } = useThemeInternal();
|
|
185
214
|
|
|
186
|
-
//
|
|
215
|
+
// Internal ref to CometChatList methods.
|
|
187
216
|
const groupListRef = useRef<CometChatListActionsInterface>(null);
|
|
188
217
|
|
|
189
|
-
//
|
|
190
|
-
const [selecting, setSelecting] = useState(selectionMode != "none" ? true : false);
|
|
191
|
-
const [selectedGroups, setSelectedGroups] = useState([]);
|
|
218
|
+
// States
|
|
192
219
|
const [hideSearchError, setHideSearchError] = useState(false);
|
|
220
|
+
const [selectedGroups, setSelectedGroups] = useState<CometChat.Group[]>([]);
|
|
221
|
+
|
|
222
|
+
// Tooltip state
|
|
223
|
+
const [tooltipVisible, setTooltipVisible] = useState(false);
|
|
224
|
+
const [selectedGroup, setSelectedGroup] = useState<CometChat.Group | null>(null);
|
|
225
|
+
const tooltipPosition = useRef({ pageX: 0, pageY: 0 });
|
|
193
226
|
|
|
194
|
-
// Merge theme styles with
|
|
227
|
+
// Merge theme styles with any overrides.
|
|
195
228
|
const mergedStyle = deepMerge(theme.groupStyles, style);
|
|
196
229
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
230
|
+
/**
|
|
231
|
+
* Expose imperative methods via ref.
|
|
232
|
+
*/
|
|
233
|
+
useImperativeHandle(ref, () => ({
|
|
234
|
+
addGroup,
|
|
235
|
+
updateGroup,
|
|
236
|
+
removeGroup,
|
|
202
237
|
getSelectedItems,
|
|
203
238
|
}));
|
|
204
239
|
|
|
205
240
|
/**
|
|
206
|
-
* Returns the
|
|
241
|
+
* Returns the currently selected group items.
|
|
207
242
|
*/
|
|
208
243
|
const getSelectedItems = () => {
|
|
209
244
|
return selectedGroups;
|
|
210
245
|
};
|
|
211
246
|
|
|
212
247
|
/**
|
|
213
|
-
* Renders
|
|
248
|
+
* Renders an empty state view when no groups are available.
|
|
249
|
+
* Also triggers `onEmpty` if provided.
|
|
214
250
|
*/
|
|
215
251
|
const EmptyStateView = useCallback(() => {
|
|
252
|
+
useEffect(() => {
|
|
253
|
+
onEmpty?.();
|
|
254
|
+
}, []);
|
|
216
255
|
return (
|
|
217
256
|
<View style={{ flex: 1 }}>
|
|
218
257
|
<ErrorEmptyView
|
|
@@ -243,28 +282,27 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
|
|
|
243
282
|
}, [mergedStyle, theme]);
|
|
244
283
|
|
|
245
284
|
/**
|
|
246
|
-
* Renders the error state view
|
|
247
|
-
* Also hides the search box
|
|
285
|
+
* Renders the error state view.
|
|
286
|
+
* Also hides the search box while this is active.
|
|
248
287
|
*/
|
|
249
288
|
const ErrorStateView = useCallback(() => {
|
|
250
289
|
useEffect(() => {
|
|
251
|
-
setHideSearchError(true); // Hide search
|
|
290
|
+
setHideSearchError(true); // Hide search while showing error
|
|
252
291
|
}, []);
|
|
253
292
|
return (
|
|
254
293
|
<View style={{ flex: 1 }}>
|
|
255
294
|
<ErrorEmptyView
|
|
256
295
|
title={localize("OOPS")}
|
|
257
296
|
subTitle={localize("SOMETHING_WENT_WRONG")}
|
|
297
|
+
tertiaryTitle={localize("WRONG_TEXT_TRY_AGAIN")}
|
|
258
298
|
Icon={
|
|
259
299
|
<Icon
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
height: 120,
|
|
263
|
-
width: 120,
|
|
264
|
-
}}
|
|
300
|
+
name='error-state'
|
|
301
|
+
size={theme.spacing.margin.m15 << 1}
|
|
265
302
|
containerStyle={{
|
|
266
303
|
marginBottom: theme.spacing.margin.m5,
|
|
267
304
|
}}
|
|
305
|
+
icon={mergedStyle.errorStateStyle.icon}
|
|
268
306
|
/>
|
|
269
307
|
}
|
|
270
308
|
containerStyle={{
|
|
@@ -281,54 +319,55 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
|
|
|
281
319
|
}, [mergedStyle, mode, theme]);
|
|
282
320
|
|
|
283
321
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
322
|
+
* Build final list of menu items for a given group:
|
|
323
|
+
* - If `options` is provided, it overrides everything.
|
|
324
|
+
* - Otherwise, if `addOptions` is provided, it returns those items only as no default as of now
|
|
287
325
|
*/
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
326
|
+
const buildMenuItems = (group: CometChat.Group): MenuItemInterface[] => {
|
|
327
|
+
if (options) {
|
|
328
|
+
return options(group);
|
|
329
|
+
}
|
|
330
|
+
if (addOptions) {
|
|
331
|
+
return addOptions(group);
|
|
332
|
+
}
|
|
333
|
+
// No default menu items, so return empty if no user-defined items.
|
|
334
|
+
return [];
|
|
291
335
|
};
|
|
292
336
|
|
|
293
337
|
/**
|
|
294
|
-
*
|
|
295
|
-
*
|
|
338
|
+
* Invoked when a group item is long pressed.
|
|
339
|
+
* If the developer passed `onItemLongPress`, call that and stop.
|
|
340
|
+
* Otherwise, show the tooltip if there are any menu items for that group.
|
|
296
341
|
*/
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
342
|
+
const handleItemLongPress = (group: CometChat.Group, e?: any) => {
|
|
343
|
+
// Call developer callback if provided
|
|
344
|
+
if (onItemLongPress) {
|
|
345
|
+
onItemLongPress(group);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
301
348
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
*/
|
|
306
|
-
const handleGroupMemberAddition = (...options: any) => {
|
|
307
|
-
const group = options[3];
|
|
308
|
-
groupListRef.current!.updateList(group);
|
|
309
|
-
};
|
|
349
|
+
// If user has no options / addOptions, no tooltip to show
|
|
350
|
+
const items = buildMenuItems(group);
|
|
351
|
+
if (items.length === 0) return;
|
|
310
352
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
353
|
+
// Save position for the tooltip
|
|
354
|
+
if (e && e.nativeEvent) {
|
|
355
|
+
tooltipPosition.current = {
|
|
356
|
+
pageX: e.nativeEvent.pageX,
|
|
357
|
+
pageY: e.nativeEvent.pageY,
|
|
358
|
+
};
|
|
359
|
+
} else {
|
|
360
|
+
// fallback if event coords are missing
|
|
361
|
+
tooltipPosition.current = { pageX: 200, pageY: 100 };
|
|
362
|
+
}
|
|
319
363
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
* @param group - The group object to update.
|
|
324
|
-
*/
|
|
325
|
-
const updateGroup = (group: CometChat.Group) => {
|
|
326
|
-
groupListRef.current!.updateList((grp: CometChat.Group) => grp.getGuid() === group.getGuid());
|
|
364
|
+
// Show tooltip
|
|
365
|
+
setSelectedGroup(group);
|
|
366
|
+
setTooltipVisible(true);
|
|
327
367
|
};
|
|
328
368
|
|
|
329
369
|
/**
|
|
330
|
-
*
|
|
331
|
-
* @param group - The group object to add.
|
|
370
|
+
* Methods below let you update/manipulate groups in the list.
|
|
332
371
|
*/
|
|
333
372
|
const addGroup = (group: CometChat.Group) => {
|
|
334
373
|
groupListRef.current!.addItemToList(
|
|
@@ -337,27 +376,41 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
|
|
|
337
376
|
);
|
|
338
377
|
};
|
|
339
378
|
|
|
379
|
+
const updateGroup = (group: CometChat.Group) => {
|
|
380
|
+
groupListRef.current!.updateList((grp: CometChat.Group) => grp.getGuid() === group.getGuid());
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
const removeGroup = (group: CometChat.Group) => {
|
|
384
|
+
groupListRef.current?.removeItemFromList(group.getGuid());
|
|
385
|
+
};
|
|
386
|
+
|
|
340
387
|
/**
|
|
341
|
-
*
|
|
342
|
-
* Also removes it from the selection list if present.
|
|
343
|
-
* @param group - The group object to remove.
|
|
388
|
+
* Group listener callbacks below, to keep the UI synced with group changes.
|
|
344
389
|
*/
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
selectedItems.splice(index, 1);
|
|
354
|
-
setSelectedGroups(selectedItems);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
390
|
+
const handleGroupMemberRemoval = (...options: any) => {
|
|
391
|
+
const group = options[3];
|
|
392
|
+
groupListRef.current!.updateList(group);
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
const handleGroupMemberBan = (...options: any) => {
|
|
396
|
+
const group = options[3];
|
|
397
|
+
groupListRef.current!.updateList(group);
|
|
357
398
|
};
|
|
358
399
|
|
|
359
|
-
|
|
360
|
-
|
|
400
|
+
const handleGroupMemberAddition = (...options: any) => {
|
|
401
|
+
const group = options[3];
|
|
402
|
+
groupListRef.current!.updateList(group);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
const handleGroupMemberScopeChange = (...options: any) => {
|
|
406
|
+
const group = options[4];
|
|
407
|
+
groupListRef.current!.updateList(group);
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Set up group listeners when the component mounts.
|
|
412
|
+
*/
|
|
413
|
+
useEffect(() => {
|
|
361
414
|
CometChat.addGroupListener(
|
|
362
415
|
groupListenerId,
|
|
363
416
|
new CometChat.GroupListener({
|
|
@@ -410,9 +463,10 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
|
|
|
410
463
|
},
|
|
411
464
|
})
|
|
412
465
|
);
|
|
466
|
+
|
|
413
467
|
CometChatUIEventHandler.addGroupListener(uiEventListener, {
|
|
414
468
|
ccGroupCreated: ({ group }: { group: CometChat.Group }) => {
|
|
415
|
-
groupListRef.current
|
|
469
|
+
groupListRef.current?.addItemToList(group, 0);
|
|
416
470
|
},
|
|
417
471
|
ccGroupDeleted: ({ group }: { group: CometChat.Group }) => {
|
|
418
472
|
groupListRef.current?.removeItemFromList(group.getGuid());
|
|
@@ -420,14 +474,14 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
|
|
|
420
474
|
ccGroupLeft: ({ leftGroup }: { leftGroup: CometChat.Group }) => {
|
|
421
475
|
leftGroup.setHasJoined(false);
|
|
422
476
|
leftGroup.setMembersCount(leftGroup.getMembersCount() - 1);
|
|
423
|
-
if (leftGroup.getType()
|
|
477
|
+
if (leftGroup.getType() === CometChat.GROUP_TYPE.PRIVATE) {
|
|
424
478
|
groupListRef.current?.removeItemFromList(leftGroup.getGuid());
|
|
425
479
|
} else {
|
|
426
480
|
groupListRef.current?.updateList(leftGroup);
|
|
427
481
|
}
|
|
428
482
|
},
|
|
429
483
|
ccGroupMemberKicked: ({ kickedFrom }: { kickedFrom: CometChat.Group }) => {
|
|
430
|
-
if (kickedFrom?.getType()
|
|
484
|
+
if (kickedFrom?.getType() === CometChat.GROUP_TYPE.PRIVATE) {
|
|
431
485
|
groupListRef.current?.removeItemFromList(kickedFrom.getGuid());
|
|
432
486
|
} else {
|
|
433
487
|
kickedFrom?.setHasJoined(false);
|
|
@@ -441,12 +495,12 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
|
|
|
441
495
|
groupListRef.current?.updateList(userAddedIn);
|
|
442
496
|
},
|
|
443
497
|
ccGroupMemberJoined: ({ joinedGroup }: { joinedGroup: CometChat.Group }) => {
|
|
444
|
-
joinedGroup.setMembersCount(joinedGroup.getMembersCount() + 1);
|
|
445
498
|
joinedGroup.setScope("participant");
|
|
446
499
|
joinedGroup.setHasJoined(true);
|
|
447
500
|
groupListRef.current?.updateList(joinedGroup);
|
|
448
501
|
},
|
|
449
502
|
});
|
|
503
|
+
|
|
450
504
|
return () => {
|
|
451
505
|
CometChat.removeGroupListener(groupListenerId);
|
|
452
506
|
CometChatUIEventHandler.removeGroupListener(uiEventListener);
|
|
@@ -457,8 +511,8 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
|
|
|
457
511
|
<View style={[Style.container, theme.groupStyles.containerStyle]}>
|
|
458
512
|
<CometChatList
|
|
459
513
|
hideHeader={hideHeader ?? hideHeader}
|
|
460
|
-
onItemLongPress={onItemLongPress}
|
|
461
514
|
onItemPress={onItemPress}
|
|
515
|
+
onItemLongPress={handleItemLongPress}
|
|
462
516
|
SubtitleView={
|
|
463
517
|
SubtitleView
|
|
464
518
|
? SubtitleView
|
|
@@ -475,34 +529,84 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
|
|
|
475
529
|
</Text>
|
|
476
530
|
)
|
|
477
531
|
}
|
|
478
|
-
statusIndicatorType={(group: CometChat.Group) =>
|
|
479
|
-
|
|
480
|
-
|
|
532
|
+
statusIndicatorType={(group: CometChat.Group) =>
|
|
533
|
+
!groupTypeVisibility
|
|
534
|
+
? null
|
|
535
|
+
: (group.getType() as CometChatStatusIndicatorInterface["type"])
|
|
536
|
+
}
|
|
481
537
|
title={localize("GROUPS")}
|
|
482
538
|
hideSearch={hideSearch ? hideSearch : hideSearchError}
|
|
483
539
|
listStyle={mergedStyle}
|
|
484
|
-
LoadingView={
|
|
540
|
+
LoadingView={
|
|
541
|
+
hideLoadingState
|
|
542
|
+
? () => <></> // will not render anything if true
|
|
543
|
+
: LoadingView
|
|
544
|
+
? LoadingView
|
|
545
|
+
: () => <Skeleton style={mergedStyle.skeletonStyle} />
|
|
546
|
+
}
|
|
485
547
|
EmptyView={EmptyView ? EmptyView : () => <EmptyStateView />}
|
|
486
548
|
ErrorView={ErrorView ? ErrorView : () => <ErrorStateView />}
|
|
487
549
|
searchPlaceholderText={searchPlaceholderText}
|
|
488
550
|
ref={groupListRef}
|
|
489
551
|
listItemKey='guid'
|
|
490
552
|
requestBuilder={
|
|
491
|
-
groupsRequestBuilder ||
|
|
492
|
-
new CometChat.GroupsRequestBuilder().setLimit(30).setSearchKeyword(
|
|
553
|
+
(groupsRequestBuilder && groupsRequestBuilder.setSearchKeyword(searchKeyword)) ||
|
|
554
|
+
new CometChat.GroupsRequestBuilder().setLimit(30).setSearchKeyword(searchKeyword)
|
|
493
555
|
}
|
|
494
556
|
searchRequestBuilder={searchRequestBuilder}
|
|
495
557
|
AppBarOptions={AppBarOptions}
|
|
496
|
-
hideBackButton={
|
|
558
|
+
hideBackButton={!showBackButton}
|
|
497
559
|
selectionMode={selectionMode}
|
|
498
560
|
onSelection={onSelection}
|
|
499
|
-
|
|
561
|
+
onSubmit={onSubmit}
|
|
500
562
|
ItemView={ItemView}
|
|
501
563
|
onError={onError}
|
|
502
564
|
hideError={hideError}
|
|
565
|
+
onListFetched={(fetchedList: CometChat.GroupMember[]) => {
|
|
566
|
+
if (fetchedList.length === 0) {
|
|
567
|
+
onEmpty?.();
|
|
568
|
+
} else {
|
|
569
|
+
onLoad?.(fetchedList);
|
|
570
|
+
}
|
|
571
|
+
}}
|
|
503
572
|
onBack={onBack}
|
|
504
573
|
{...newProps}
|
|
505
574
|
/>
|
|
575
|
+
|
|
576
|
+
{/* Tooltip Menu: only shows if selectionMode is "none" and items exist */}
|
|
577
|
+
{selectedGroup && selectionMode === "none" && tooltipVisible && (
|
|
578
|
+
<View
|
|
579
|
+
style={{
|
|
580
|
+
position: "absolute",
|
|
581
|
+
top: tooltipPosition.current.pageY,
|
|
582
|
+
left: tooltipPosition.current.pageX,
|
|
583
|
+
zIndex: 9999,
|
|
584
|
+
}}
|
|
585
|
+
>
|
|
586
|
+
<CometChatTooltipMenu
|
|
587
|
+
visible={tooltipVisible}
|
|
588
|
+
onClose={() => setTooltipVisible(false)}
|
|
589
|
+
onDismiss={() => setTooltipVisible(false)}
|
|
590
|
+
event={{
|
|
591
|
+
nativeEvent: tooltipPosition.current,
|
|
592
|
+
}}
|
|
593
|
+
menuItems={buildMenuItems(selectedGroup).map((menuItem) => ({
|
|
594
|
+
text: menuItem.text,
|
|
595
|
+
onPress: () => {
|
|
596
|
+
// Perform the user-defined action,
|
|
597
|
+
// then close the tooltip.
|
|
598
|
+
menuItem.onPress();
|
|
599
|
+
setTooltipVisible(false);
|
|
600
|
+
},
|
|
601
|
+
icon: menuItem?.icon,
|
|
602
|
+
textStyle: menuItem?.textStyle,
|
|
603
|
+
iconStyle: menuItem?.iconStyle,
|
|
604
|
+
iconContainerStyle: menuItem?.iconContainerStyle,
|
|
605
|
+
disabled: menuItem.disabled,
|
|
606
|
+
}))}
|
|
607
|
+
/>
|
|
608
|
+
</View>
|
|
609
|
+
)}
|
|
506
610
|
</View>
|
|
507
611
|
);
|
|
508
612
|
});
|