@cometchat/chat-uikit-react-native 5.2.5 → 5.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cometchat/chat-uikit-react-native",
3
- "version": "5.2.5",
3
+ "version": "5.2.6",
4
4
  "description": "Ready-to-use Chat UI Components for React Native",
5
5
  "main": "src/index",
6
6
  "module": "src/index",
@@ -264,12 +264,18 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
264
264
  const [tooltipVisible, setTooltipVisible] = useState(false);
265
265
  const [modalType, setModalType] = useState<"ban" | "kick" | "">("");
266
266
  const modalVisible = modalType !== "";
267
- const [selectedRole, setSelectedRole] = useState("Participant");
267
+ const [selectedRole, setSelectedRole] = useState<string>("");
268
268
  const [currentUserRole, setCurrentUserRole] = useState<string | null>(null);
269
269
  const listRef = useRef<any>(null);
270
270
  const [isToolTipDismissed, setIsToolTipDismissed] = useState(false);
271
271
  const loggedInUser = React.useRef(CometChatUIKit.loggedInUser!);
272
272
 
273
+ // Derived: whether selected scope equals current user scope
274
+ const isScopeUnchanged = React.useMemo(() => {
275
+ if (!selectedItem) return true;
276
+ return selectedRole === selectedItem.getScope();
277
+ }, [selectedItem, selectedRole]);
278
+
273
279
 
274
280
  // Define role permissions for current user actions
