@cometchat/chat-uikit-react-native 5.4.1 → 5.5.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 (80) hide show
  1. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  2. package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
  3. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  4. package/android/.gradle/7.4/gc.properties +0 -0
  5. package/android/.gradle/vcs-1/gc.properties +0 -0
  6. package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +34 -0
  7. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +542 -5
  8. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +20 -1
  9. package/ios/CometChatClipboardModule.m +5 -0
  10. package/ios/CometChatClipboardModule.swift +22 -0
  11. package/ios/RichTextEditorView.swift +593 -31
  12. package/ios/RichTextEditorViewManager.m +2 -0
  13. package/ios/RichTextEditorViewManager.swift +16 -0
  14. package/package.json +1 -1
  15. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +245 -55
  16. package/src/CometChatCompactMessageComposer/index.ts +2 -0
  17. package/src/CometChatConversations/CometChatConversations.tsx +291 -14
  18. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
  19. package/src/CometChatMessageList/CometChatMessageList.tsx +568 -15
  20. package/src/CometChatMessageList/MANUAL_TEST_CASES.md +154 -0
  21. package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
  22. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +14 -1
  23. package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
  24. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +940 -0
  25. package/src/CometChatPinnedMessages/index.ts +5 -0
  26. package/src/CometChatPinnedMessages/style.ts +216 -0
  27. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +5 -0
  28. package/src/CometChatRichTextEditor/index.tsx +27 -1
  29. package/src/CometChatRichTextEditor/types.ts +19 -1
  30. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +634 -0
  31. package/src/CometChatSavedMessages/index.ts +5 -0
  32. package/src/CometChatSavedMessages/style.ts +159 -0
  33. package/src/CometChatSearch/CometChatSearch.tsx +47 -340
  34. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
  35. package/src/index.ts +60 -0
  36. package/src/shared/CometChatUiKit/CometChatUIKit.ts +16 -0
  37. package/src/shared/base/Types.ts +5 -0
  38. package/src/shared/constants/UIKitConstants.ts +13 -0
  39. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +34 -0
  40. package/src/shared/events/CometChatUIEventHandler/Listener.ts +37 -0
  41. package/src/shared/events/ListenerInitializer.ts +20 -1
  42. package/src/shared/events/messages.ts +18 -0
  43. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +92 -6
  44. package/src/shared/formatters/index.ts +14 -0
  45. package/src/shared/formatters/richTextWireFormat.ts +165 -0
  46. package/src/shared/framework/MessageDataSource.tsx +296 -3
  47. package/src/shared/icons/components/thread-follow.tsx +13 -0
  48. package/src/shared/icons/components/thread-unfollow.tsx +13 -0
  49. package/src/shared/icons/components/unsave.tsx +13 -0
  50. package/src/shared/icons/icon-mapping.tsx +6 -0
  51. package/src/shared/index.ts +37 -0
  52. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +54 -0
  53. package/src/shared/utils/MarkdownUtils.ts +25 -4
  54. package/src/shared/utils/MessageUtils.tsx +80 -5
  55. package/src/shared/utils/PinConversationHelper.ts +245 -0
  56. package/src/shared/utils/PinSaveFeatureGates.ts +178 -0
  57. package/src/shared/utils/PinSaveHelper.ts +549 -0
  58. package/src/shared/utils/SavedMessagesHelper.ts +231 -0
  59. package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
  60. package/src/shared/utils/conversationUtils.ts +8 -1
  61. package/src/shared/utils/stripRichText.ts +7 -0
  62. package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +21 -0
  63. package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
  64. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
  65. package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
  66. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +1 -0
  67. package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
  68. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
  69. package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
  70. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +4 -0
  71. package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +1 -0
  72. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +4 -0
  73. package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
  74. package/src/theme/default/default.ts +6 -0
  75. package/src/theme/type.ts +4 -0
  76. package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +0 -478
  77. package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +0 -613
  78. package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +0 -313
  79. package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +0 -76
  80. package/src/shared/CometChatUiKit/checkAuthSettings-review.md +0 -211
