@cometchat/chat-uikit-react-native 4.3.3 → 4.3.5

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 (92) hide show
  1. package/README.md +11 -21
  2. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +6 -6
  3. package/ios/CommonUtil.h +4 -0
  4. package/ios/CommonUtil.m +27 -0
  5. package/package.json +10 -5
  6. package/src/AI/AIAssistBot/AIAssistBotDecorator.tsx +0 -3
  7. package/src/CometChatConversations/CometChatConversations.tsx +143 -72
  8. package/src/CometChatConversations/ConversationsConfiguration.ts +25 -4
  9. package/src/CometChatConversationsWithMessages/CometChatConversationsWithMessages.tsx +29 -29
  10. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +11 -1
  11. package/src/CometChatGroups/CometChatGroups.tsx +10 -0
  12. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +554 -52
  13. package/src/CometChatMessageComposer/MessageComposerConfiguration.tsx +12 -1
  14. package/src/CometChatMessageComposer/resources/Info.png +0 -0
  15. package/src/CometChatMessageComposer/resources/index.ts +3 -1
  16. package/src/CometChatMessageHeader/listners.ts +0 -2
  17. package/src/CometChatMessageList/CometChatMessageList.tsx +124 -15
  18. package/src/CometChatMessageList/MessageListConfiguration.ts +14 -1
  19. package/src/CometChatMessages/CometChatMessages.tsx +16 -16
  20. package/src/CometChatThreadedMessages/CometChatThreadedMessages.tsx +6 -1
  21. package/src/calls/CallingExtentionDecorator.tsx +11 -9
  22. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +3 -3
  23. package/src/calls/CometChatCallLogHistory/CometChatCallLogHistory.tsx +10 -0
  24. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +10 -0
  25. package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +2 -0
  26. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +2 -0
  27. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +3 -3
  28. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +3 -3
  29. package/src/extensions/LinkPreview/LinkPreviewExtentionDecorator.tsx +4 -4
  30. package/src/extensions/MessageTranslation/MessageTranslationBubble.tsx +31 -9
  31. package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +83 -6
  32. package/src/extensions/Polls/Polls.tsx +106 -70
  33. package/src/extensions/Polls/PollsDecorator.tsx +3 -2
  34. package/src/extensions/Stickers/CometChatStickerKeyboard/style.ts +3 -3
  35. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +14 -6
  36. package/src/extensions/TextModeration/TextModerationExtensionDecorator.tsx +3 -3
  37. package/src/index.ts +21 -0
  38. package/src/shared/CometChatUiKit/CometChatUIKit.ts +150 -25
  39. package/src/shared/CometChatUiKit/index.ts +1 -1
  40. package/src/shared/base/vars.ts +13 -0
  41. package/src/shared/constants/UIKitConstants.ts +6 -0
  42. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +7 -0
  43. package/src/shared/events/CometChatUIEventHandler/Listener.ts +11 -1
  44. package/src/shared/events/CometChatUIEvents.ts +3 -1
  45. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +380 -0
  46. package/src/shared/formatters/CometChatMentionsFormatter/MentionTextStyle.ts +14 -0
  47. package/src/shared/formatters/CometChatMentionsFormatter/index.ts +7 -0
  48. package/src/shared/formatters/CometChatTextFormatter.ts +253 -0
  49. package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +146 -0
  50. package/src/shared/formatters/index.ts +11 -0
  51. package/src/shared/framework/DataSource.ts +21 -16
  52. package/src/shared/framework/DataSourceDecorator.tsx +29 -13
  53. package/src/shared/framework/MessageDataSource.tsx +215 -49
  54. package/src/shared/helper/useKeyboard.tsx +20 -2
  55. package/src/shared/index.ts +23 -3
  56. package/src/shared/resources/CometChatLocalize/CometChatLocalize.ts +2 -0
  57. package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +11 -1
  58. package/src/shared/resources/CometChatLocalize/resources/de/translation.json +11 -1
  59. package/src/shared/resources/CometChatLocalize/resources/en/translation.json +10 -1
  60. package/src/shared/resources/CometChatLocalize/resources/es/translation.json +11 -1
  61. package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +11 -1
  62. package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +10 -1
  63. package/src/shared/resources/CometChatLocalize/resources/hu/translation.json +315 -0
  64. package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +11 -1
  65. package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +11 -1
  66. package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +12 -1
  67. package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +11 -1
  68. package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +11 -1
  69. package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +11 -1
  70. package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +11 -1
  71. package/src/shared/resources/CometChatTheme/Palette.ts +16 -0
  72. package/src/shared/utils/InteractiveMessageUtils.ts +39 -1
  73. package/src/shared/utils/PermissionUtil.ts +142 -0
  74. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +8 -6
  75. package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +5 -1
  76. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +12 -11
  77. package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +7 -5
  78. package/src/shared/views/CometChatList/CometChatList.tsx +12 -0
  79. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +11 -2
  80. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +3 -2
  81. package/src/shared/views/CometChatReactions/CometChatReactions.tsx +3 -3
  82. package/src/shared/views/CometChatSchedulerBubble/CometChatSchedulerBubble.tsx +12 -0
  83. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +64 -0
  84. package/src/shared/views/CometChatSuggestionList/SuggestionItem.ts +48 -0
  85. package/src/shared/views/CometChatSuggestionList/SuggestionListConfiguration.ts +23 -0
  86. package/src/shared/views/CometChatSuggestionList/index.ts +11 -0
  87. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +33 -46
  88. package/src/shared/views/CometChatTextBubble/TextBubbleStyle.ts +0 -14
  89. package/src/shared/views/CometChatTextBubble/index.ts +2 -3
  90. package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +5 -3
  91. package/src/shared/views/index.ts +9 -3
  92. package/src/shared/utils/PermissionUtilIOS.ts +0 -104