275
281
  const RolePermissions: { [key: string]: string[] } = {
@@ -517,9 +523,9 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
517
523
  onPress: () => {
518
524
  const currentScope = item.getScope();
519
525
  setTooltipVisible(false);
520
- const formattedScope = currentScope.charAt(0).toUpperCase() + currentScope.slice(1);
521
526
  setIsBottomSheetVisible(true);
522
- setSelectedRole(formattedScope);
527
+ // Preselect to current scope (lowercase) for accurate comparison
528
+ setSelectedRole(currentScope);
523
529
  },
524
530
  icon: (
525
531
  <ChangeCircle
@@ -771,8 +777,12 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
771
777
  onClose={() => {
772
778
  setIsBottomSheetVisible(false);
773
779
  setSelectedItem(null);
780
+ setSelectedRole("");
781
+ }}
782
+ onDismiss={() => {
783
+ setSelectedItem(null);
784
+ setSelectedRole("");
774
785
  }}
775
- onDismiss={() => setSelectedItem(null)}
776
786
  >
777
787
  {selectedItem ? (
778
788
  <View style={mergedStyle?.changeScope?.container}>
@@ -861,6 +871,7 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
861
871
  onPress={() => {
862
872
  setIsBottomSheetVisible(false);
863
873
  setSelectedItem(null);
874
+ setSelectedRole("");
864
875
  }}
865
876
  >
866
877
  <Text style={mergedStyle?.changeScope?.cancelStyle?.textStyle}>
@@ -868,8 +879,13 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
868
879
  </Text>
869
880
  </TouchableOpacity>
870
881
  <TouchableOpacity
871
- style={mergedStyle?.changeScope?.confirmStyle?.containerStyle}
882
+ style={[
883
+ mergedStyle?.changeScope?.confirmStyle?.containerStyle,
884
+ isScopeUnchanged ? {opacity: 0.5} : {}
885
+ ]}
886
+ disabled={isScopeUnchanged}
872
887
  onPress={async () => {
888
+ if (isScopeUnchanged) return;
873
889
  if (selectedItem && selectedRole) {
874
890
  const currentScope = selectedItem.getScope();
875
891
  const scopeToSet = selectedRole;
@@ -878,7 +894,7 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
878
894
  if (scopeToSet === currentScope) {
879
895
  setIsBottomSheetVisible(false);
880
896
  setSelectedItem(null);
881
- setSelectedRole("participant");
897
+ setSelectedRole("");
882
898
  return;
883
899
  }
884
900
 
@@ -925,7 +941,7 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
925
941
  }
926
942
  );
927
943
  setSelectedItem(null);
928
- setSelectedRole("Participant");
944
+ setSelectedRole("");
929
945
  } catch (error) {
930
946
  console.error("Error updating user scope:", error);
931
947
  }
@@ -164,14 +164,14 @@ export interface CometChatMessageComposerInterface {
164
164
  id?: string | number;
165
165
 
166
166
  /**
167
- * CometChat SDK’s user object.
167
+ * CometChat SDK's user object.
168
168
  *
169
169
  * @type {CometChat.User}
170
170
  */
171
171
  user?: CometChat.User;
172
172
 
173
173
  /**
174
- * CometChat SDK’s group object.
174
+ * CometChat SDK's group object.
175
175
  *
176
176
  * @type {CometChat.Group}
177
177
  */
@@ -1611,6 +1611,16 @@ export const CometChatMessageComposer = React.forwardRef(
1611
1611
  return false; // No mention found at the cursor position
1612
1612
  }
1613
1613
 
1614
+ function getMentionRangeAtCursor(mentionRanges: any, cursorPosition: number): { start: number; end: number } | null {
1615
+ for (let [range] of mentionRanges) {
1616
+ const [start, end] = range.split("_").map(Number);
1617
+ if (cursorPosition >= start && cursorPosition <= end) {
1618
+ return { start, end }; // Return the boundary positions
1619
+ }
1620
+ }
1621
+ return null; // No mention found at the cursor position
1622
+ }
1623
+
1614
1624
  function shouldOpenList(
1615
1625
  selection: {
1616
1626
  start: number;
@@ -2284,9 +2294,31 @@ export const CometChatMessageComposer = React.forwardRef(
2284
2294
  },
2285
2295
  }}
2286
2296
  onSelectionChange={({ nativeEvent: { selection } }) => {
2297
+ const cursorPos = selection.start;
2298
+ const mentionRange = getMentionRangeAtCursor(mentionMap.current, cursorPos);
2299
+
2300
+ if (mentionRange) {
2301
+ console.log('Mention boundary positions:', mentionRange);
2302
+ const distanceToStart = cursorPos - mentionRange.start;
2303
+ const distanceToEnd = mentionRange.end - cursorPos;
2304
+ let targetPosition: number;
2305
+ if (distanceToStart <= distanceToEnd) {
2306
+ targetPosition = mentionRange.start;
2307
+ } else {
2308
+ targetPosition = mentionRange.end;
2309
+ }
2310
+ if (targetPosition !== cursorPos) {
2311
+ InteractionManager.runAfterInteractions(() => {
2312
+ setSelectionPosition({ start: targetPosition, end: targetPosition });
2313
+ });
2314
+ return;
2315
+ }
2316
+ }
2317
+
2287
2318
  setSelectionPosition(selection);
2288
2319
  openList(selection);
2289
2320
  }}
2321
+ selection={selectionPosition}
2290
2322
  onChangeText={textChangeHandler}
2291
2323
  VoiceRecordingButtonView={voiceRecoringButtonElem}
2292
2324
  SecondaryButtonView={SecondaryButtonViewElem}
@@ -335,7 +335,10 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
335
335
  };
336
336
 
337
337
  const handleUserStatus = (userDetails: CometChat.User) => {
338
- if (userDetails.getUid() === userObj?.getUid()) setUserStatus(userDetails.getStatus());
338
+ if (userDetails.getUid() === userObj?.getUid()) {
339
+ setUserObj(userDetails);
340
+ setUserStatus(userDetails.getStatus());
341
+ }
339
342
  };
340
343
 
341
344
  const msgTypingIndicator = (typist: CometChat.TypingIndicator, status: string) => {
@@ -559,7 +559,7 @@ export const CometChatMessageList = memo(
559
559
  const hideReactionOption = isAgenticUser() ? true : propHideReactionOption;
560
560
  const hideMessagePrivatelyOption = isAgenticUser() ? true : propHideMessagePrivatelyOption;
561
561
  const hideCopyMessageOption = isAgenticUser() ? true : propHideCopyMessageOption;
562
- const hideMessageInfoOption = isAgenticUser() ? true : propHideMessageInfoOption;
562
+ const hideMessageInfoOption = isAgenticUser() ? true : (propHideMessageInfoOption || !receiptsVisibility);
563
563
  const hideGroupActionMessages = isAgenticUser() ? true : propHideGroupActionMessages;
564
564
  const hideFlagMessageOption = isAgenticUser() ? true : propHideFlagMessageOption;
565
565
 
@@ -1261,7 +1261,7 @@ export const CometChatMessageList = memo(
1261
1261
  hideReactionOption: isAgenticUserCheck || hideReactionOption,
1262
1262
  hideMessagePrivatelyOption: isAgenticUserCheck || hideMessagePrivatelyOption,
1263
1263
  hideCopyMessageOption: isAgenticUserCheck || hideCopyMessageOption,
1264
- hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption,
1264
+ hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption || !receiptsVisibility,
1265
1265
  hideFlagMessageOption: isAgenticUserCheck || hideFlagMessageOption,
1266
1266
  hideGroupActionMessages,
1267
1267
  onReplyClick: (messageId: string) => {
@@ -1310,6 +1310,7 @@ export const CometChatMessageList = memo(
1310
1310
  hideCopyMessageOption,
1311
1311
  hideMessageInfoOption,
1312
1312
  hideGroupActionMessages,
1313
+ receiptsVisibility,
1313
1314
  ]);
1314
1315
 
1315
1316
  const getPlainString = (underlyingText: string, messageObject: CometChat.BaseMessage) => {
@@ -2332,6 +2333,7 @@ export const CometChatMessageList = memo(
2332
2333
 
2333
2334
  useEffect(() => {
2334
2335
  if (selectedEmoji) {
2336
+ Keyboard.dismiss();
2335
2337
  setShowReactionList(true);
2336
2338
  }
2337
2339
  }, [selectedEmoji]);
@@ -681,7 +681,6 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
681
681
  const handleClearSearch = useCallback(() => {
682
682
  setSearchValue("");
683
683
  dispatch({ type: "setSearchText", searchText: "" });
684
- dispatch({ type: "resetActiveFilters" });
685
684
  dispatch({ type: "clearResults" });
686
685
  }, []);
687
686
 
@@ -52,8 +52,16 @@ export const CometChatAvatar = (props: CometChatAvatarProps) => {
52
52
  return <Image source={imageSource} style={[avatarStyle.imageStyle]} />;
53
53
  }
54
54
  const initials = [...(name || "")].slice(0, 2).join("").toUpperCase();
55
-
56
- return <Text style={[avatarStyle.textStyle]}>{initials}</Text>;
55
+
56
+ return (
57
+ <Text
58
+ style={[avatarStyle.textStyle]}
59
+ adjustsFontSizeToFit={true}
60
+ numberOfLines={1}
61
+ >
62
+ {initials}
63
+ </Text>
64
+ );
57
65
  }, [image, name, avatarStyle.imageStyle, avatarStyle.textStyle]);
58
66
 
59
67
  return <View style={[avatarStyle.containerStyle]}>{getImageView()}</View>;
@@ -6,6 +6,7 @@ import {
6
6
  GestureResponderEvent,
7
7
  ImageSourcePropType,
8
8
  ImageStyle,
9
+ Platform,
9
10
  StyleProp,
10
11
  Text,
11
12
  TextStyle,
@@ -245,11 +246,17 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
245
246
 
246
247
  const listHandlerRef = useRef<any>(null);
247
248
  const initialRunRef = useRef(true);
249
+ const selectionEffectDidMountRef = useRef(false);
248
250
 
249
251
  const [list, setList] = useState<any[]>([]);
250
252
  const [dataLoadingStatus, setDataLoadingStatus] = useState<string>(LOADING);
251
253
 
252
254
  useEffect(() => {
255
+ // Skip calling onSelection on initial mount; only trigger after a user-driven change
256
+ if (!selectionEffectDidMountRef.current) {
257
+ selectionEffectDidMountRef.current = true;
258
+ return;
259
+ }
253
260
  if (props.onSelection) {
254
261
  const selectedArray = Object.values(selectedItems);
255
262
  props.onSelection(selectedArray);
@@ -766,6 +773,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
766
773
  showsVerticalScrollIndicator={false}
767
774
  ListFooterComponent={renderFooter}
768
775
  keyboardShouldPersistTaps='always'
776
+ keyboardDismissMode={Platform.OS === 'ios' ? 'on-drag' : 'none'}
769
777
  />
770
778
  </View>
771
779
  );
@@ -202,6 +202,7 @@ export default function Header({
202
202
  <Text
203
203
  ellipsizeMode='tail'
204
204
  numberOfLines={1}
205
+ allowFontScaling={true}
205
206
  style={[{ color: theme.color.textPrimary }, titleStyle]}
206
207
  >
207
208
  {title}
@@ -39,7 +39,8 @@ const styles = StyleSheet.create({
39
39
  flexDirection: "row",
40
40
  alignItems: "center",
41
41
  justifyContent: "center",
42
- height: 55,
42
+ minHeight: 44, // minHeight for accessibility
43
+ paddingVertical:8,
43
44
  },
44
45
  selectedCountText: {
45
46
  paddingLeft: 10,
@@ -90,11 +91,12 @@ const styles = StyleSheet.create({
90
91
  width: "100%",
91
92
  },
92
93
  headerLetterStyle: {
93
- height: 24,
94
+ minHeight: 24, // minHeight for accessibility
94
95
  fontWeight: "500",
95
96
  fontFamily: undefined,
96
97
  fontSize: 13,
97
98
  marginTop: 8,
99
+ paddingVertical: 4,
98
100
  },
99
101
  dividerStyle: {
100
102
  height: 1,
@@ -88,6 +88,12 @@ export interface CometChatMessageInputInterface {
88
88
  * @type {RefObject<any>}
89
89
  */
90
90
  messageInputRef?: RefObject<any>;
91
+ /**
92
+ * Selection state for the TextInput to control cursor position.
93
+ *
94
+ * @type {{ start: number; end: number } | undefined}
95
+ */
96
+ selection?: { start: number; end: number };
91
97
  }
92
98
 
93
99
  /**
@@ -112,6 +118,7 @@ export const CometChatMessageInput = (props: CometChatMessageInputInterface) =>
112
118
  onSelectionChange,
113
119
  messageInputRef,
114
120
  VoiceRecordingButtonView,
121
+ selection,
115
122
  } = props;
116
123
 
117
124
  return (
@@ -125,6 +132,7 @@ export const CometChatMessageInput = (props: CometChatMessageInputInterface) =>
125
132
  textAlignVertical='top'
126
133
  placeholder={placeHolderText}
127
134
  onSelectionChange={onSelectionChange}
135
+ selection={selection}
128
136
  onFocus={() => {
129
137
  CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.hidePanel, {
130
138
  alignment: ViewAlignment.composerBottom,