@@ -0,0 +1,5 @@
1
+ export { CometChatPinnedMessages } from "./CometChatPinnedMessages";
2
+ export type { CometChatPinnedMessagesInterface } from "./CometChatPinnedMessages";
3
+
4
+ export { getPinnedMessagesStyleLight, getPinnedMessagesStyleDark } from "./style";
5
+ export type { PinnedMessagesStyle } from "./style";
@@ -0,0 +1,216 @@
1
+ import { ImageSourcePropType, ImageStyle, TextStyle, ViewStyle } from "react-native";
2
+ import { JSX } from "react";
3
+ import { CometChatTheme } from "../theme/type";
4
+
5
+ /**
6
+ * Style type for the CometChatPinnedMessages component (design doc §6.7).
7
+ *
8
+ * Every value maps to a SEMANTIC theme token rather than a literal, so light and
9
+ * dark are two calls to the same builder and an integrator retheming the kit gets
10
+ * this surface for free.
11
+ */
12
+ export type PinnedMessagesStyle = {
13
+ /** Root container. */
14
+ containerStyle: ViewStyle;
15
+
16
+ /** Header: title on the left, close affordance on the right. */
17
+ headerContainerStyle: ViewStyle;
18
+ titleStyle: TextStyle;
19
+ closeButtonIconStyle: ImageStyle;
20
+ closeButtonIcon?: ImageSourcePropType | JSX.Element;
21
+
22
+ /** One pinned message row: the sender line above, the bubble below. */
23
+ itemStyle: {
24
+ containerStyle: ViewStyle;
25
+ /** Avatar + name + date row that sits above the bubble. */
26
+ headerContainerStyle: ViewStyle;
27
+ avatarStyle: CometChatTheme["avatarStyle"];
28
+ senderNameStyle: TextStyle;
29
+ separatorStyle: TextStyle;
30
+ dateStyle: Partial<CometChatTheme["dateStyles"]>;
31
+ /** Bookmark shown when a pinned message is ALSO saved by this viewer. */
32
+ savedIndicatorStyle: ImageStyle;
33
+ savedIndicatorContainerStyle: ViewStyle;
34
+ /** Left inset that lines the bubble up under the sender name. */
35
+ bubbleContainerStyle: ViewStyle;
36
+ };
37
+
38
+ /** Empty and error states. */
39
+ emptyStateStyle: {
40
+ /** Centres the whole block in the space the list would have filled. */
41
+ containerStyle: ViewStyle;
42
+ titleStyle: TextStyle;
43
+ subTitleStyle: TextStyle;
44
+ iconStyle: ImageStyle;
45
+ };
46
+ errorStateStyle: {
47
+ containerStyle: ViewStyle;
48
+ titleStyle: TextStyle;
49
+ subTitleStyle: TextStyle;
50
+ iconStyle: ImageStyle;
51
+ };
52
+ };
53
+
54
+ export const getPinnedMessagesStyleLight = (
55
+ color: CometChatTheme["color"],
56
+ spacing: CometChatTheme["spacing"],
57
+ typography: CometChatTheme["typography"]
58
+ ): PinnedMessagesStyle => ({
59
+ containerStyle: {
60
+ flex: 1,
61
+ backgroundColor: color.background1,
62
+ },
63
+ // Mirrors the Group Info / User Info header: a leading back arrow, then the title. Those
64
+ // screens are the reference for every full-screen view in the app, so the paddings and the
65
+ // heading1.bold title are copied rather than re-invented.
66
+ headerContainerStyle: {
67
+ flexDirection: "row",
68
+ alignItems: "center",
69
+ paddingTop: spacing.padding.p4,
70
+ paddingLeft: spacing.padding.p2,
71
+ paddingBottom: spacing.padding.p2,
72
+ },
73
+ titleStyle: {
74
+ ...typography.heading1.bold,
75
+ color: color.textPrimary,
76
+ paddingLeft: spacing.padding.p1,
77
+ },
78
+ closeButtonIconStyle: {
79
+ tintColor: color.iconPrimary,
80
+ height: spacing.spacing.s6,
81
+ width: spacing.spacing.s6,
82
+ },
83
+ itemStyle: {
84
+ containerStyle: {
85
+ paddingHorizontal: spacing.padding.p4,
86
+ paddingVertical: spacing.padding.p3,
87
+ },
88
+ headerContainerStyle: {
89
+ flexDirection: "row",
90
+ alignItems: "center",
91
+ marginBottom: spacing.margin.m1,
92
+ },
93
+ avatarStyle: {
94
+ containerStyle: {
95
+ height: spacing.spacing.s8,
96
+ width: spacing.spacing.s8,
97
+ },
98
+ // The font has to come down WITH the circle (ENG-38886).
99
+ //
100
+ // The theme sizes initials at heading2.bold (20px) for its own 48px avatar. This row uses
101
+ // a 32px one, and two capitals at 20px do not fit inside it — which left the whole thing
102
+ // resting on `adjustsFontSizeToFit`. That prop shrinks text differently on iOS than on
103
+ // Android, so the initials came out clipped and mis-centred on iOS only, while Android
104
+ // looked fine and hid the problem.
105
+ //
106
+ // body.bold (14px) keeps roughly the same letter-to-circle ratio the theme uses at 48px,
107
+ // so the text fits on its own and the auto-shrink never has to do anything.
108
+ textStyle: {
109
+ ...typography.body.bold,
110
+ // heading2.bold brings a 28px lineHeight with it; left in place it pushes two 14px
111
+ // capitals off-centre inside a 32px circle.
112
+ lineHeight: undefined,
113
+ },
114
+ },
115
+ senderNameStyle: {
116
+ ...typography.body.medium,
117
+ color: color.textHighlight,
118
+ marginLeft: spacing.margin.m2,
119
+ },
120
+ separatorStyle: {
121
+ ...typography.caption1.regular,
122
+ color: color.textSecondary,
123
+ marginHorizontal: spacing.margin.m1,
124
+ },
125
+ dateStyle: {
126
+ textStyle: {
127
+ ...typography.caption1.regular,
128
+ color: color.textSecondary,
129
+ },
130
+ },
131
+ savedIndicatorStyle: {
132
+ tintColor: color.iconSecondary,
133
+ height: 14,
134
+ width: 14,
135
+ },
136
+ savedIndicatorContainerStyle: {
137
+ marginLeft: spacing.margin.m1,
138
+ },
139
+ bubbleContainerStyle: {
140
+ // Lines the bubble up under the sender name rather than the avatar.
141
+ marginLeft: spacing.spacing.s10,
142
+ },
143
+ },
144
+ emptyStateStyle: {
145
+ containerStyle: {
146
+ flex: 1,
147
+ alignItems: "center",
148
+ justifyContent: "center",
149
+ paddingHorizontal: spacing.padding.p8,
150
+ gap: spacing.spacing.s2,
151
+ },
152
+ titleStyle: {
153
+ ...typography.heading4.bold,
154
+ color: color.textPrimary,
155
+ textAlign: "center",
156
+ },
157
+ subTitleStyle: {
158
+ ...typography.body.regular,
159
+ color: color.textSecondary,
160
+ textAlign: "center",
161
+ },
162
+ iconStyle: {
163
+ tintColor: color.iconSecondary,
164
+ // 120, not a spacing token: these glyphs sit in a 24x24 viewBox but only fill ~54% of its
165
+ // width, so the BOX has to be far larger than the mark you want to see. The design's
166
+ // bookmark measures 66x80 against a 16px title, and 66 / 0.54 ≈ 120. Using s14 (56) drew
167
+ // a 30x37 mark — less than half the intended size.
168
+ height: 120,
169
+ width: 120,
170
+ marginBottom: spacing.margin.m3,
171
+ },
172
+ },
173
+ // Same layout as the empty state, because it fills the same hole. The icon needs no
174
+ // size compensation: `error-state` is a purpose-built 120x120 illustration that fills
175
+ // its viewBox, unlike the glyphs above. 120 is also what the conversation list asks
176
+ // for (`margin.m15 << 1`), so the two error screens come out identical.
177
+ errorStateStyle: {
178
+ containerStyle: {
179
+ flex: 1,
180
+ alignItems: "center",
181
+ justifyContent: "center",
182
+ paddingHorizontal: spacing.padding.p8,
183
+ },
184
+ titleStyle: {
185
+ ...typography.heading4.bold,
186
+ color: color.textPrimary,
187
+ textAlign: "center",
188
+ },
189
+ subTitleStyle: {
190
+ ...typography.body.regular,
191
+ color: color.textSecondary,
192
+ textAlign: "center",
193
+ },
194
+ iconStyle: {
195
+ height: 120,
196
+ width: 120,
197
+ marginBottom: spacing.margin.m3,
198
+ },
199
+ },
200
+ });
201
+
202
+ /**
203
+ * Dark delegates to light, deliberately.
204
+ *
205
+ * The kit's convention is `dark = deepMerge(light(...), <dark-only overrides>)`, and
206
+ * those overrides exist only where a value CANNOT come from a token — the skeleton
207
+ * gradient literals in CometChatUsers, for instance. Every value here resolves from
208
+ * a semantic token, and `color` is already the dark palette by the time it arrives,
209
+ * so there is nothing left to override. An empty deepMerge would say the same thing
210
+ * with more ceremony.
211
+ */
212
+ export const getPinnedMessagesStyleDark = (
213
+ color: CometChatTheme["color"],
214
+ spacing: CometChatTheme["spacing"],
215
+ typography: CometChatTheme["typography"]
216
+ ): PinnedMessagesStyle => getPinnedMessagesStyleLight(color, spacing, typography);
@@ -23,6 +23,8 @@ export type StyleRange = Readonly<{
23
23
  end: Int32;
24
24
  url?: string;
25
25
  highlightColor?: string;
26
+ /** `#rrggbb` for a `textColor` range. */
27
+ color?: string;
26
28
  }>;
