@cometchat/chat-uikit-react-native 5.5.0 → 5.5.2
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/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/build.gradle +23 -89
- package/android/gradle.properties +5 -5
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatSoundModule.java +5 -1
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +52 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +37 -4
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +9 -1
- package/ios/FileManager.m +77 -3
- package/ios/RichTextEditorView.swift +52 -1
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/RichTextEditorViewManager.swift +8 -0
- package/package.json +8 -5
- package/react-native-cometchat-ui-kit.podspec +5 -19
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +69 -36
- package/src/CometChatConversations/CometChatConversations.tsx +12 -1
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +2 -2
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +50 -31
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +10 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +24 -19
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +7 -8
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +43 -19
- package/src/CometChatRichTextEditor/index.tsx +6 -1
- package/src/CometChatRichTextEditor/types.ts +2 -0
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +251 -14
- package/src/CometChatSearch/CometChatSearch.tsx +39 -11
- package/src/calls/CometChatOngoingCall/CometChatOngoingCall.tsx +56 -17
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +12 -9
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +13 -10
- package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +34 -27
- package/src/extensions/Polls/Polls.tsx +7 -7
- package/src/extensions/Polls/PollsBubble.tsx +2 -2
- package/src/globals.d.ts +6 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +2 -1
- package/src/shared/constants/UIKitConstants.ts +3 -17
- package/src/shared/constants/textPatterns.ts +45 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +25 -259
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +22 -11
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +56 -32
- package/src/shared/formatters/CometChatTextFormatter.ts +22 -0
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +8 -0
- package/src/shared/formatters/applyRawFormatters.ts +31 -0
- package/src/shared/formatters/codeElements.ts +21 -0
- package/src/shared/framework/MessageDataSource.tsx +14 -8
- package/src/shared/helper/types/index.ts +5 -0
- package/src/shared/libs/ImageZoom/ReactNativeZoomableView.tsx +4 -4
- package/src/shared/libs/ImageZoom/types/index.ts +2 -0
- package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +15 -30
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +138 -19
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +0 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +54 -1
- package/src/shared/resources/CometChatSoundManager/sound.js +2 -3
- package/src/shared/services/UploadQueueService.ts +7 -0
- package/src/shared/utils/CometChatMessageHelper/index.ts +3 -0
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +11 -0
- package/src/shared/utils/MarkdownUtils.ts +42 -5
- package/src/shared/utils/MessageUtils.tsx +7 -5
- package/src/shared/utils/PinnedMessagesHelper.ts +65 -0
- package/src/shared/utils/SavedMessagesHelper.ts +42 -6
- package/src/shared/utils/__testUtils__/messagesRequestBuilderMock.ts +37 -0
- package/src/shared/utils/cloneRequestBuilder.ts +25 -0
- package/src/shared/utils/groupMemberAddedRows.ts +28 -0
- package/src/shared/utils/linkPreviewSelection.ts +109 -0
- package/src/shared/utils/mentionTokens.ts +77 -0
- package/src/shared/utils/runAfterInteractions.ts +26 -0
- package/src/shared/utils/stripRichText.ts +2 -1
- package/src/shared/utils/tapGesture.ts +23 -0
- package/src/shared/utils/videoThumbnail.ts +74 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +15 -4
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +21 -13
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +13 -15
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +5 -0
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +4 -1
- package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +8 -1
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +1 -1
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +2 -1
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +7 -1
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +8 -26
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +4 -2
- package/src/shared/views/CometChatList/Header.tsx +9 -3
- package/src/shared/views/CometChatMediaRecorder/CometChatAudioPreview/CometChatAudioPreview.tsx +2 -1
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +28 -8
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -4
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +36 -4
- package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +2 -1
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +62 -30
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +5 -0
- package/src/CometChatMessageList/MANUAL_TEST_CASES.md +0 -154
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useReducer, useRef, useState, useMemo, JSX } from 'react';
|
|
2
|
-
import { View, TextInput, TouchableOpacity, Text, Image, ImageBackground, FlatList, ImageSourcePropType, StyleSheet } from 'react-native';
|
|
2
|
+
import { View, TextInput, TouchableOpacity, Text, Image, ImageBackground, FlatList, ImageSourcePropType, StyleSheet, Platform } from 'react-native';
|
|
3
3
|
import { CometChat } from '@cometchat/chat-sdk-react-native';
|
|
4
4
|
import {
|
|
5
5
|
CometChatAvatar,
|
|
@@ -18,8 +18,12 @@ import { deepMerge } from '../shared/helper/helperFunctions';
|
|
|
18
18
|
import { DeepPartial } from '../shared/helper/types';
|
|
19
19
|
import { getCometChatTranslation } from '../shared/resources/CometChatLocalizeNew/LocalizationManager';
|
|
20
20
|
import { CommonUtils } from '../shared/utils/CommonUtils';
|
|
21
|
+
import { selectLinkPreview } from "../shared/utils/linkPreviewSelection";
|
|
22
|
+
import { unescapeTypedMentionTokens } from "../shared/utils/mentionTokens";
|
|
21
23
|
import { stripMarkdown } from '../shared/utils/MarkdownUtils';
|
|
22
24
|
import { CometChatRichTextFormatter } from '../shared/formatters/CometChatRichTextFormatter';
|
|
25
|
+
import { CometChatTextFormatter } from '../shared/formatters/CometChatTextFormatter';
|
|
26
|
+
import { applyRawFormatters } from '../shared/formatters/applyRawFormatters';
|
|
23
27
|
import { ExtensionConstants } from '../extensions/ExtensionConstants';
|
|
24
28
|
import { getExtensionData } from '../extensions/ExtensionModerator';
|
|
25
29
|
|
|
@@ -34,10 +38,16 @@ const searchRichTextFormatter = new CometChatRichTextFormatter();
|
|
|
34
38
|
* so only colour runs remain — the result is always inline `<Text>`, never a block-level `View`.
|
|
35
39
|
* Returns a JSX element when the text carries colour, a plain string otherwise.
|
|
36
40
|
*/
|
|
37
|
-
const formatPreviewText = (
|
|
41
|
+
const formatPreviewText = (
|
|
42
|
+
rawText: any,
|
|
43
|
+
message?: CometChat.BaseMessage,
|
|
44
|
+
textFormatters?: Array<CometChatTextFormatter>
|
|
45
|
+
): string | JSX.Element => {
|
|
38
46
|
if (typeof rawText !== 'string') return rawText;
|
|
39
47
|
|
|
40
|
-
|
|
48
|
+
// A consumer's own wire token becomes UI Kit markup first; `stripMarkdown` below removes
|
|
49
|
+
// anything it does not recognise, so nothing left until later would survive.
|
|
50
|
+
let text = stripMarkdown(applyRawFormatters(rawText, textFormatters), true).replace(/<@all:(.*?)>/g, '@$1');
|
|
41
51
|
|
|
42
52
|
try {
|
|
43
53
|
const mentionedUsers: CometChat.User[] = (message && (message).getMentionedUsers && (message).getMentionedUsers()) || [];
|
|
@@ -54,6 +64,9 @@ const formatPreviewText = (rawText: any, message?: CometChat.BaseMessage): strin
|
|
|
54
64
|
console.log(e)
|
|
55
65
|
}
|
|
56
66
|
|
|
67
|
+
// Tokens are resolved above; typed token text (stored escaped) now reads as typed.
|
|
68
|
+
text = unescapeTypedMentionTokens(text);
|
|
69
|
+
|
|
57
70
|
return searchRichTextFormatter.getFormattedText(text) ?? text;
|
|
58
71
|
};
|
|
59
72
|
|
|
@@ -328,6 +341,15 @@ interface CometChatSearchProps {
|
|
|
328
341
|
*/
|
|
329
342
|
conversationItemView?: (conversation: CometChat.Conversation, searchKeyword?: string) => React.ReactElement;
|
|
330
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Text formatters, the same instances passed to the message list and the composer.
|
|
346
|
+
*
|
|
347
|
+
* A search row renders the message's own text, so a consumer's wire token has to be rewritten
|
|
348
|
+
* here too — otherwise a message reads coloured in the chat and raw in the search results.
|
|
349
|
+
* Only `formatRawText` is used: rows are flattened to a single line.
|
|
350
|
+
*/
|
|
351
|
+
textFormatters?: Array<CometChatTextFormatter>;
|
|
352
|
+
|
|
331
353
|
/**
|
|
332
354
|
* Custom view component for text message items
|
|
333
355
|
* @param message - The text message object to render
|
|
@@ -606,10 +628,11 @@ interface ConversationItemProps {
|
|
|
606
628
|
mergedStyles: any;
|
|
607
629
|
theme: any;
|
|
608
630
|
conversationItemView?: (conversation: CometChat.Conversation, searchKeyword?: string) => React.ReactElement;
|
|
631
|
+
textFormatters?: Array<CometChatTextFormatter>;
|
|
609
632
|
}
|
|
610
633
|
|
|
611
634
|
const ConversationItem = React.memo<ConversationItemProps>((
|
|
612
|
-
{ conversation, searchText, onPress, mergedStyles, theme, conversationItemView }
|
|
635
|
+
{ conversation, searchText, onPress, mergedStyles, theme, conversationItemView, textFormatters }
|
|
613
636
|
) => {
|
|
614
637
|
const getStatusIndicator = () => {
|
|
615
638
|
const withObj = conversation.getConversationWith();
|
|
@@ -684,7 +707,7 @@ const ConversationItem = React.memo<ConversationItemProps>((
|
|
|
684
707
|
{conversation.getConversationWith().getName()}
|
|
685
708
|
</Text>
|
|
686
709
|
<Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
|
|
687
|
-
{formatPreviewText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
|
|
710
|
+
{formatPreviewText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage(), textFormatters)}
|
|
688
711
|
</Text>
|
|
689
712
|
</View>
|
|
690
713
|
{renderTrailingView()}
|
|
@@ -728,6 +751,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
728
751
|
emptyView,
|
|
729
752
|
errorView,
|
|
730
753
|
conversationItemView,
|
|
754
|
+
textFormatters,
|
|
731
755
|
textMessageItemView,
|
|
732
756
|
imageMessageItemView,
|
|
733
757
|
audioMessageItemView,
|
|
@@ -742,7 +766,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
742
766
|
const theme = useTheme();
|
|
743
767
|
const errorHandler = useCometChatErrorHandler(onError);
|
|
744
768
|
const timeoutIdRef = useRef<any | null>(null);
|
|
745
|
-
const searchInputRef = useRef<TextInput
|
|
769
|
+
const searchInputRef = useRef<React.ComponentRef<typeof TextInput>>(null);
|
|
746
770
|
|
|
747
771
|
// Merge theme styles with provided style overrides
|
|
748
772
|
const mergedStyles = useMemo(() => {
|
|
@@ -1468,7 +1492,10 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1468
1492
|
// The caption carries wire markup since ENG-38258, and it is concatenated with the count
|
|
1469
1493
|
// label below — so it is flattened here, exactly as the conversation row flattens it.
|
|
1470
1494
|
const caption = stripMarkdown(
|
|
1471
|
-
(
|
|
1495
|
+
applyRawFormatters(
|
|
1496
|
+
(typeof (message as any).getCaption === "function" ? (message as any).getCaption() : "") || "",
|
|
1497
|
+
textFormatters
|
|
1498
|
+
)
|
|
1472
1499
|
);
|
|
1473
1500
|
const firstName =
|
|
1474
1501
|
atts[0]?.getName?.() || (message.getAttachment?.() as any)?.getName?.() || "";
|
|
@@ -1517,7 +1544,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1517
1544
|
return getMediaSearchSubtitle(message as CometChat.MediaMessage);
|
|
1518
1545
|
}
|
|
1519
1546
|
if (messageType === "text") {
|
|
1520
|
-
return formatPreviewText((message as CometChat.TextMessage).getText?.() ?? "", message)
|
|
1547
|
+
return formatPreviewText((message as CometChat.TextMessage).getText?.() ?? "", message, textFormatters)
|
|
1521
1548
|
|| messageType || "Message";
|
|
1522
1549
|
}
|
|
1523
1550
|
if (message.getCategory() === MessageCategoryConstants.card) {
|
|
@@ -1624,8 +1651,8 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1624
1651
|
const metadata = textMessage.getMetadata();
|
|
1625
1652
|
const linkPreview = metadata && (metadata as any)['@injected'] && (metadata as any)['@injected']['extensions'] && (metadata as any)['@injected']['extensions']['link-preview'];
|
|
1626
1653
|
|
|
1627
|
-
|
|
1628
|
-
|
|
1654
|
+
const firstLink = selectLinkPreview(linkPreview?.links, textMessage.getText());
|
|
1655
|
+
if (firstLink) {
|
|
1629
1656
|
const thumbnailUrl = firstLink.image || firstLink.favicon;
|
|
1630
1657
|
|
|
1631
1658
|
if (thumbnailUrl) {
|
|
@@ -1865,6 +1892,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1865
1892
|
mergedStyles={mergedStyles}
|
|
1866
1893
|
theme={theme}
|
|
1867
1894
|
conversationItemView={conversationItemView}
|
|
1895
|
+
textFormatters={textFormatters}
|
|
1868
1896
|
/>
|
|
1869
1897
|
);
|
|
1870
1898
|
|
|
@@ -1988,7 +2016,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1988
2016
|
initialNumToRender={10}
|
|
1989
2017
|
maxToRenderPerBatch={10}
|
|
1990
2018
|
windowSize={10}
|
|
1991
|
-
removeClippedSubviews={
|
|
2019
|
+
removeClippedSubviews={Platform.OS !== 'android'} // ENG-40210: clipping crashes Fabric on Android
|
|
1992
2020
|
updateCellsBatchingPeriod={100}
|
|
1993
2021
|
onEndReached={() => {
|
|
1994
2022
|
// Load more messages if we're at the end and messages section is visible
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
2
2
|
import React, { useEffect, useRef, useState } from "react";
|
|
3
|
-
import { ActivityIndicator, View } from "react-native";
|
|
3
|
+
import { ActivityIndicator, LayoutChangeEvent, View } from "react-native";
|
|
4
|
+
import { SafeAreaView } from "react-native-safe-area-context";
|
|
4
5
|
import { CallingPackage } from "../CallingPackage";
|
|
5
6
|
import { useTheme } from "../../theme";
|
|
6
7
|
import { JSX } from "react";
|
|
@@ -9,6 +10,9 @@ const { Proximity } = NativeModules;
|
|
|
9
10
|
|
|
10
11
|
const CometChatCalls = CallingPackage.CometChatCalls;
|
|
11
12
|
|
|
13
|
+
/** How long the call area must keep the same size before the Calls SDK is mounted into it. */
|
|
14
|
+
const CALL_AREA_SETTLE_MS = 150;
|
|
15
|
+
|
|
12
16
|
/**
|
|
13
17
|
* Props for the CometChatOngoingCall component.
|
|
14
18
|
*
|
|
@@ -88,22 +92,57 @@ export const CometChatOngoingCall = (props: CometChatOngoingCallInterface): JSX.
|
|
|
88
92
|
};
|
|
89
93
|
}, [callToken]);
|
|
90
94
|
|
|
95
|
+
// Size of the area the Calls SDK draws into, once it has stopped changing.
|
|
96
|
+
const [callArea, setCallArea] = useState<{ width: number; height: number } | null>(null);
|
|
97
|
+
const settleTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
98
|
+
|
|
99
|
+
useEffect(() => () => clearTimeout(settleTimer.current), []);
|
|
100
|
+
|
|
101
|
+
// The Calls SDK saves the size of its FIRST layout in a module-level variable and reuses it
|
|
102
|
+
// for every later call in the app session. Mount it only after this area has settled — the
|
|
103
|
+
// SafeAreaView below applies its padding a frame after the first layout — and hand it a box
|
|
104
|
+
// of exactly that size, so the size it saves is the real one.
|
|
105
|
+
const onCallAreaLayout = (e: LayoutChangeEvent) => {
|
|
106
|
+
const { width, height } = e.nativeEvent.layout;
|
|
107
|
+
clearTimeout(settleTimer.current);
|
|
108
|
+
settleTimer.current = setTimeout(() => {
|
|
109
|
+
setCallArea((prev) =>
|
|
110
|
+
prev && prev.width === width && prev.height === height ? prev : { width, height }
|
|
111
|
+
);
|
|
112
|
+
}, CALL_AREA_SETTLE_MS);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// Keep the call inside the safe area: on RN 0.87 Android is edge-to-edge, and a full-screen
|
|
116
|
+
// parent (the accepted CometChatIncomingCall, or the Modal of CometChatOutgoingCall) reaches
|
|
117
|
+
// under the system bars. The native SafeAreaView pads only for the insets it overlaps.
|
|
91
118
|
return (
|
|
92
|
-
<
|
|
93
|
-
{
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
119
|
+
<SafeAreaView
|
|
120
|
+
edges={["top", "bottom"]}
|
|
121
|
+
style={{
|
|
122
|
+
height: "100%",
|
|
123
|
+
width: "100%",
|
|
124
|
+
position: "relative",
|
|
125
|
+
backgroundColor: theme.color.background1,
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
<View style={{ flex: 1 }} onLayout={onCallAreaLayout}>
|
|
129
|
+
{(callSettings.current && callToken && callArea && (
|
|
130
|
+
<View style={{ width: callArea.width, height: callArea.height }}>
|
|
131
|
+
<CometChatCalls.Component callSettings={callSettings.current} callToken={callToken} />
|
|
132
|
+
</View>
|
|
133
|
+
)) || (
|
|
134
|
+
<View
|
|
135
|
+
style={{
|
|
136
|
+
justifyContent: "center",
|
|
137
|
+
alignItems: "center",
|
|
138
|
+
height: "100%",
|
|
139
|
+
backgroundColor: "transparent",
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
<ActivityIndicator size={"large"} color={theme.color.primary} />
|
|
143
|
+
</View>
|
|
144
|
+
)}
|
|
145
|
+
</View>
|
|
146
|
+
</SafeAreaView>
|
|
108
147
|
);
|
|
109
148
|
};
|
|
@@ -281,13 +281,16 @@ export const CometChatOutgoingCall = (props: CometChatOutgoingCallInterface): JS
|
|
|
281
281
|
visible={isModalVisible}
|
|
282
282
|
onRequestClose={handleModalClose}
|
|
283
283
|
>
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
284
|
+
{/* The connected call handles its own safe area. Rendered outside the SafeAreaView below
|
|
285
|
+
so it gets the same geometry as an accepted incoming call: the Calls SDK keeps the size
|
|
286
|
+
of the first call in the session, so both directions must lay out the same way. */}
|
|
287
|
+
{isCallConnected ? (
|
|
288
|
+
<CometChatOngoingCall
|
|
289
|
+
sessionID={callSessionId.current!}
|
|
290
|
+
callSettingsBuilder={callSettings.current!}
|
|
291
|
+
/>
|
|
292
|
+
) : (
|
|
293
|
+
<SafeAreaView style={{ flex: 1 }}>
|
|
291
294
|
<View style={outgoingCallStyle.containerStyle}>
|
|
292
295
|
{TitleView ? (
|
|
293
296
|
TitleView(call)
|
|
@@ -331,8 +334,8 @@ export const CometChatOutgoingCall = (props: CometChatOutgoingCallInterface): JS
|
|
|
331
334
|
</TouchableOpacity>
|
|
332
335
|
)}
|
|
333
336
|
</View>
|
|
334
|
-
|
|
335
|
-
|
|
337
|
+
</SafeAreaView>
|
|
338
|
+
)}
|
|
336
339
|
</Modal>
|
|
337
340
|
);
|
|
338
341
|
};
|
|
@@ -109,7 +109,7 @@ export const LinkPreviewBubble = (props: LinkPreviewBubbleInterface) => {
|
|
|
109
109
|
if (onPress) {
|
|
110
110
|
onPress();
|
|
111
111
|
} else {
|
|
112
|
-
const opened = await Linking.openURL(link);
|
|
112
|
+
const opened: unknown = await Linking.openURL(link);
|
|
113
113
|
if (!opened) {
|
|
114
114
|
Alert.alert(t("SOMETHING_WRONG"));
|
|
115
115
|
}
|
|
@@ -212,15 +212,18 @@ export const LinkPreviewBubble = (props: LinkPreviewBubbleInterface) => {
|
|
|
212
212
|
</Text>
|
|
213
213
|
</View>
|
|
214
214
|
</View>
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
215
|
+
{/* Only the card that carries the message text gets this padded row; the others would show an empty band. */}
|
|
216
|
+
{ChildView && (
|
|
217
|
+
<View
|
|
218
|
+
style={{
|
|
219
|
+
paddingVertical: theme.spacing.padding.p3,
|
|
220
|
+
paddingHorizontal: style?.bodyStyle?.containerStyle.padding,
|
|
221
|
+
flexShrink: 0,
|
|
222
|
+
}}
|
|
223
|
+
>
|
|
224
|
+
<ChildView />
|
|
225
|
+
</View>
|
|
226
|
+
)}
|
|
224
227
|
</View>
|
|
225
228
|
);
|
|
226
229
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
2
2
|
import React, { JSX } from "react";
|
|
3
|
+
import { View } from "react-native";
|
|
3
4
|
import { AdditionalParams, MessageBubbleAlignmentType } from "../../shared/base/Types";
|
|
4
5
|
import { DataSource, DataSourceDecorator } from "../../shared/framework";
|
|
5
6
|
import { BubbleStyles, CometChatTheme } from "../../theme/type";
|
|
@@ -8,6 +9,7 @@ import { getExtensionData } from "../ExtensionModerator";
|
|
|
8
9
|
import { LinkPreviewBubble } from "./LinkPreviewBubble";
|
|
9
10
|
import { CometChatUIKit } from "../../shared";
|
|
10
11
|
import { DeepPartial } from "../../shared/helper/types";
|
|
12
|
+
import { previewImage, selectLinkPreviews, trimStrayParens } from "../../shared/utils/linkPreviewSelection";
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Extension decorator for rendering link preview messages.
|
|
@@ -60,35 +62,40 @@ export class LinkPreviewExtensionDecorator extends DataSourceDecorator {
|
|
|
60
62
|
): JSX.Element {
|
|
61
63
|
const loggedInUser = CometChatUIKit.loggedInUser;
|
|
62
64
|
const linkData = getExtensionData(message, ExtensionConstants.linkPreview);
|
|
65
|
+
// One card per link the text goes TO (not every address the server scanned) — like React UI Kit.
|
|
66
|
+
const previews = selectLinkPreviews(linkData?.links, message.getText());
|
|
63
67
|
|
|
64
|
-
if (
|
|
68
|
+
if (previews.length === 0) {
|
|
65
69
|
return super.getTextMessageContentView(message, alignment, theme, additionalParams);
|
|
66
|
-
} else {
|
|
67
|
-
const _style: DeepPartial<BubbleStyles["linkPreviewBubbleStyles"]> =
|
|
68
|
-
message.getSender()?.getUid() === loggedInUser?.getUid()
|
|
69
|
-
? theme.messageListStyles?.outgoingMessageBubbleStyles?.linkPreviewBubbleStyles
|
|
70
|
-
: theme.messageListStyles?.incomingMessageBubbleStyles?.linkPreviewBubbleStyles;
|
|
71
|
-
const { image, favicon, title, url, description } = linkData.links[0];
|
|
72
|
-
const img = image.length === 0 || image === favicon ? "" : image;
|
|
73
|
-
return (
|
|
74
|
-
<LinkPreviewBubble
|
|
75
|
-
link={url}
|
|
76
|
-
description={description}
|
|
77
|
-
image={img}
|
|
78
|
-
favicon={favicon}
|
|
79
|
-
ChildView={() =>
|
|
80
|
-
super.getTextMessageBubble(
|
|
81
|
-
(message as CometChat.TextMessage).getText(),
|
|
82
|
-
message as CometChat.TextMessage,
|
|
83
|
-
alignment,
|
|
84
|
-
theme,
|
|
85
|
-
additionalParams
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
title={title}
|
|
89
|
-
style={_style as CometChatTheme["linkPreviewBubbleStyles"]}
|
|
90
|
-
/>
|
|
91
|
-
);
|
|
92
70
|
}
|
|
71
|
+
const _style: DeepPartial<BubbleStyles["linkPreviewBubbleStyles"]> =
|
|
72
|
+
message.getSender()?.getUid() === loggedInUser?.getUid()
|
|
73
|
+
? theme.messageListStyles?.outgoingMessageBubbleStyles?.linkPreviewBubbleStyles
|
|
74
|
+
: theme.messageListStyles?.incomingMessageBubbleStyles?.linkPreviewBubbleStyles;
|
|
75
|
+
const textView = () =>
|
|
76
|
+
super.getTextMessageBubble(
|
|
77
|
+
(message as CometChat.TextMessage).getText(),
|
|
78
|
+
message as CometChat.TextMessage,
|
|
79
|
+
alignment,
|
|
80
|
+
theme,
|
|
81
|
+
additionalParams
|
|
82
|
+
);
|
|
83
|
+
// Cards stack in link order with a small gap; the message text sits under the last one.
|
|
84
|
+
return (
|
|
85
|
+
<View style={{ gap: theme.spacing.padding.p2 }}>
|
|
86
|
+
{previews.map(({ image, favicon, title, url, description }, i) => (
|
|
87
|
+
<LinkPreviewBubble
|
|
88
|
+
key={`${i}-${url}`}
|
|
89
|
+
link={trimStrayParens(url)}
|
|
90
|
+
description={description}
|
|
91
|
+
image={previewImage(image, favicon)}
|
|
92
|
+
favicon={favicon}
|
|
93
|
+
ChildView={i === previews.length - 1 ? textView : undefined}
|
|
94
|
+
title={title}
|
|
95
|
+
style={_style as CometChatTheme["linkPreviewBubbleStyles"]}
|
|
96
|
+
/>
|
|
97
|
+
))}
|
|
98
|
+
</View>
|
|
99
|
+
);
|
|
93
100
|
}
|
|
94
101
|
}
|
|
@@ -2,7 +2,6 @@ import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
|
2
2
|
import {
|
|
3
3
|
ActivityIndicator,
|
|
4
4
|
FlatList,
|
|
5
|
-
InteractionManager,
|
|
6
5
|
Keyboard,
|
|
7
6
|
KeyboardAvoidingView,
|
|
8
7
|
NativeModules,
|
|
@@ -21,6 +20,7 @@ import { useCometChatTranslation } from "../../shared/resources/CometChatLocaliz
|
|
|
21
20
|
import { SafeAreaView, useSafeAreaInsets } from "react-native-safe-area-context";
|
|
22
21
|
import { CometChatMessageEvents } from "../../shared/events/CometChatMessageEvents";
|
|
23
22
|
import { messageStatus } from "../../shared/utils/CometChatMessageHelper";
|
|
23
|
+
import { runAfterInteractions } from "../../shared/utils/runAfterInteractions";
|
|
24
24
|
|
|
25
25
|
const { CommonUtil } = NativeModules;
|
|
26
26
|
|
|
@@ -147,7 +147,7 @@ export const CometChatCreatePoll = (props: CometChatCreatePollInterface) => {
|
|
|
147
147
|
const loggedInUser = useRef<CometChat.User | null>(null);
|
|
148
148
|
const theme = useTheme();
|
|
149
149
|
const { t } = useCometChatTranslation();
|
|
150
|
-
const answerRefs = useRef<(TextInput | null)[]>([]);
|
|
150
|
+
const answerRefs = useRef<(React.ComponentRef<typeof TextInput> | null)[]>([]);
|
|
151
151
|
const [lastRemovedIndex, setLastRemovedIndex] = useState<number | null>(null);
|
|
152
152
|
const [newlyAddedIndex, setNewlyAddedIndex] = useState<number | null>(null);
|
|
153
153
|
const flatListRef = useRef<FlatList>(null);
|
|
@@ -425,7 +425,7 @@ export const CometChatCreatePoll = (props: CometChatCreatePollInterface) => {
|
|
|
425
425
|
|
|
426
426
|
useEffect(() => {
|
|
427
427
|
if (answers.length) {
|
|
428
|
-
|
|
428
|
+
runAfterInteractions(() => {
|
|
429
429
|
flatListRef.current?.scrollToEnd({ animated: true });
|
|
430
430
|
});
|
|
431
431
|
}
|
|
@@ -588,10 +588,10 @@ export const CometChatCreatePoll = (props: CometChatCreatePollInterface) => {
|
|
|
588
588
|
style={{
|
|
589
589
|
paddingHorizontal: 20,
|
|
590
590
|
backgroundColor: theme.color.background1,
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
591
|
+
// Both platforms: an edge-to-edge Android window (RN 0.86+ Modals, targetSdk 35+)
|
|
592
|
+
// draws under the navigation bar, so the fixed 10 left Create hidden behind it.
|
|
593
|
+
// Non-edge-to-edge Android reports a 0 inset, so this stays 10 there.
|
|
594
|
+
paddingBottom: Math.max(insets.bottom, 10),
|
|
595
595
|
}}
|
|
596
596
|
>
|
|
597
597
|
{error && <ErrorView />}
|
|
@@ -227,10 +227,10 @@ export const PollsBubble = (props: PollsBubbleInterface) => {
|
|
|
227
227
|
const secondavatarStyle = voteravatarStyle;
|
|
228
228
|
const thirdavatarStyle = voteravatarStyle;
|
|
229
229
|
if (secondavatarStyle && secondavatarStyle.containerStyle) {
|
|
230
|
-
secondavatarStyle.containerStyle
|
|
230
|
+
Object.assign(secondavatarStyle.containerStyle, { marginLeft: -10 });
|
|
231
231
|
}
|
|
232
232
|
if (thirdavatarStyle && thirdavatarStyle.containerStyle) {
|
|
233
|
-
thirdavatarStyle.containerStyle
|
|
233
|
+
Object.assign(thirdavatarStyle.containerStyle, { marginLeft: -10 });
|
|
234
234
|
}
|
|
235
235
|
// Ensure value is a string for rendering
|
|
236
236
|
let optionText = typeof value === 'string' ? value : (value && value.value ? value.value : String(value));
|
package/src/globals.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `__DEV__` is injected by the React Native runtime. React Native's own typings declare it,
|
|
3
|
+
* but only when `react-native` resolves to its generated typings; declare it here so the
|
|
4
|
+
* package's own type-check does not depend on how `react-native` gets resolved.
|
|
5
|
+
*/
|
|
6
|
+
declare const __DEV__: boolean;
|
|
@@ -52,23 +52,9 @@ export const PASSWORD_GROUP_COLOR = "rgb(247, 165, 0)";
|
|
|
52
52
|
export const IMAGE_PREFETCH_MAX_ATTEMPTS = 5;
|
|
53
53
|
export const IMAGE_PREFETCH_TIMEOUT = 800;
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const emailPattern =
|
|
61
|
-
wordBoundary.start + `[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}` + wordBoundary.end;
|
|
62
|
-
|
|
63
|
-
export const urlPattern =
|
|
64
|
-
`((https?://|ftp://|www\\.|pic\\.)[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]+[\\w/#](\\(\\))?` +
|
|
65
|
-
`|[a-zA-Z][a-zA-Z0-9]*[-a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\\.[a-zA-Z]{2,}(?:[:/][-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]*[\\w/#](\\(\\))?)?)` +
|
|
66
|
-
wordBoundary.end;
|
|
67
|
-
|
|
68
|
-
export const phoneNumPattern =
|
|
69
|
-
wordBoundary.start +
|
|
70
|
-
`(?:\\+?(\\d{1,3}))?([-. (]*(\\d{3})[-. )]*)?((\\d{3})[-. ]*(\\d{2,4})(?:[-.x ]*(\\d+))?)` +
|
|
71
|
-
wordBoundary.end;
|
|
55
|
+
// Moved to their own import-free module so a leaf like MarkdownUtils can use `urlPattern`
|
|
56
|
+
// without dragging the Chat SDK in through this file. Re-exported so callers are unaffected.
|
|
57
|
+
export { emailPattern, urlPattern, phoneNumPattern } from "./textPatterns";
|
|
72
58
|
|
|
73
59
|
export const MetadataConstants = {
|
|
74
60
|
file: "file",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The link/email/phone patterns, kept in their OWN module with no imports.
|
|
3
|
+
*
|
|
4
|
+
* They live here rather than in UIKitConstants because that file imports the Chat SDK on its
|
|
5
|
+
* first line. Anything that pulls a pattern from it also pulls the SDK, which reads native
|
|
6
|
+
* modules at load — enough to break any consumer (and any test) that does not have the whole
|
|
7
|
+
* SDK available. MarkdownUtils needs `urlPattern` and is exactly that kind of leaf.
|
|
8
|
+
*
|
|
9
|
+
* UIKitConstants re-exports these, so existing imports keep working.
|
|
10
|
+
*/
|
|
11
|
+
export const wordBoundary = {
|
|
12
|
+
start: `(?:^|:|;|'|"|,|{|}|\\.|\\s|\\!|\\?|\\(|\\)|\\[|\\]|\\*)`,
|
|
13
|
+
end: `(?=$|:|;|'|"|,|{|}|\\.|\\s|\\!|\\?|\\(|\\)|\\[|\\]|\\*)`,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const emailPattern =
|
|
17
|
+
wordBoundary.start + `[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}` + wordBoundary.end;
|
|
18
|
+
|
|
19
|
+
// A URL character, excluding parentheses — those only count in balanced pairs (below).
|
|
20
|
+
const urlChar = `[-\\w;/?:@&=+$\\|\\_.!~*\\|'\\[\\]%#,☺]`;
|
|
21
|
+
const urlParens = `\\(${urlChar}*\\)`;
|
|
22
|
+
// A URL path: ends on a word char, `/`, `#`, or a balanced `(…)`. A lone `)` could never be the
|
|
23
|
+
// last character, so https://en.wikipedia.org/wiki/Mercury_(planet) linked without its `)` and
|
|
24
|
+
// opened a page that does not exist — while "(see https://example.com/page)" must still leave
|
|
25
|
+
// the sentence's own `)` outside the link. Balanced pairs satisfy both.
|
|
26
|
+
const urlPath = `(?:${urlChar}|${urlParens})*(?:[\\w/#]|${urlParens})`;
|
|
27
|
+
|
|
28
|
+
export const urlPattern =
|
|
29
|
+
`((https?://|ftp://|www\\.|pic\\.)${urlPath}` +
|
|
30
|
+
`|[a-zA-Z][a-zA-Z0-9]*[-a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-a-zA-Z0-9]*)*\\.[a-zA-Z]{2,}(?:[:/]${urlPath})?)` +
|
|
31
|
+
wordBoundary.end;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A markdown link `[label](address)`. Group 1 is the label, group 2 the address.
|
|
35
|
+
*
|
|
36
|
+
* The address may contain one level of balanced parentheses, so a Wikipedia-style
|
|
37
|
+
* `[Mercury](https://en.wikipedia.org/wiki/Mercury_(planet))` keeps its `(planet)` and only the
|
|
38
|
+
* final `)` closes the link. The old `[^)]+` stopped at the first `)`, opening `…Mercury_(planet`.
|
|
39
|
+
*/
|
|
40
|
+
export const markdownLinkPattern = `\\[([^\\]]+)\\]\\(((?:[^()]|\\([^()]*\\))+)\\)`;
|
|
41
|
+
|
|
42
|
+
export const phoneNumPattern =
|
|
43
|
+
wordBoundary.start +
|
|
44
|
+
`(?:\\+?(\\d{1,3}))?([-. (]*(\\d{3})[-. )]*)?((\\d{3})[-. ]*(\\d{2,4})(?:[-.x ]*(\\d+))?)` +
|
|
45
|
+
wordBoundary.end;
|