@cometchat/chat-uikit-react-native 5.2.7 → 5.2.8

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.
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cometchat/chat-uikit-react-native",
3
- "version": "5.2.7",
3
+ "version": "5.2.8",
4
4
  "description": "Ready-to-use Chat UI Components for React Native",
5
5
  "main": "src/index",
6
6
  "module": "src/index",
@@ -19,6 +19,9 @@ import { deepMerge } from "../shared/helper/helperFunctions";
19
19
  import { CommonUtils } from "../shared/utils/CommonUtils";
20
20
  import { DeepPartial } from "../shared/helper/types";
21
21
  import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
22
+ import { ExtensionConstants } from "../extensions";
23
+ import { getExtensionData } from "../shared/helper/functions";
24
+ import { urlPattern } from "../shared/constants/UIKitConstants";
22
25
 
23
26
  /**
24
27
  * Unique UI event identifier for CometChatUIEventHandler.
@@ -234,10 +237,29 @@ export const CometChatThreadHeader = (props: CometChatThreadHeaderInterface): JS
234
237
  };
235
238
  }, []);
236
239
 
240
+ // Check if message has URLs (link preview or URLs in text)
241
+ const hasUrl = useMemo(() => {
242
+ // Check for link preview extension data
243
+ const linkData = getExtensionData(message, ExtensionConstants.linkPreview);
244
+ if (linkData && linkData.links && linkData.links.length > 0) {
245
+ return true;
246
+ }
247
+
248
+ // Check if text message contains URLs
249
+ if (message.getType() === "text") {
250
+ const textMessage = message as CometChat.TextMessage;
251
+ const text = textMessage.getText() || "";
252
+ const urlRegex = new RegExp(urlPattern);
253
+ return urlRegex.test(text);
254
+ }
255
+
256
+ return false;
257
+ }, [message]);
258
+
237
259
  return (
238
260
  <View style={[style?.containerStyle]}>
239
261
  <ScrollView style={style?.messageBubbleContainerStyle}>
240
- <View pointerEvents='none'>
262
+ <View pointerEvents={hasUrl ? 'auto' : 'none'}>
241
263
  {MessageUtils.getMessageView({
242
264
  message,
243
265
  templates:
@@ -1,4 +1,4 @@
1
- import React, { JSX, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
1
+ import React, { JSX, useCallback, useRef, useState } from "react";
2
2
  import {
3
3
  Alert,
4
4
  DimensionValue,
@@ -80,7 +80,6 @@ export const LinkPreviewBubble = (props: LinkPreviewBubbleInterface) => {
80
80
  * Handles the touch end event. If the press duration is less than 500ms, it triggers the onPress callback or opens the link.
81
81
  */
82
82
  const handleTouchEnd = async () => {
83
- if (pressTime.current === null && Platform.OS === "ios") return;
84
83
  const endTime = Date.now();
85
84
  const pressDuration = endTime - (pressTime.current ?? 0);
86
85
  if (pressDuration < 500) {
@@ -138,7 +137,12 @@ export const LinkPreviewBubble = (props: LinkPreviewBubbleInterface) => {
138
137
  );
139
138
 
140
139
  return (
141
- <View style={{ flex: 1 }} onLayout={onLayoutHandler}>
140
+ <View
141
+ onLayout={onLayoutHandler}
142
+ onTouchStart={handleTouchStart}
143
+ onTouchEnd={handleTouchEnd}
144
+ onTouchMove={onTouchMove}
145
+ >
142
146
  <View
143
147
  style={style?.headerImageContainerStyle}
144
148
  onTouchStart={handleTouchStart}
@@ -167,7 +171,7 @@ export const LinkPreviewBubble = (props: LinkPreviewBubbleInterface) => {
167
171
  source={faviconSource}
168
172
  style={style?.bodyStyle?.faviconStyle}
169
173
  onError={(err) => {
170
- setImageSource(DefaultLinkPreview);
174
+ setFaviconSource(DefaultLinkPreview);
171
175
  }}
172
176
  />
173
177
  </View>
@@ -185,6 +189,7 @@ export const LinkPreviewBubble = (props: LinkPreviewBubbleInterface) => {
185
189
  style={{
186
190
  paddingVertical: theme.spacing.padding.p3,
187
191
  paddingHorizontal: style?.bodyStyle?.containerStyle.padding,
192
+ flexShrink: 0,
188
193
  }}
189
194
  >
190
195
  {ChildView && <ChildView />}
@@ -61,7 +61,6 @@ export const emailPattern =
61
61
  wordBoundary.start + `[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}` + wordBoundary.end;
62
62
 
63
63
  export const urlPattern =
64
- wordBoundary.start +
65
64
  `((https?://|www\\.|pic\\.)[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]+[\\w/#](\\(\\))?)` +
66
65
  wordBoundary.end;
67
66
 
@@ -19,6 +19,27 @@ export class CometChatUrlsFormatter extends CometChatTextFormatter {
19
19
  }
20
20
 
21
21
  private Link = ({ text, url, style }: any) => {
22
+ const handlePress = async () => {
23
+ try {
24
+ let finalUrl = url;
25
+ if (!url.match(/^(https?|mailto|tel):/i)) {
26
+ finalUrl = `http://${url}`;
27
+ }
28
+
29
+ const canOpen = await Linking.canOpenURL(finalUrl);
30
+ if (canOpen) {
31
+ Linking.openURL(finalUrl);
32
+ } else {
33
+ // Try opening anyway as fallback
34
+ Linking.openURL(finalUrl).catch((err) => {
35
+ console.log("Can not open link", finalUrl, err);
36
+ });
37
+ }
38
+ } catch (err) {
39
+ console.log("Error opening URL:", err);
40
+ }
41
+ };
42
+
22
43
  return (
23
44
  <Text
24
45
  style={{
@@ -26,20 +47,7 @@ export class CometChatUrlsFormatter extends CometChatTextFormatter {
26
47
  ...style?.linkTextFont,
27
48
  textDecorationLine: "underline",
28
49
  }}
29
- onPress={() => {
30
- let finalUrl = url.startsWith("http") ? url : `http://${url}`;
31
- Linking.canOpenURL(finalUrl)
32
- .then((res) => {
33
- if (res) {
34
- Linking.openURL(finalUrl);
35
- return;
36
- }
37
- console.log("Can not open link", finalUrl);
38
- })
39
- .catch((err) => {
40
- console.log("Error:", err);
41
- });
42
- }}
50
+ onPress={handlePress}
43
51
  >
44
52
  {text}
45
53
  </Text>
@@ -86,7 +94,7 @@ export class CometChatUrlsFormatter extends CometChatTextFormatter {
86
94
  if (phone) urlLink = "tel:";
87
95
  return (
88
96
  <Text>
89
- <Text>{pre} </Text>
97
+ <Text>{pre}</Text>
90
98
  {this.Link({
91
99
  text: resPart[0].trim(),
92
100
  url: urlLink.trim() + resPart[0].trim(),