27
29
 
28
30
  export type Block = Readonly<{
@@ -37,6 +39,9 @@ export type Block = Readonly<{
37
39
  type ContentChangeEventData = Readonly<{
38
40
  text: string;
39
41
  blocksJson: string;
42
+ // Mention ranges in clean (ZWS-stripped) coordinates, JSON-encoded. Read back by
43
+ // getMentionRanges() so a consumer formatter can skip mentions.
44
+ mentionRangesJson?: string;
40
45
  }>;
41
46
 
42
47
  type SelectionChangeEventData = Readonly<{
@@ -1,5 +1,5 @@
1
1
  import React, { forwardRef, useImperativeHandle, useRef, useCallback, useState } from 'react';
2
- import { StyleSheet, UIManager, findNodeHandle } from 'react-native';
2
+ import { StyleSheet, UIManager, findNodeHandle, processColor } from 'react-native';
3
3
  import type {
4
4
  Block,
5
5
  TextAlignment,
@@ -7,6 +7,7 @@ import type {
7
7
  SelectionChangeEvent,
8
8
  RichTextEditorProps,
9
9
  RichTextEditorRef,
10
+ InlineStyleKey,
10
11
  } from './types';
11
12
  import RichTextEditorViewNative from './RichTextEditorViewNativeComponent';
12
13
 
@@ -44,6 +45,8 @@ const COMMANDS = {
44
45
  setMentionRanges: 'setMentionRanges',
45
46
  removeLink: 'removeLink',
46
47
  updateLink: 'updateLink',
48
+ applyInlineStyle: 'applyInlineStyle',
49
+ removeInlineStyle: 'removeInlineStyle',
47
50
  } as const;
48
51
 
49
52
  // Helper to dispatch commands to native view
@@ -141,6 +144,9 @@ export interface RichTextEditorPropsExtended extends RichTextEditorProps {
141
144
  const RichTextEditor = forwardRef<RichTextEditorRef, RichTextEditorPropsExtended>((props, ref) => {
142
145
  const nativeRef = useRef<React.ElementRef<typeof RichTextEditorViewNative>>(null);
143
146
  const [height, setHeight] = useState<number | undefined>(undefined);
147
+ // Latest mention ranges reported by native, in plain-text coordinates. Native owns them
148
+ // because editing shifts them; it re-reports on every content change.
149
+ const mentionRangesRef = useRef<Array<{ start: number; end: number }>>([]);
144
150
 
145
151
  const handleSizeChange = useCallback((event: SizeChangeEvent) => {
146
152
  const newHeight = event.nativeEvent?.height;
@@ -253,6 +259,17 @@ const RichTextEditor = forwardRef<RichTextEditorRef, RichTextEditorPropsExtended
253
259
  updateLink: (location: number, length: number, newUrl: string, newText: string) => {
254
260
  dispatchCommand(nativeRef, COMMANDS.updateLink, [location, length, newUrl, newText]);
255
261
  },
262
+ applyInlineStyle: (key: InlineStyleKey, value: string) => {
263
+ // Let RN normalise the colour string (hex / named / rgba) into the packed int
264
+ // both platforms already speak, instead of parsing colours natively.
265
+ const color = processColor(value);
266
+ if (typeof color !== 'number') return;
267
+ dispatchCommand(nativeRef, COMMANDS.applyInlineStyle, [key, color]);
268
+ },
269
+ removeInlineStyle: (key: InlineStyleKey) => {
270
+ dispatchCommand(nativeRef, COMMANDS.removeInlineStyle, [key]);
271
+ },
272
+ getMentionRanges: () => mentionRangesRef.current,
256
273
  }));
257
274
 
258
275
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -271,6 +288,14 @@ const RichTextEditor = forwardRef<RichTextEditorRef, RichTextEditorPropsExtended
271
288
  blocks = [];
272
289
  }
273
290
 
291
+ try {
292
+ mentionRangesRef.current = event.nativeEvent.mentionRangesJson
293
+ ? JSON.parse(event.nativeEvent.mentionRangesJson)
294
+ : [];
295
+ } catch {
296
+ mentionRangesRef.current = [];
297
+ }
298
+
274
299
  // Convert native event to our API format
275
300
  const contentEvent: ContentChangeEvent = {
276
301
  nativeEvent: {
@@ -406,5 +431,6 @@ export type {
406
431
  DeltaType,
407
432
  Selection,
408
433
  TextStyle,
434
+ InlineStyleKey,
409
435
  } from './types';
410
436
  export { dispatchCommand };
@@ -13,11 +13,13 @@ export interface TextStyle {
13
13
  }
14
14
 
15
15
  export interface StyleRange {
16
- style: 'bold' | 'italic' | 'underline' | 'strikethrough' | 'link' | 'code' | 'highlight';
16
+ style: 'bold' | 'italic' | 'underline' | 'strikethrough' | 'link' | 'code' | 'highlight' | 'textColor';
17
17
  start: number;
18
18
  end: number;
19
19
  url?: string;
20
20
  highlightColor?: string;
21
+ /** `#rrggbb` for a `textColor` range — the wire format's only value-carrying style. */
22
+ color?: string;
21
23
  }
22
24
 
23
25
  export type BlockType = 'paragraph' | 'bullet' | 'numbered' | 'heading' | 'quote' | 'checklist';
@@ -126,6 +128,9 @@ export interface RichTextEditorProps {
126
128
  onBlur?: () => void;
127
129
  }
128
130
 
131
+ /** Inline style a consumer formatter can apply to the composer selection. */
132
+ export type InlineStyleKey = 'color' | 'backgroundColor';
133
+
129
134
  export interface RichTextEditorRef {
130
135
  setContent: (blocks: Block[]) => void;
131
136
  getText: () => Promise<string>;
@@ -159,4 +164,17 @@ export interface RichTextEditorRef {
159
164
  setMentionRanges: (ranges: Array<{ start: number; end: number }>) => void;
160
165
  removeLink: (location: number, length: number) => void;
161
166
  updateLink: (location: number, length: number, newUrl: string, newText: string) => void;
167
+ /**
168
+ * Applies an arbitrary inline style to the current selection, skipping mentions.
169
+ * `value` is any React Native colour string (`'#FF0000'`, `'red'`, `'rgba(…)'`).
170
+ * Styles compose — an existing bold/italic on the range is left alone.
171
+ */
172
+ applyInlineStyle: (key: InlineStyleKey, value: string) => void;
173
+ /** Removes a style previously applied with `applyInlineStyle` from the current selection. */
174
+ removeInlineStyle: (key: InlineStyleKey) => void;
175
+ /**
176
+ * Mention ranges in the composer's plain-text coordinates, as of the last content change.
177
+ * Use it to leave mentions untouched when computing ranges to format.
178
+ */
179
+ getMentionRanges: () => Array<{ start: number; end: number }>;
162
180
  }