@cometchat/chat-uikit-react-native 5.4.0 → 5.4.1

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.
@@ -0,0 +1,38 @@
1
+ import { Text, View } from "react-native";
2
+
3
+ /**
4
+ * Identity checks for react-native's `View` / `Text` that survive a wrapped JSX runtime.
5
+ *
6
+ * We ship raw `.tsx`, so the *consumer's* babel compiles our source. A build that
7
+ * substitutes the JSX runtime — NativeWind (`react-native-css-interop`) being the common
8
+ * case — swaps every element's type for an equivalent wrapper (`CssInterop.View`). A bare
9
+ * `element.type === View` then silently returns false, and rich-text bubbles lose their
10
+ * colour and truncation (ENG-38093).
11
+ *
12
+ * The fix is to stop assuming what a `View` element looks like and ask the runtime that is
13
+ * actually in effect. Because these probes are compiled by the same pipeline as the code
14
+ * whose elements we inspect, they resolve to whatever identity that pipeline produces.
15
+ *
16
+ * The probes must be written as JSX. `React.createElement` is deliberately NOT equivalent:
17
+ * css-interop wraps only the JSX runtime and re-exports `createElement` untouched, so
18
+ * building the probe that way would capture the unwrapped identity and defeat the purpose.
19
+ *
20
+ * With no wrapper present these constants are simply `View` / `Text`, so the checks behave
21
+ * exactly as the original strict comparison did — no behaviour change for consumers who
22
+ * don't transform our JSX.
23
+ */
24
+ const RUNTIME_VIEW = (<View />).type;
25
+ const RUNTIME_TEXT = (<Text />).type;
26
+
27
+ /**
28
+ * True when `el` is a react-native `View` element.
29
+ *
30
+ * The `=== View` arm is a fallback for elements built outside our own compilation unit —
31
+ * e.g. a consumer's custom `CometChatTextFormatter` returning a plain `<View>` tree.
32
+ */
33
+ export const isViewElement = (el: any): boolean =>
34
+ el?.type === RUNTIME_VIEW || el?.type === View;
35
+
36
+ /** True when `el` is a react-native `Text` element. Mirrors {@link isViewElement}. */
37
+ export const isTextElement = (el: any): boolean =>
38
+ el?.type === RUNTIME_TEXT || el?.type === Text;
@@ -1,5 +1,6 @@
1
1
  import React, {
2
2
  forwardRef,
3
+ useContext,
3
4
  useEffect,
4
5
  useImperativeHandle,
5
6
  useRef,
@@ -16,6 +17,7 @@ import {
16
17
  Platform,
17
18
  ScrollView,
18
19
  } from "react-native";
20
+ import { SafeAreaInsetsContext } from "react-native-safe-area-context";
19
21
  import { useTheme } from "../../../theme";
20
22
 
21
23
  /**
@@ -93,6 +95,10 @@ const CometChatBottomSheet = forwardRef(
93
95
  // All hooks called unconditionally at top level
94
96
  const overlayAnim = useRef(new Animated.Value(0)).current;
95
97
 
98
+ const safeAreaInsets = useContext(SafeAreaInsetsContext);
99
+ const bottomInset =
100
+ Platform.OS === "android" ? safeAreaInsets?.bottom ?? 0 : 0;
101
+
96
102
  // Fade in/out the overlay when isOpen changes
97
103
  useEffect(() => {
98
104
  if (isOpen) {
@@ -184,7 +190,7 @@ const CometChatBottomSheet = forwardRef(
184
190
  backgroundColor: theme.color.background1,
185
191
  paddingTop: 25,
186
192
  position: "absolute",
187
- bottom: 0,
193
+ bottom: bottomInset,
188
194
  left: 0,
189
195
  right: 0,
190
196
  borderTopLeftRadius: 24,
@@ -199,19 +205,26 @@ const CometChatBottomSheet = forwardRef(
199
205
  ...(doNotOccupyEntireHeight ? {} : { height: "100%" }),
200
206
  }}
201
207
  >
202
- {scrollEnabled ? (
203
- <ScrollView
204
- scrollEnabled={scrollEnabled}
205
- keyboardShouldPersistTaps="always"
206
- style={{ flex: 1 }}
207
- >
208
- {typeof children === "function" ? children() : children}
209
- </ScrollView>
210
- ) : typeof children === "function" ? (
211
- children()
212
- ) : (
213
- children
214
- )}
208
+ <View
209
+ style={{
210
+ ...(doNotOccupyEntireHeight ? {} : { flex: 1 }),
211
+ paddingBottom: style.paddingBottom ?? 0,
212
+ }}
213
+ >
214
+ {scrollEnabled ? (
215
+ <ScrollView
216
+ scrollEnabled={scrollEnabled}
217
+ keyboardShouldPersistTaps="always"
218
+ style={{ flex: 1 }}
219
+ >
220
+ {typeof children === "function" ? children() : children}
221
+ </ScrollView>
222
+ ) : typeof children === "function" ? (
223
+ children()
224
+ ) : (
225
+ children
226
+ )}
227
+ </View>
215
228
  </KeyboardAvoidingView>
216
229
  </Modal>
217
230
  );
@@ -16,6 +16,7 @@ import {
16
16
  CometChatUrlsFormatter,
17
17
  } from "../../formatters";
18
18
  import { useCometChatTranslation } from "../../resources/CometChatLocalizeNew";
19
+ import { isTextElement, isViewElement } from "../../utils/elementType";
19
20
 
20
21
  // Pre-allocated style for view-based content wrapper (blockquotes, lists).
21
22
  const VIEW_BASED_WRAPPER_STYLE = { flexShrink: 1 as const };
@@ -56,12 +57,12 @@ function applyTextStyleDeep(
56
57
  el: React.ReactElement<any>,
57
58
  textStyle: StyleProp<TextStyle> | undefined
58
59
  ): React.ReactElement<any> {
59
- if (el.type === Text) {
60
+ if (isTextElement(el)) {
60
61
  return React.cloneElement(el, {
61
62
  style: [textStyle, el.props?.style],
62
63
  });
63
64
  }
64
- if (el.type === View && el.props.children) {
65
+ if (isViewElement(el) && el.props.children) {
65
66
  const newChildren = React.Children.map(el.props.children, (child) => {
66
67
  if (!React.isValidElement(child)) return child;
67
68
  return applyTextStyleDeep(child as React.ReactElement<any>, textStyle);
@@ -171,7 +172,7 @@ export const CometChatTextBubbleText = (
171
172
  // Check if formattedText is a View-based element (e.g. blockquote with View wrapper).
172
173
  // View elements cannot be nested inside Text, so render them directly.
173
174
  const isViewBased = React.isValidElement(formattedText) &&
174
- (formattedText as React.ReactElement<any>).type === View;
175
+ isViewElement(formattedText);
175
176
 
176
177
  // For View-based content, count children to determine truncatability and slice when collapsed.
177
178
  // This avoids pixel-based clipping that cuts through the middle of list items.
File without changes
File without changes
@@ -1,154 +0,0 @@
1
- # Manual Test Cases — `loadLastAgentConversation`
2
-
3
- ## Prerequisites
4
- - An `@agentic` user configured in your CometChat dashboard
5
- - The example app running with `loadLastAgentConversation={true}` on `CometChatMessageList`
6
- - At least one previous conversation with the agent (send a message, get a response)
7
-
8
- ---
9
-
10
- ## TC-1: Auto-loads last conversation on open
11
-
12
- **Steps:**
13
- 1. Have at least one previous conversation with the agent (send "Hello", wait for reply)
14
- 2. Navigate away from the agent chat (go back to conversation list)
15
- 3. Open the agent chat again
16
-
17
- **Expected:**
18
- - A loading indicator appears briefly
19
- - The previous conversation messages load automatically
20
- - You see your last messages and the agent's responses
21
-
22
- ---
23
-
24
- ## TC-2: Shows greeting/empty state when no previous conversation exists
25
-
26
- **Steps:**
27
- 1. Use a fresh `@agentic` user with no message history (or use a new logged-in user who hasn't chatted with the agent)
28
- 2. Open the agent chat
29
-
30
- **Expected:**
31
- - The agent greeting view appears (avatar, greeting message, suggested messages)
32
- - No loading spinner hangs indefinitely
33
-
34
- ---
35
-
36
- ## TC-3: "New Chat" button from header shows empty state
37
-
38
- **Steps:**
39
- 1. Open the agent chat (previous conversation auto-loads)
40
- 2. Tap the "New Chat" button (pencil/compose icon) in the header
41
-
42
- **Expected:**
43
- - The screen resets to the greeting/empty state
44
- - The previous conversation is NOT re-loaded
45
- - You can type a fresh message to start a new conversation
46
-
47
- ---
48
-
49
- ## TC-4: "New Chat" button from Chat History drawer works
50
-
51
- **Steps:**
52
- 1. Open the agent chat
53
- 2. Tap the "Chat History" button in the header to open the history drawer
54
- 3. Tap the "New Chat" button inside the history drawer
55
-
56
- **Expected:**
57
- - The history drawer closes
58
- - The message list resets to greeting/empty state
59
- - The previous conversation is NOT re-loaded
60
-
61
- ---
62
-
63
- ## TC-5: Loading a specific conversation from Chat History still works
64
-
65
- **Steps:**
66
- 1. Open the agent chat (previous conversation auto-loads)
67
- 2. Tap the "Chat History" button in the header
68
- 3. Tap on a specific past conversation from the list
69
-
70
- **Expected:**
71
- - The selected conversation loads with all its messages
72
- - Streaming/responses still work if you send a new message in that thread
73
-
74
- ---
75
-
76
- ## TC-6: Sending a new message after "New Chat" starts a new thread
77
-
78
- **Steps:**
79
- 1. Open the agent chat (previous conversation auto-loads)
80
- 2. Tap "New Chat" (message list resets to empty)
81
- 3. Type and send a message (e.g., "What's the weather?")
82
-
83
- **Expected:**
84
- - Your message appears in the list
85
- - A streaming indicator shows while the agent responds
86
- - The agent's reply appears correctly
87
- - This is now a NEW conversation thread (not appended to the old one)
88
-
89
- ---
90
-
91
- ## TC-7: Re-opening after new chat shows the NEW conversation
92
-
93
- **Steps:**
94
- 1. Complete TC-6 (start a new chat, send message, get reply)
95
- 2. Navigate away from the agent chat
96
- 3. Open the agent chat again
97
-
98
- **Expected:**
99
- - The most recent conversation (from step 1-2) auto-loads
100
- - You see the "What's the weather?" message and the agent's response
101
- - NOT the older conversation from before
102
-
103
- ---
104
-
105
- ## TC-8: `loadLastAgentConversation={false}` preserves existing behavior
106
-
107
- **Steps:**
108
- 1. Change the prop to `loadLastAgentConversation={false}` (or remove it) in Messages.tsx
109
- 2. Open the agent chat (even with previous conversations)
110
-
111
- **Expected:**
112
- - The greeting/empty state shows immediately
113
- - No automatic loading of previous conversation
114
- - Behaves exactly as before this feature was added
115
-
116
- ---
117
-
118
- ## TC-9: Non-agentic users are unaffected
119
-
120
- **Steps:**
121
- 1. With `loadLastAgentConversation={true}` still set
122
- 2. Open a regular (non-agentic) user chat that has message history
123
-
124
- **Expected:**
125
- - Messages load normally (standard behavior)
126
- - No change in behavior — the prop only applies to `@agentic` users
127
-
128
- ---
129
-
130
- ## TC-10: Scroll up to load older messages in auto-loaded conversation
131
-
132
- **Steps:**
133
- 1. Have a long conversation history with the agent (30+ messages)
134
- 2. Open the agent chat (auto-loads last conversation)
135
- 3. Scroll up to the top of the loaded messages
136
-
137
- **Expected:**
138
- - Older messages load (pagination works)
139
- - No crash or infinite spinner
140
- - The loading indicator appears at the top while fetching
141
-
142
- ---
143
-
144
- ## TC-11: Delete all history from Chat History panel
145
-
146
- **Steps:**
147
- 1. Open the agent chat
148
- 2. Open Chat History drawer
149
- 3. Long-press and delete all conversations one by one until none remain
150
-
151
- **Expected:**
152
- - When the last conversation is deleted, the list shows empty state
153
- - The message list resets to greeting/empty view
154
- - Re-opening the chat shows greeting (no conversation to auto-load)