@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
|
@@ -14,31 +14,103 @@ import { useTheme } from "../../../theme";
|
|
|
14
14
|
import { Icon } from "../../icons/Icon";
|
|
15
15
|
import styles from "./styles";
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Props for the Header component.
|
|
19
|
+
*/
|
|
17
20
|
interface HeaderProps {
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Style for the separator view between the back button and title.
|
|
23
|
+
*/
|
|
24
|
+
titleSeparatorStyle?: ViewStyle;
|
|
25
|
+
/**
|
|
26
|
+
* Count of selected items (used in selection mode).
|
|
27
|
+
*/
|
|
19
28
|
selectedCount?: number;
|
|
29
|
+
/**
|
|
30
|
+
* If true, hides the back button.
|
|
31
|
+
*/
|
|
20
32
|
hideBackButton?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Callback function invoked when the back button is pressed.
|
|
35
|
+
*/
|
|
21
36
|
onBack?: () => void;
|
|
37
|
+
/**
|
|
38
|
+
* Custom component for additional AppBar options.
|
|
39
|
+
*/
|
|
22
40
|
AppBarOptions?: React.FC;
|
|
41
|
+
/**
|
|
42
|
+
* If true, indicates that the list is in selection mode.
|
|
43
|
+
*/
|
|
23
44
|
shouldSelect?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* If true, hides the submit (confirm) button in selection mode.
|
|
47
|
+
*/
|
|
24
48
|
hideSubmitButton?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Callback function invoked when the cancel button is pressed in selection mode.
|
|
51
|
+
*/
|
|
25
52
|
onCancel?: () => void;
|
|
53
|
+
/**
|
|
54
|
+
* Callback function invoked when the confirm button is pressed in selection mode.
|
|
55
|
+
*/
|
|
26
56
|
onConfirm?: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* If true, hides the search box.
|
|
59
|
+
*/
|
|
27
60
|
hideSearch?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Callback function to handle changes in the search input.
|
|
63
|
+
*/
|
|
28
64
|
searchHandler?: (text: string) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Current search input value.
|
|
67
|
+
*/
|
|
29
68
|
searchInput?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Callback function invoked when submitting the search (e.g., via keyboard's search button).
|
|
71
|
+
*/
|
|
30
72
|
onSubmitEditing?: () => void;
|
|
73
|
+
/**
|
|
74
|
+
* Back button icon, can be an image source or a JSX element.
|
|
75
|
+
*/
|
|
31
76
|
backButtonIcon?: ImageSourcePropType | JSX.Element;
|
|
77
|
+
/**
|
|
78
|
+
* Custom style for the back button icon.
|
|
79
|
+
*/
|
|
32
80
|
backButtonIconStyle?: ImageStyle;
|
|
81
|
+
/**
|
|
82
|
+
* Title text to display in the header.
|
|
83
|
+
*/
|
|
33
84
|
title?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Custom style for the title text.
|
|
87
|
+
*/
|
|
34
88
|
titleStyle?: StyleProp<TextStyle>;
|
|
89
|
+
/**
|
|
90
|
+
* Custom style for the container wrapping the title.
|
|
91
|
+
*/
|
|
35
92
|
titleViewStyle?: StyleProp<ViewStyle>;
|
|
93
|
+
/**
|
|
94
|
+
* Custom style for the header container.
|
|
95
|
+
*/
|
|
36
96
|
containerStyle?: StyleProp<ViewStyle>;
|
|
97
|
+
/**
|
|
98
|
+
* Placeholder text for the search input.
|
|
99
|
+
*/
|
|
37
100
|
searchPlaceholderText?: string;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
101
|
+
confirmSelectionStyle?: {
|
|
102
|
+
icon?: ImageSourcePropType | JSX.Element;
|
|
103
|
+
iconStyle?: ImageStyle;
|
|
104
|
+
iconContainerStyle?: ImageStyle;
|
|
105
|
+
};
|
|
106
|
+
selectionCancelStyle?: {
|
|
107
|
+
icon?: ImageSourcePropType | JSX.Element;
|
|
108
|
+
iconStyle?: ImageStyle;
|
|
109
|
+
iconContainerStyle?: ImageStyle;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Custom style for the search component.
|
|
113
|
+
*/
|
|
42
114
|
searchStyle?: Partial<{
|
|
43
115
|
textStyle: TextStyle;
|
|
44
116
|
placehodlerTextStyle?: TextStyle;
|
|
@@ -46,10 +118,23 @@ interface HeaderProps {
|
|
|
46
118
|
icon: ImageSourcePropType | JSX.Element;
|
|
47
119
|
iconStyle: ImageStyle;
|
|
48
120
|
}>;
|
|
121
|
+
/**
|
|
122
|
+
* Custom style for the container of the back button icon.
|
|
123
|
+
*/
|
|
49
124
|
backButtonIconContainerStyle?: ViewStyle;
|
|
125
|
+
/**
|
|
126
|
+
* If true, hides the entire header.
|
|
127
|
+
*/
|
|
50
128
|
hideHeader?: boolean;
|
|
51
129
|
}
|
|
52
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Header component renders the top portion of the list with a title, back button, selection actions,
|
|
133
|
+
* AppBar options, and a search box.
|
|
134
|
+
*
|
|
135
|
+
* Props to customize the header.
|
|
136
|
+
* The rendered header component.
|
|
137
|
+
*/
|
|
53
138
|
export default function Header({
|
|
54
139
|
selectedCount = 0,
|
|
55
140
|
hideBackButton = true,
|
|
@@ -70,11 +155,9 @@ export default function Header({
|
|
|
70
155
|
titleViewStyle,
|
|
71
156
|
containerStyle,
|
|
72
157
|
searchPlaceholderText = "Search",
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
cancellationIconStyle,
|
|
77
|
-
titleSeparatorStyle,
|
|
158
|
+
confirmSelectionStyle,
|
|
159
|
+
selectionCancelStyle,
|
|
160
|
+
titleSeparatorStyle = {},
|
|
78
161
|
searchStyle,
|
|
79
162
|
hideHeader = false,
|
|
80
163
|
backButtonIconContainerStyle = { marginLeft: 10 },
|
|
@@ -84,8 +167,8 @@ export default function Header({
|
|
|
84
167
|
<View style={[styles.listBaseHeaderStyle, containerStyle]}>
|
|
85
168
|
{!hideHeader && (
|
|
86
169
|
<View style={styles.upperContainer}>
|
|
87
|
-
<View style={
|
|
88
|
-
{/*
|
|
170
|
+
<View style={{ flexDirection: "row", ...titleSeparatorStyle }}>
|
|
171
|
+
{/* Render back button and title if not in selection mode */}
|
|
89
172
|
{!shouldSelect && (!hideBackButton || title.length !== 0) && (
|
|
90
173
|
<View style={styles.headerLeftContainer}>
|
|
91
174
|
{!hideBackButton && (
|
|
@@ -116,7 +199,7 @@ export default function Header({
|
|
|
116
199
|
</View>
|
|
117
200
|
)}
|
|
118
201
|
|
|
119
|
-
{/*
|
|
202
|
+
{/* Render selection mode actions: cancel button and selected count */}
|
|
120
203
|
{shouldSelect && (
|
|
121
204
|
<View
|
|
122
205
|
style={[
|
|
@@ -127,12 +210,13 @@ export default function Header({
|
|
|
127
210
|
<TouchableOpacity onPress={onCancel}>
|
|
128
211
|
<Icon
|
|
129
212
|
name='close'
|
|
130
|
-
size={
|
|
131
|
-
height={
|
|
132
|
-
width={
|
|
133
|
-
color={
|
|
134
|
-
icon={
|
|
135
|
-
imageStyle={
|
|
213
|
+
size={selectionCancelStyle?.iconStyle?.width || 24}
|
|
214
|
+
height={selectionCancelStyle?.iconStyle?.height || 24}
|
|
215
|
+
width={selectionCancelStyle?.iconStyle?.width || 24}
|
|
216
|
+
color={selectionCancelStyle?.iconStyle?.tintColor || theme.color.iconPrimary}
|
|
217
|
+
icon={selectionCancelStyle?.icon}
|
|
218
|
+
imageStyle={selectionCancelStyle?.iconStyle}
|
|
219
|
+
containerStyle={selectionCancelStyle?.iconContainerStyle}
|
|
136
220
|
/>
|
|
137
221
|
</TouchableOpacity>
|
|
138
222
|
<Text
|
|
@@ -143,28 +227,29 @@ export default function Header({
|
|
|
143
227
|
</View>
|
|
144
228
|
)}
|
|
145
229
|
|
|
146
|
-
{/* AppBar
|
|
230
|
+
{/* Render AppBar options or the selection confirm (tick) icon */}
|
|
147
231
|
<View style={styles.headerRightContainer}>
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
232
|
+
{!shouldSelect && AppBarOptions && <AppBarOptions />}
|
|
233
|
+
{selectedCount > 0 && shouldSelect && !hideSubmitButton && (
|
|
234
|
+
<TouchableOpacity onPress={onConfirm} style={{ paddingHorizontal: 20 }}>
|
|
235
|
+
<Icon
|
|
236
|
+
name='list-item-check'
|
|
237
|
+
size={confirmSelectionStyle?.iconStyle?.width || 24}
|
|
238
|
+
height={confirmSelectionStyle?.iconStyle?.height || 24}
|
|
239
|
+
width={confirmSelectionStyle?.iconStyle?.width || 24}
|
|
240
|
+
color={confirmSelectionStyle?.iconStyle?.tintColor || theme.color.iconPrimary}
|
|
241
|
+
icon={confirmSelectionStyle?.icon}
|
|
242
|
+
imageStyle={confirmSelectionStyle?.iconStyle}
|
|
243
|
+
containerStyle={confirmSelectionStyle?.iconContainerStyle}
|
|
244
|
+
/>
|
|
245
|
+
</TouchableOpacity>
|
|
246
|
+
)}
|
|
247
|
+
</View>
|
|
163
248
|
</View>
|
|
164
249
|
</View>
|
|
165
250
|
)}
|
|
166
251
|
|
|
167
|
-
{/*
|
|
252
|
+
{/* Render search box */}
|
|
168
253
|
{!hideSearch && (
|
|
169
254
|
<View
|
|
170
255
|
style={[
|
|
@@ -194,7 +279,7 @@ export default function Header({
|
|
|
194
279
|
searchStyle?.placehodlerTextStyle?.color || theme.color.textTertiary
|
|
195
280
|
}
|
|
196
281
|
onChangeText={searchHandler}
|
|
197
|
-
returnKeyType=
|
|
282
|
+
returnKeyType='search'
|
|
198
283
|
value={searchInput}
|
|
199
284
|
numberOfLines={1}
|
|
200
285
|
style={[
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import React, { ReactNode, useCallback,
|
|
1
|
+
import React, { ReactNode, useCallback, useState } from "react";
|
|
2
2
|
import {
|
|
3
|
-
FlatList,
|
|
4
3
|
GestureResponderEvent,
|
|
5
|
-
Image,
|
|
6
4
|
ImageSourcePropType,
|
|
7
5
|
StyleProp,
|
|
8
6
|
Text,
|
|
@@ -20,30 +18,99 @@ import {
|
|
|
20
18
|
CometChatStatusIndicatorInterface,
|
|
21
19
|
} from "../CometChatStatusIndicator";
|
|
22
20
|
import { Style } from "./style";
|
|
21
|
+
import { DeepPartial } from "../../helper/types";
|
|
23
22
|
|
|
24
23
|
export interface CometChatListItemInterface {
|
|
24
|
+
/**
|
|
25
|
+
* Unique identifier for the list item.
|
|
26
|
+
*/
|
|
25
27
|
id: string | number;
|
|
28
|
+
/**
|
|
29
|
+
* URL for the avatar image.
|
|
30
|
+
*/
|
|
26
31
|
avatarURL?: ImageSourcePropType;
|
|
32
|
+
/**
|
|
33
|
+
* Fallback name for the avatar if image is not available.
|
|
34
|
+
*/
|
|
27
35
|
avatarName?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Custom style for the avatar.
|
|
38
|
+
*/
|
|
28
39
|
avatarStyle?: CometChatTheme["avatarStyle"];
|
|
40
|
+
/**
|
|
41
|
+
* Title text to display.
|
|
42
|
+
*/
|
|
29
43
|
title?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Custom style for the title text.
|
|
46
|
+
*/
|
|
30
47
|
titleStyle?: StyleProp<TextStyle>;
|
|
48
|
+
/**
|
|
49
|
+
* Custom style for the item container.
|
|
50
|
+
*/
|
|
31
51
|
containerStyle?: StyleProp<ViewStyle>;
|
|
32
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Specifies the type for the status indicator.
|
|
54
|
+
*/
|
|
55
|
+
statusIndicatorType?: CometChatStatusIndicatorInterface["type"] | null;
|
|
56
|
+
/**
|
|
57
|
+
* Custom node to display at the beginning of the item.
|
|
58
|
+
*/
|
|
33
59
|
LeadingView?: ReactNode;
|
|
60
|
+
/**
|
|
61
|
+
* Custom node to display as the title view.
|
|
62
|
+
*/
|
|
34
63
|
TitleView?: ReactNode;
|
|
64
|
+
/**
|
|
65
|
+
* Custom node to display as the subtitle view.
|
|
66
|
+
*/
|
|
35
67
|
SubtitleView?: ReactNode;
|
|
68
|
+
/**
|
|
69
|
+
* Custom node to display at the end of the item.
|
|
70
|
+
*/
|
|
36
71
|
TrailingView?: ReactNode;
|
|
72
|
+
/**
|
|
73
|
+
* Color for the separator.
|
|
74
|
+
*/
|
|
37
75
|
separatorColor?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Callback function triggered on item press.
|
|
78
|
+
*/
|
|
38
79
|
onPress?: Function;
|
|
80
|
+
/**
|
|
81
|
+
* Callback function triggered on item long press.
|
|
82
|
+
*/
|
|
39
83
|
onLongPress?: Function;
|
|
84
|
+
/**
|
|
85
|
+
* Indicates if the item is selectable.
|
|
86
|
+
*/
|
|
40
87
|
shouldSelect?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Custom style for the container of the left (head) view.
|
|
90
|
+
*/
|
|
41
91
|
headViewContainerStyle?: StyleProp<ViewStyle>;
|
|
92
|
+
/**
|
|
93
|
+
* Custom style for the container of the trailing view.
|
|
94
|
+
*/
|
|
42
95
|
trailingViewContainerStyle?: StyleProp<ViewStyle>;
|
|
96
|
+
/**
|
|
97
|
+
* Custom style for the container wrapping title and subtitle.
|
|
98
|
+
*/
|
|
43
99
|
titleSubtitleContainerStyle?: StyleProp<ViewStyle>;
|
|
100
|
+
/**
|
|
101
|
+
* Indicates if the item is selected.
|
|
102
|
+
*/
|
|
44
103
|
selected?: boolean;
|
|
104
|
+
statusIndicatorStyle?: DeepPartial<CometChatTheme['statusIndicatorStyle']>
|
|
45
105
|
}
|
|
46
106
|
|
|
107
|
+
/**
|
|
108
|
+
* CometChatListItem renders a single item in the list.
|
|
109
|
+
* It displays an avatar with an optional status indicator, title, subtitle, and trailing view.
|
|
110
|
+
*
|
|
111
|
+
* @param {CometChatListItemInterface} props - Props for the list item.
|
|
112
|
+
* @returns {JSX.Element} The rendered list item.
|
|
113
|
+
*/
|
|
47
114
|
export const CometChatListItem = React.memo((props: CometChatListItemInterface) => {
|
|
48
115
|
const [translate, setTranslate] = useState(0);
|
|
49
116
|
const theme = useTheme();
|
|
@@ -68,16 +135,14 @@ export const CometChatListItem = React.memo((props: CometChatListItemInterface)
|
|
|
68
135
|
selected = false,
|
|
69
136
|
shouldSelect,
|
|
70
137
|
TitleView,
|
|
138
|
+
statusIndicatorStyle
|
|
71
139
|
} = props;
|
|
72
140
|
|
|
73
141
|
let cancelClick = false;
|
|
74
142
|
|
|
75
|
-
|
|
76
|
-
* Component to display the avatar with optional selection box
|
|
77
|
-
*/
|
|
78
|
-
const AvatarWithStatusView = useCallback(() => {
|
|
143
|
+
const CheckBoxView = useCallback(() => {
|
|
79
144
|
return (
|
|
80
|
-
|
|
145
|
+
<>
|
|
81
146
|
{shouldSelect && (
|
|
82
147
|
<View
|
|
83
148
|
style={{
|
|
@@ -104,22 +169,14 @@ export const CometChatListItem = React.memo((props: CometChatListItemInterface)
|
|
|
104
169
|
)}
|
|
105
170
|
</View>
|
|
106
171
|
)}
|
|
107
|
-
|
|
108
|
-
<CometChatStatusIndicator type={statusIndicatorType} />
|
|
109
|
-
</View>
|
|
172
|
+
</>
|
|
110
173
|
);
|
|
111
|
-
}, [
|
|
112
|
-
avatarURL,
|
|
113
|
-
avatarName,
|
|
114
|
-
statusIndicatorType,
|
|
115
|
-
avatarStyle,
|
|
116
|
-
selected,
|
|
117
|
-
theme.color.primary,
|
|
118
|
-
shouldSelect,
|
|
119
|
-
]);
|
|
174
|
+
}, [selected, shouldSelect]);
|
|
120
175
|
|
|
121
176
|
/**
|
|
122
|
-
*
|
|
177
|
+
* Renders the title view.
|
|
178
|
+
*
|
|
179
|
+
* The title view.
|
|
123
180
|
*/
|
|
124
181
|
const getTitleView = () => {
|
|
125
182
|
if (TitleView) return TitleView;
|
|
@@ -131,7 +188,7 @@ export const CometChatListItem = React.memo((props: CometChatListItemInterface)
|
|
|
131
188
|
};
|
|
132
189
|
|
|
133
190
|
/**
|
|
134
|
-
*
|
|
191
|
+
* Handles the press event on the list item.
|
|
135
192
|
*/
|
|
136
193
|
const clickHandler = () => {
|
|
137
194
|
if (!cancelClick) {
|
|
@@ -142,7 +199,9 @@ export const CometChatListItem = React.memo((props: CometChatListItemInterface)
|
|
|
142
199
|
};
|
|
143
200
|
|
|
144
201
|
/**
|
|
145
|
-
*
|
|
202
|
+
* Handles the long press event on the list item.
|
|
203
|
+
*
|
|
204
|
+
* @param {GestureResponderEvent} e - The long press event.
|
|
146
205
|
*/
|
|
147
206
|
const longPressHandler = useCallback(
|
|
148
207
|
(e: GestureResponderEvent) => {
|
|
@@ -156,23 +215,24 @@ export const CometChatListItem = React.memo((props: CometChatListItemInterface)
|
|
|
156
215
|
);
|
|
157
216
|
|
|
158
217
|
/**
|
|
159
|
-
*
|
|
218
|
+
* Renders the trailing view of the list item.
|
|
219
|
+
*
|
|
220
|
+
* @returns {JSX.Element | null} The trailing view if provided.
|
|
160
221
|
*/
|
|
161
222
|
const getTrailingView = () => {
|
|
162
223
|
if (TrailingView)
|
|
163
224
|
return (
|
|
164
225
|
<View style={[Style.tailViewStyle, trailingViewContainerStyle ?? {}]}>{TrailingView}</View>
|
|
165
226
|
);
|
|
166
|
-
|
|
167
227
|
return null;
|
|
168
228
|
};
|
|
169
229
|
|
|
170
230
|
let ListComponent =
|
|
171
|
-
(onPress && typeof onPress
|
|
231
|
+
(onPress && typeof onPress === "function") || (onLongPress && typeof onLongPress === "function")
|
|
172
232
|
? TouchableOpacity
|
|
173
233
|
: View;
|
|
174
234
|
let listComponentProps =
|
|
175
|
-
(onPress && typeof onPress
|
|
235
|
+
(onPress && typeof onPress === "function") || (onLongPress && typeof onLongPress === "function")
|
|
176
236
|
? {
|
|
177
237
|
activeOpacity: 1,
|
|
178
238
|
onPress: clickHandler,
|
|
@@ -180,18 +240,44 @@ export const CometChatListItem = React.memo((props: CometChatListItemInterface)
|
|
|
180
240
|
}
|
|
181
241
|
: {};
|
|
182
242
|
|
|
243
|
+
const getLeadingView = useCallback(() => {
|
|
244
|
+
return (
|
|
245
|
+
<View style={[{ flexDirection: "row", alignItems: "center" }, headViewContainerStyle]}>
|
|
246
|
+
<CheckBoxView />
|
|
247
|
+
{LeadingView ? (
|
|
248
|
+
LeadingView
|
|
249
|
+
) : avatarURL || avatarName ? (
|
|
250
|
+
<>
|
|
251
|
+
<CometChatAvatar image={avatarURL} name={avatarName!} style={avatarStyle} />
|
|
252
|
+
<CometChatStatusIndicator type={statusIndicatorType} style={statusIndicatorStyle} />
|
|
253
|
+
</>
|
|
254
|
+
) : null}
|
|
255
|
+
</View>
|
|
256
|
+
);
|
|
257
|
+
}, [
|
|
258
|
+
avatarURL,
|
|
259
|
+
avatarName,
|
|
260
|
+
statusIndicatorType,
|
|
261
|
+
avatarStyle,
|
|
262
|
+
headViewContainerStyle,
|
|
263
|
+
theme,
|
|
264
|
+
selected,
|
|
265
|
+
shouldSelect,
|
|
266
|
+
statusIndicatorStyle
|
|
267
|
+
]);
|
|
268
|
+
|
|
183
269
|
return (
|
|
184
270
|
<ListComponent
|
|
185
271
|
{...listComponentProps}
|
|
186
272
|
style={[containerStyle, selected && { backgroundColor: theme.color.background4 }]}
|
|
187
273
|
>
|
|
188
|
-
{
|
|
274
|
+
{getLeadingView()}
|
|
189
275
|
<View style={[Style.rightContainerStyle]}>
|
|
190
276
|
<View
|
|
191
277
|
style={[
|
|
192
278
|
Style.middleViewStyle,
|
|
193
279
|
{ padding: 0, paddingLeft: 0 },
|
|
194
|
-
|
|
280
|
+
titleSubtitleContainerStyle ?? {},
|
|
195
281
|
]}
|
|
196
282
|
>
|
|
197
283
|
{getTitleView()}
|
|
@@ -1,66 +1,88 @@
|
|
|
1
|
-
import React, { memo,
|
|
1
|
+
import React, { memo, useState, useCallback } from "react";
|
|
2
2
|
import { View, ViewProps } from "react-native";
|
|
3
3
|
import { BubbleStyles } from "../../../theme/type";
|
|
4
4
|
import { MessageBubbleAlignmentType } from "../../base/Types";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Props for the CometChatMessageBubble component.
|
|
8
|
+
*/
|
|
6
9
|
export interface CometChatMessageBubbleInterface {
|
|
7
10
|
/**
|
|
8
|
-
* The
|
|
9
|
-
*
|
|
11
|
+
* The unique identifier of the message bubble.
|
|
12
|
+
*
|
|
13
|
+
* @type {string}
|
|
10
14
|
*/
|
|
11
15
|
id: string;
|
|
12
16
|
/**
|
|
13
17
|
* The leading view of the message bubble.
|
|
14
|
-
*
|
|
18
|
+
*
|
|
19
|
+
* @type {JSX.Element | null}
|
|
15
20
|
*/
|
|
16
21
|
LeadingView?: JSX.Element | null;
|
|
17
22
|
/**
|
|
18
23
|
* The header view of the message bubble.
|
|
19
|
-
*
|
|
24
|
+
*
|
|
25
|
+
* @type {JSX.Element | null}
|
|
20
26
|
*/
|
|
21
27
|
HeaderView?: JSX.Element | null;
|
|
22
28
|
/**
|
|
23
29
|
* The status info view of the message bubble.
|
|
24
|
-
*
|
|
30
|
+
*
|
|
31
|
+
* @type {JSX.Element | null}
|
|
25
32
|
*/
|
|
26
33
|
StatusInfoView?: JSX.Element | null;
|
|
27
34
|
/**
|
|
28
35
|
* The reply view of the message bubble.
|
|
29
|
-
*
|
|
36
|
+
*
|
|
37
|
+
* @type {JSX.Element | null}
|
|
30
38
|
*/
|
|
31
39
|
ReplyView?: JSX.Element | null;
|
|
32
40
|
/**
|
|
33
41
|
* The bottom view of the message bubble.
|
|
34
|
-
*
|
|
42
|
+
*
|
|
43
|
+
* @type {JSX.Element | null}
|
|
35
44
|
*/
|
|
36
45
|
BottomView?: JSX.Element | null;
|
|
37
46
|
/**
|
|
38
47
|
* The content view of the message bubble.
|
|
39
|
-
*
|
|
48
|
+
*
|
|
49
|
+
* @type {JSX.Element | null}
|
|
40
50
|
*/
|
|
41
51
|
ContentView?: JSX.Element | null;
|
|
42
52
|
/**
|
|
43
53
|
* The thread view of the message bubble.
|
|
44
|
-
*
|
|
54
|
+
*
|
|
55
|
+
* @type {JSX.Element | null}
|
|
45
56
|
*/
|
|
46
57
|
ThreadView?: JSX.Element | null;
|
|
47
58
|
/**
|
|
48
|
-
* The footer view of the message bubble.
|
|
49
|
-
*
|
|
59
|
+
* The footer view of the message bubble. Can be a JSX element or a function returning a JSX element.
|
|
60
|
+
*
|
|
61
|
+
* @type {JSX.Element | ((params: { maxContentWidth: number }) => JSX.Element) | null}
|
|
50
62
|
*/
|
|
51
|
-
FooterView?: JSX.Element | ((params: {maxContentWidth: number}) => JSX.Element) | null;
|
|
63
|
+
FooterView?: JSX.Element | ((params: { maxContentWidth: number }) => JSX.Element) | null;
|
|
52
64
|
/**
|
|
53
65
|
* The alignment of the message bubble.
|
|
54
|
-
*
|
|
66
|
+
*
|
|
67
|
+
* @type {MessageBubbleAlignmentType}
|
|
55
68
|
*/
|
|
56
69
|
alignment?: MessageBubbleAlignmentType;
|
|
57
70
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
71
|
+
* Custom styles for the message bubble.
|
|
72
|
+
*
|
|
73
|
+
* @type {BubbleStyles}
|
|
60
74
|
*/
|
|
61
75
|
style?: BubbleStyles;
|
|
62
76
|
}
|
|
63
77
|
|
|
78
|
+
/**
|
|
79
|
+
* CometChatMessageBubble renders a customizable message bubble with optional header, content, footer,
|
|
80
|
+
* and additional views such as leading, bottom, and thread views. The component adjusts its alignment
|
|
81
|
+
* based on the provided `alignment` prop.
|
|
82
|
+
*
|
|
83
|
+
* @param {CometChatMessageBubbleInterface} props - Props for configuring the message bubble.
|
|
84
|
+
* @returns {JSX.Element} The rendered message bubble.
|
|
85
|
+
*/
|
|
64
86
|
export const CometChatMessageBubble = memo(
|
|
65
87
|
({
|
|
66
88
|
HeaderView,
|
|
@@ -77,11 +99,14 @@ export const CometChatMessageBubble = memo(
|
|
|
77
99
|
}: CometChatMessageBubbleInterface) => {
|
|
78
100
|
const [_width, setWidth] = useState<number | undefined>();
|
|
79
101
|
|
|
80
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Handles layout changes by updating the component's width.
|
|
104
|
+
*
|
|
105
|
+
* @param {any} event - The layout event.
|
|
106
|
+
*/
|
|
81
107
|
const handleLayout = useCallback(
|
|
82
108
|
(event: any) => {
|
|
83
109
|
const { width: newWidth } = event.nativeEvent.layout;
|
|
84
|
-
|
|
85
110
|
// Update width only if it has changed
|
|
86
111
|
if (newWidth !== _width) {
|
|
87
112
|
setWidth(newWidth);
|
|
@@ -92,20 +117,17 @@ export const CometChatMessageBubble = memo(
|
|
|
92
117
|
|
|
93
118
|
return (
|
|
94
119
|
<View
|
|
95
|
-
// key={id}
|
|
96
120
|
style={{
|
|
97
121
|
width: "100%",
|
|
98
122
|
alignItems:
|
|
99
|
-
alignment === "right"
|
|
123
|
+
alignment === "right"
|
|
124
|
+
? "flex-end"
|
|
125
|
+
: alignment === "left"
|
|
126
|
+
? "flex-start"
|
|
127
|
+
: alignment,
|
|
100
128
|
}}
|
|
101
129
|
>
|
|
102
|
-
<View
|
|
103
|
-
style={
|
|
104
|
-
{
|
|
105
|
-
flexDirection: "row",
|
|
106
|
-
} as ViewProps
|
|
107
|
-
}
|
|
108
|
-
>
|
|
130
|
+
<View style={{ flexDirection: "row" } as ViewProps}>
|
|
109
131
|
{LeadingView && LeadingView}
|
|
110
132
|
<View style={{ marginStart: 4, maxWidth: "80%" } as ViewProps}>
|
|
111
133
|
{HeaderView && HeaderView}
|
|
@@ -119,8 +141,8 @@ export const CometChatMessageBubble = memo(
|
|
|
119
141
|
<View style={{ maxWidth: _width }}>
|
|
120
142
|
{FooterView
|
|
121
143
|
? typeof FooterView === "function"
|
|
122
|
-
? FooterView({ maxContentWidth: _width }) // Call
|
|
123
|
-
: FooterView // Render
|
|
144
|
+
? FooterView({ maxContentWidth: _width }) // Call function if FooterView is a function
|
|
145
|
+
: FooterView // Render JSX element directly
|
|
124
146
|
: null}
|
|
125
147
|
</View>
|
|
126
148
|
)}
|
|
@@ -130,4 +152,4 @@ export const CometChatMessageBubble = memo(
|
|
|
130
152
|
</View>
|
|
131
153
|
);
|
|
132
154
|
}
|
|
133
|
-
);
|
|
155
|
+
);
|