@@ -1,29 +1,30 @@
1
- import React, {useContext} from "react";
1
+ import React, { useContext, useEffect, useState } from "react";
2
2
  import { View, Text, Linking, StyleProp, ViewStyle } from "react-native";
3
3
  import { CometChatContextType } from "../../base/Types";
4
4
  import { CometChatContext } from "../../CometChatContext";
5
5
  import { emailPattern, phoneNumPattern, urlPattern } from "../../constants/UIKitConstants";
6
6
  import { TextBubbleStyle, TextBubbleStyleInterface } from "./TextBubbleStyle";
7
+ import { CometChatMentionsFormatter, CometChatTextFormatter, CometChatUrlsFormatter } from "../../formatters";
7
8
 
8
9
  const Link = ({ text, url, style }) => {
9
- return <Text style={{...style, textDecorationLine: "underline"}} onPress={() => {
10
+ return <Text style={{ ...style, textDecorationLine: "underline" }} onPress={() => {
10
11
  let finalUrl = url.startsWith("http") ? url : `http://${url}`
11
12
  Linking.canOpenURL(finalUrl)
12
13
  .then(res => {
13
14
  if (res) {
14
15
  Linking.openURL(finalUrl);
15
16
  return;
16
- }
17
+ }
17
18
  console.log("Can not open link", finalUrl);
18
19
  })
19
20
  .catch(err => {
20
- console.log({url});
21
+ console.log({ url });
21
22
  console.log("Error:", err);
22
23
  })
23
24
  }} >{text}</Text>
24
25
  }
25
26
 
26
- const getPatternGroup = (str: string):{phone?: string, email?: string, url?: string} => {
27
+ const getPatternGroup = (str: string): { phone?: string, email?: string, url?: string } => {
27
28
  let result = {};
28
29
  if (str.match(phoneNumPattern))
29
30
  result['phone'] = str;
@@ -34,32 +35,6 @@ const getPatternGroup = (str: string):{phone?: string, email?: string, url?: str
34
35
  return result;
35
36
  }
36
37
 
37
- export const FormatTextForLinks = ({str, style}) => {
38
- let res = str.matchAll(phoneNumPattern + "|" + emailPattern + "|" + urlPattern);
39
- for (let resPart of res) {
40
- let { email, phone } = getPatternGroup(resPart[0]);
41
- let pre: string, post:string;
42
- pre = str.substring(0, resPart.index);
43
- post = str.substring(resPart.index + resPart[0].length);
44
- let urlLink = "";
45
- if (email)
46
- urlLink = "mailto:";
47
- if (phone)
48
- urlLink = "tel:";
49
- return (
50
- <Text style={{...style.textFont, color: style.textColor}}>
51
- <Text>
52
- {pre}
53
- </Text>
54
- <Link text={resPart[0]} url={urlLink + resPart[0].trim()} style={{...style.linkTextFont, color: style.linkTextColor}} />
55
- <FormatTextForLinks str={post} style={style} />
56
- </Text>
57
- )
58
- }
59
-
60
- return <Text style={{...style.textFont, color: style.textColor}}>{str}</Text>;
61
- }
62
-
63
38
  export interface CometChatTextBubbleInterface {
64
39
  /**
65
40
  * text tobe shown
@@ -73,17 +48,24 @@ export interface CometChatTextBubbleInterface {
73
48
  * text container style
74
49
  */
75
50
  textContainerStyle?: StyleProp<ViewStyle>
51
+ textFormatters?: Array<CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter>;
76
52
  }
77
53
 
78
54
  export const CometChatTextBubble = (props: CometChatTextBubbleInterface) => {
79
-
80
- const {theme} = useContext<CometChatContextType>(CometChatContext);
55
+
56
+ const {
57
+ text,
58
+ textContainerStyle,
59
+ textFormatters
60
+ } = props;
61
+
62
+ const { theme } = useContext<CometChatContextType>(CometChatContext);
63
+ const [formattedText, setFormattedText] = useState<string>();
81
64
 
82
65
  const _style = new TextBubbleStyle({
83
66
  backgroundColor: theme?.palette.getBackgroundColor(),
84
67
  textColor: theme?.palette.getAccent(),
85
68
  textFont: theme?.typography.body,
86
- linkTextFont: theme?.typography.body,
87
69
  ...props.style
88
70
  });
89
71
 
@@ -93,30 +75,35 @@ export const CometChatTextBubble = (props: CometChatTextBubbleInterface) => {
93
75
  borderRadius,
94
76
  textColor,
95
77
  textFont,
96
- linkTextColor,
97
- linkTextFont,
98
78
  height,
99
79
  width
100
80
  } = _style;
101
81
 
102
- const {
103
- text,
104
- textContainerStyle
105
- } = props;
82
+ useEffect(() => {
83
+ let finalText = text;
84
+ if (textFormatters && textFormatters.length) {
85
+ if (textFormatters) {
86
+ for (let i = 0; i < textFormatters.length; i++) {
87
+ (finalText as string | void) = textFormatters[i].getFormattedText(finalText);
88
+ }
89
+ }
90
+ }
91
+ setFormattedText(finalText as string);
92
+ }, [])
106
93
 
107
94
  return <View style={[
108
95
  {
109
96
  alignSelf: "flex-start",
110
97
  },
111
98
  {
112
- backgroundColor, borderRadius, maxHeight: height, maxWidth: width,
99
+ backgroundColor, borderRadius, maxHeight: height, maxWidth: width,
113
100
  overflow: "hidden", padding: 8, paddingBottom: 0
114
101
  },
115
- border,
116
- textContainerStyle
117
- ]}>
118
- <FormatTextForLinks str={text} style={{textColor, textFont, linkTextColor, linkTextFont}} />
119
-
102
+ border,
103
+ textContainerStyle
104
+ ]}>
105
+ <Text style={[{ color: textColor }, textFont]}>{formattedText}</Text>
106
+
120
107
  </View>
121
108
  }
122
109
 
@@ -9,21 +9,11 @@ export interface TextBubbleStyleInterface extends BaseStyleInterface {
9
9
  * font style for text
10
10
  */
11
11
  textFont?: FontStyle,
12
- /**
13
- * font syle for special text
14
- */
15
- linkTextFont?: FontStyle,
16
- /**
17
- * color for special text
18
- */
19
- linkTextColor?: string
20
12
  }
21
13
 
22
14
  export class TextBubbleStyle extends BaseStyle {
23
15
  textColor: string
24
16
  textFont: FontStyle
25
- linkTextFont: FontStyle
26
- linkTextColor: string
27
17
 
28
18
  constructor({
29
19
  width = "auto",
@@ -33,8 +23,6 @@ export class TextBubbleStyle extends BaseStyle {
33
23
  borderRadius = 0,
34
24
  textColor = "rgb(20, 20, 20)",
35
25
  textFont = new FontStyle({fontSize: 17, fontWeight: "400"}),
36
- linkTextColor = "blue",
37
- linkTextFont = new FontStyle({fontSize: 17, fontWeight: "400"}),
38
26
  }: TextBubbleStyleInterface) {
39
27
  super({
40
28
  width,
@@ -45,7 +33,5 @@ export class TextBubbleStyle extends BaseStyle {
45
33
  });
46
34
  this.textColor = textColor;
47
35
  this.textFont = new FontStyle({...textFont});
48
- this.linkTextColor = linkTextColor;
49
- this.linkTextFont = new FontStyle({...linkTextFont});
50
36
  }
51
37
  }
@@ -1,9 +1,8 @@
1
- import {CometChatTextBubble, CometChatTextBubbleInterface, FormatTextForLinks} from "./CometChatTextBubble";
1
+ import { CometChatTextBubble, CometChatTextBubbleInterface } from "./CometChatTextBubble";
2
2
 
3
- import {TextBubbleStyle, TextBubbleStyleInterface} from "./TextBubbleStyle";
3
+ import { TextBubbleStyle, TextBubbleStyleInterface } from "./TextBubbleStyle";
4
4
 
5
5
  export {
6
- FormatTextForLinks,
7
6
  CometChatTextBubble,
8
7
  CometChatTextBubbleInterface,
9
8
  TextBubbleStyle,
@@ -133,7 +133,7 @@ export const CometChatVideoBubble = (props: CometChatVideoBubbleInterface) => {
133
133
  };
134
134
 
135
135
  const handleTouchEnd = () => {
136
- // if (pressTime.current === null) return;
136
+ if (pressTime.current === null && Platform.OS === "ios") return;
137
137
  const endTime = Date.now();
138
138
  const pressDuration = endTime - pressTime.current;
139
139
  if (pressDuration < 500) {
@@ -142,7 +142,9 @@ export const CometChatVideoBubble = (props: CometChatVideoBubbleInterface) => {
142
142
  };
143
143
 
144
144
  const onTouchMove = () => {
145
- // pressTime.current = null
145
+ if (Platform.OS === "ios") {
146
+ pressTime.current = null;
147
+ }
146
148
  }
147
149
 
148
150
  return (
@@ -169,7 +171,7 @@ export const CometChatVideoBubble = (props: CometChatVideoBubbleInterface) => {
169
171
  <View
170
172
  onTouchStart={handleTouchStart}
171
173
  onTouchEnd={handleTouchEnd}
172
- // onTouchMove={onTouchMove}
174
+ onTouchMove={onTouchMove}
173
175
  style={[Style.playIconPosition, { backgroundColor: playIconBackgroundColor, borderRadius }]}>
174
176
  {isLoading ? <ActivityIndicator size={"small"} color={playIconTint} />
175
177
  : <Image source={playIcon || defaultPlayIcon} style={{ tintColor: playIconTint }} />
@@ -16,7 +16,6 @@ import {
16
16
  CometChatTextBubbleInterface,
17
17
  TextBubbleStyle,
18
18
  TextBubbleStyleInterface,
19
- FormatTextForLinks,
20
19
  } from './CometChatTextBubble';
21
20
  import {
22
21
  CometChatImageBubble,
@@ -94,6 +93,8 @@ import { CometChatQuickReactions, CometChatQuickReactionsInterface, QuickReactio
94
93
 
95
94
  import { CometChatEmojiKeyboard, EmojiKeyboardConfiguration, EmojiKeyboardStyle } from './CometChatEmojiKeyboard';
96
95
 
96
+ import { CometChatSuggestionList, CometChatSuggestionListInterface, SuggestionItem, SuggestionListConfiguration, SuggestionListConfigurationInterface } from './CometChatSuggestionList';
97
+
97
98
  export {
98
99
  CometChatMessageInputStyleInterface,
99
100
  CometChatMessageInputInterface,
@@ -109,7 +110,6 @@ export {
109
110
  BadgeConfigurationInterface,
110
111
  BadgeStyleInterface,
111
112
  AvatarConfigurationInterface,
112
- FormatTextForLinks,
113
113
  ActionItemInterface,
114
114
  ActionSheetStylesInterface,
115
115
  CometChatConfirmDialogInterface,
@@ -198,5 +198,11 @@ export {
198
198
  EmojiKeyboardStyle,
199
199
 
200
200
  CometChatSchedulerBubble,
201
- CometChatSchedulerBubbleInterface
201
+ CometChatSchedulerBubbleInterface,
202
+
203
+ CometChatSuggestionList,
204
+ CometChatSuggestionListInterface,
205
+ SuggestionItem,
206
+ SuggestionListConfiguration,
207
+ SuggestionListConfigurationInterface,
202
208
  };
@@ -1,104 +0,0 @@
1
- import { Alert, Linking, NativeModules, Platform } from 'react-native';
2
- import { localize } from '../../shared/resources/CometChatLocalize/CometChatLocalize';
3
- const { FileManager } = NativeModules;
4
-
5
- let instance: PermissionUtilIOS;
6
- const permissionStatus = {
7
- 'Not Determined': 0,
8
- 'Restricted': 1,
9
- 'Denied': 2,
10
- 'Authorized': 3,
11
- 'Unknown': -1,
12
- } as const;
13
-
14
- const permissibleResources = ['camera', 'mic'] as const;
15
- type TPermissibleResources = (typeof permissibleResources)[number];
16
-
17
- type ValueOf<T> = T[keyof T];
18
- type TPermissionStatus = ValueOf<typeof permissionStatus>;
19
-
20
- const permissionStore: Record<TPermissibleResources, TPermissionStatus> = {
21
- camera: permissionStatus.Unknown,
22
- mic: permissionStatus.Unknown,
23
- };
24
-
25
- class PermissionUtilIOS {
26
- status = permissionStatus;
27
- constructor() {
28
- if (instance) {
29
- throw new Error('New instance cannot be created!!');
30
- }
31
- instance = this;
32
- }
33
-
34
- async init() {
35
- try {
36
- const res: Record<TPermissibleResources, TPermissionStatus> =
37
- await FileManager.checkResourcesPermission(['mic', 'camera']);
38
- for (const resourceType in res) {
39
- permissionStore[resourceType as TPermissibleResources] =
40
- res[resourceType as TPermissibleResources];
41
- }
42
- permissionStore.camera = res.camera;
43
- permissionStore.mic = res.mic;
44
- return true;
45
- } catch (error: any) {
46
- return false;
47
- }
48
- }
49
-
50
- async get(resources: TPermissibleResources[]) {
51
- return resources.map((resource) => {
52
- if (!permissibleResources.includes(resource)) {
53
- throw new Error('Invalid resource type');
54
- }
55
- return permissionStore[resource];
56
- });
57
- }
58
-
59
- async request(resources: TPermissibleResources[]) {
60
- for (const resource of resources) {
61
- if (!permissibleResources.includes(resource)) {
62
- throw new Error('Invalid resource type');
63
- }
64
- }
65
- const res: Record<TPermissibleResources, TPermissionStatus> =
66
- await FileManager.requestResourcesPermission(resources);
67
- for (const resourceType in res) {
68
- permissionStore[resourceType as TPermissibleResources] =
69
- res[resourceType as TPermissibleResources];
70
- }
71
- }
72
-
73
- async startResourceBasedTask(resources: TPermissibleResources[]) {
74
- if (Platform.OS === 'ios') {
75
- const resourcePermStatuses = await this.get(resources);
76
- for (let i = 0; i < resourcePermStatuses.length; i++) {
77
- const resourcePermStatus = resourcePermStatuses[i];
78
- if (resourcePermStatus === this.status['Not Determined']) {
79
- await this.request([resources[i]]);
80
- [resourcePermStatuses[i]] = await this.get([resources[i]]);
81
- }
82
- if (resourcePermStatuses[i] === this.status.Denied) {
83
- Alert.alert(localize('RESOURCE_PERMISSION_REQUIRED'), undefined, [
84
- {
85
- style: 'cancel',
86
- text: localize('CANCEL'),
87
- },
88
- {
89
- style: 'default',
90
- text: localize('SETTINGS'),
91
- onPress: () => {
92
- Linking.openSettings();
93
- },
94
- },
95
- ]);
96
- return false;
97
- }
98
- }
99
- }
100
- return true;
101
- }
102
- }
103
-
104
- export const permissionUtilIOS = Object.freeze(new PermissionUtilIOS());