@cometchat/chat-uikit-react-native 4.2.2 → 4.3.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.
Files changed (227) hide show
  1. package/README.md +26 -67
  2. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  3. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  4. package/android/build.gradle +1 -1
  5. package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +2 -1
  6. package/android/src/main/java/com/reactnativecometchatuikit/ReactVideoView.java +796 -0
  7. package/android/src/main/java/com/reactnativecometchatuikit/ReactVideoViewManager.java +172 -0
  8. package/android/src/main/java/com/scalablevideoview/BuildConfig.java +10 -0
  9. package/android/src/main/java/com/scalablevideoview/PivotPoint.java +13 -0
  10. package/android/src/main/java/com/scalablevideoview/ScalableType.java +34 -0
  11. package/android/src/main/java/com/scalablevideoview/ScalableVideoView.java +255 -0
  12. package/android/src/main/java/com/scalablevideoview/ScaleManager.java +188 -0
  13. package/android/src/main/java/com/scalablevideoview/Size.java +20 -0
  14. package/android/src/main/java/com/zipfile/APEZProvider.java +287 -0
  15. package/android/src/main/java/com/zipfile/APKExpansionSupport.java +81 -0
  16. package/android/src/main/java/com/zipfile/ZipResourceFile.java +428 -0
  17. package/android/src/main/res/values/attrs.xml +37 -0
  18. package/ios/FileManager.m +75 -5
  19. package/ios/Video/CCRCTVideo.h +67 -0
  20. package/ios/Video/CCRCTVideo.m +2031 -0
  21. package/ios/Video/CCRCTVideoManager.h +6 -0
  22. package/ios/Video/CCRCTVideoManager.m +133 -0
  23. package/ios/Video/CCRCTVideoPlayerViewController.h +20 -0
  24. package/ios/Video/CCRCTVideoPlayerViewController.m +43 -0
  25. package/ios/Video/CCRCTVideoPlayerViewControllerDelegate.h +7 -0
  26. package/ios/Video/UIView+FindUIViewController.h +15 -0
  27. package/ios/Video/UIView+FindUIViewController.m +21 -0
  28. package/ios/VideoCaching/RCTVideoCache.h +38 -0
  29. package/ios/VideoCaching/RCTVideoCache.m +174 -0
  30. package/ios/VideoPickerModule.h +7 -0
  31. package/ios/VideoPickerModule.mm +95 -0
  32. package/package.json +3 -4
  33. package/react-native-cometchat-ui-kit.podspec +24 -10
  34. package/src/CometChatContacts/CometChatContacts.tsx +12 -9
  35. package/src/CometChatConversations/CometChatConversations.tsx +84 -64
  36. package/src/CometChatDetails/CometChatDetails.tsx +14 -12
  37. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +8 -4
  38. package/src/CometChatGroupMembers/resources/check.png +0 -0
  39. package/src/CometChatGroupMembers/resources/index.ts +2 -0
  40. package/src/CometChatGroups/CometChatGroups.tsx +4 -4
  41. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +57 -15
  42. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +9 -2
  43. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +1 -1
  44. package/src/CometChatMessageList/CometChatMessageList.tsx +596 -181
  45. package/src/CometChatMessageList/MessageListConfiguration.ts +55 -4
  46. package/src/CometChatMessageList/resources/index.ts +5 -1
  47. package/src/CometChatMessageList/resources/leftarrowcurve.png +0 -0
  48. package/src/CometChatMessageList/resources/rightarrowcurve.png +0 -0
  49. package/src/CometChatMessages/CometChatMessages.tsx +1 -1
  50. package/src/CometChatThreadedMessages/CometChatThreadedMessages.tsx +4 -12
  51. package/src/CometChatThreadedMessages/style.ts +3 -1
  52. package/src/CometChatUsers/CometChatUsers.tsx +1 -1
  53. package/src/calls/CallUtils.ts +4 -8
  54. package/src/calls/CallingExtentionDecorator.tsx +5 -2
  55. package/src/calls/CometChatCallBubble/styles.ts +2 -1
  56. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +14 -3
  57. package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +9 -9
  58. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +80 -73
  59. package/src/extensions/CollaborativeBubble/styles.ts +2 -0
  60. package/src/extensions/SmartReplies/SmartRepliesDecorator.tsx +11 -0
  61. package/src/extensions/index.ts +0 -4
  62. package/src/index.ts +53 -8
  63. package/src/shared/CometChatUiKit/CometChatUIKit.ts +14 -2
  64. package/src/shared/constants/UIKitConstants.ts +1 -0
  65. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +6 -0
  66. package/src/shared/events/CometChatUIEventHandler/Listener.ts +8 -0
  67. package/src/shared/events/ListenerInitializer.ts +6 -0
  68. package/src/shared/events/messages.ts +2 -0
  69. package/src/shared/framework/MessageDataSource.tsx +29 -25
  70. package/src/shared/index.ts +49 -1
  71. package/src/shared/libs/VideoPlayer/DRMType.js +6 -0
  72. package/src/shared/libs/VideoPlayer/FilterType.js +18 -0
  73. package/src/shared/libs/VideoPlayer/TextTrackType.js +5 -0
  74. package/src/shared/libs/VideoPlayer/Video.js +519 -0
  75. package/src/shared/libs/VideoPlayer/VideoResizeMode.js +5 -0
  76. package/src/shared/libs/VideoPlayerControls/OSSupport/PlatformSupport.tsx +43 -0
  77. package/src/shared/libs/VideoPlayerControls/OSSupport/TVOSSupport.tsx +16 -0
  78. package/src/shared/libs/VideoPlayerControls/OSSupport/index.tsx +1 -0
  79. package/src/shared/libs/VideoPlayerControls/VideoPlayer.tsx +511 -0
  80. package/src/shared/libs/VideoPlayerControls/assets/img/back.png +0 -0
  81. package/src/shared/libs/VideoPlayerControls/assets/img/back@2x.png +0 -0
  82. package/src/shared/libs/VideoPlayerControls/assets/img/back@3x.png +0 -0
  83. package/src/shared/libs/VideoPlayerControls/assets/img/bottom-vignette.png +0 -0
  84. package/src/shared/libs/VideoPlayerControls/assets/img/bottom-vignette@2x.png +0 -0
  85. package/src/shared/libs/VideoPlayerControls/assets/img/bottom-vignette@3x.png +0 -0
  86. package/src/shared/libs/VideoPlayerControls/assets/img/error-icon.png +0 -0
  87. package/src/shared/libs/VideoPlayerControls/assets/img/error-icon@2x.png +0 -0
  88. package/src/shared/libs/VideoPlayerControls/assets/img/error-icon@3x.png +0 -0
  89. package/src/shared/libs/VideoPlayerControls/assets/img/expand.png +0 -0
  90. package/src/shared/libs/VideoPlayerControls/assets/img/expand@2x.png +0 -0
  91. package/src/shared/libs/VideoPlayerControls/assets/img/expand@3x.png +0 -0
  92. package/src/shared/libs/VideoPlayerControls/assets/img/forward.png +0 -0
  93. package/src/shared/libs/VideoPlayerControls/assets/img/forward@2x.png +0 -0
  94. package/src/shared/libs/VideoPlayerControls/assets/img/forward@3x.png +0 -0
  95. package/src/shared/libs/VideoPlayerControls/assets/img/loader-icon.png +0 -0
  96. package/src/shared/libs/VideoPlayerControls/assets/img/loader-icon@2x.png +0 -0
  97. package/src/shared/libs/VideoPlayerControls/assets/img/loader-icon@3x.png +0 -0
  98. package/src/shared/libs/VideoPlayerControls/assets/img/pause.png +0 -0
  99. package/src/shared/libs/VideoPlayerControls/assets/img/pause@2x.png +0 -0
  100. package/src/shared/libs/VideoPlayerControls/assets/img/pause@3x.png +0 -0
  101. package/src/shared/libs/VideoPlayerControls/assets/img/play.png +0 -0
  102. package/src/shared/libs/VideoPlayerControls/assets/img/play@2x.png +0 -0
  103. package/src/shared/libs/VideoPlayerControls/assets/img/play@3x.png +0 -0
  104. package/src/shared/libs/VideoPlayerControls/assets/img/rewind.png +0 -0
  105. package/src/shared/libs/VideoPlayerControls/assets/img/rewind@2x.png +0 -0
  106. package/src/shared/libs/VideoPlayerControls/assets/img/rewind@3x.png +0 -0
  107. package/src/shared/libs/VideoPlayerControls/assets/img/shrink.png +0 -0
  108. package/src/shared/libs/VideoPlayerControls/assets/img/shrink@2x.png +0 -0
  109. package/src/shared/libs/VideoPlayerControls/assets/img/shrink@3x.png +0 -0
  110. package/src/shared/libs/VideoPlayerControls/assets/img/top-vignette.png +0 -0
  111. package/src/shared/libs/VideoPlayerControls/assets/img/top-vignette@2x.png +0 -0
  112. package/src/shared/libs/VideoPlayerControls/assets/img/top-vignette@3x.png +0 -0
  113. package/src/shared/libs/VideoPlayerControls/assets/img/volume.png +0 -0
  114. package/src/shared/libs/VideoPlayerControls/assets/img/volume@2x.png +0 -0
  115. package/src/shared/libs/VideoPlayerControls/assets/img/volume@3x.png +0 -0
  116. package/src/shared/libs/VideoPlayerControls/components/Back/Back.tsx +28 -0
  117. package/src/shared/libs/VideoPlayerControls/components/Back/index.ts +1 -0
  118. package/src/shared/libs/VideoPlayerControls/components/BottomControls.tsx +142 -0
  119. package/src/shared/libs/VideoPlayerControls/components/Control.tsx +45 -0
  120. package/src/shared/libs/VideoPlayerControls/components/Error/Error.tsx +22 -0
  121. package/src/shared/libs/VideoPlayerControls/components/Error/index.ts +1 -0
  122. package/src/shared/libs/VideoPlayerControls/components/Error/styles.ts +21 -0
  123. package/src/shared/libs/VideoPlayerControls/components/Fullscreen.tsx +36 -0
  124. package/src/shared/libs/VideoPlayerControls/components/Loader/Loader.tsx +15 -0
  125. package/src/shared/libs/VideoPlayerControls/components/Loader/index.ts +1 -0
  126. package/src/shared/libs/VideoPlayerControls/components/Loader/styles.ts +16 -0
  127. package/src/shared/libs/VideoPlayerControls/components/NullControl.tsx +7 -0
  128. package/src/shared/libs/VideoPlayerControls/components/Overlay.tsx +23 -0
  129. package/src/shared/libs/VideoPlayerControls/components/PlayPause/PlayPause.tsx +109 -0
  130. package/src/shared/libs/VideoPlayerControls/components/PlayPause/index.ts +1 -0
  131. package/src/shared/libs/VideoPlayerControls/components/PlayPause/styles.ts +21 -0
  132. package/src/shared/libs/VideoPlayerControls/components/Seekbar/Seekbar.tsx +47 -0
  133. package/src/shared/libs/VideoPlayerControls/components/Seekbar/index.ts +1 -0
  134. package/src/shared/libs/VideoPlayerControls/components/Seekbar/styles.ts +37 -0
  135. package/src/shared/libs/VideoPlayerControls/components/Timer/Timer.tsx +28 -0
  136. package/src/shared/libs/VideoPlayerControls/components/Timer/index.ts +1 -0
  137. package/src/shared/libs/VideoPlayerControls/components/Timer/styles.ts +12 -0
  138. package/src/shared/libs/VideoPlayerControls/components/Title.tsx +35 -0
  139. package/src/shared/libs/VideoPlayerControls/components/TopControls.tsx +110 -0
  140. package/src/shared/libs/VideoPlayerControls/components/Volume/Volume.tsx +37 -0
  141. package/src/shared/libs/VideoPlayerControls/components/Volume/index.ts +1 -0
  142. package/src/shared/libs/VideoPlayerControls/components/Volume/styles.ts +31 -0
  143. package/src/shared/libs/VideoPlayerControls/components/index.ts +14 -0
  144. package/src/shared/libs/VideoPlayerControls/components/styles.ts +30 -0
  145. package/src/shared/libs/VideoPlayerControls/hooks/index.ts +3 -0
  146. package/src/shared/libs/VideoPlayerControls/hooks/useAnimations.ts +68 -0
  147. package/src/shared/libs/VideoPlayerControls/hooks/useControlTimeout.tsx +67 -0
  148. package/src/shared/libs/VideoPlayerControls/hooks/usePanResponders.tsx +96 -0
  149. package/src/shared/libs/VideoPlayerControls/index.ts +4 -0
  150. package/src/shared/libs/VideoPlayerControls/styles.ts +19 -0
  151. package/src/shared/libs/VideoPlayerControls/types.ts +290 -0
  152. package/src/shared/libs/VideoPlayerControls/utils.ts +76 -0
  153. package/src/shared/modals/CometChatMessageTemplate.ts +113 -9
  154. package/src/shared/modals/InteractiveData/InteractiveMessage/SchedulerMessage.ts +23 -21
  155. package/src/shared/resources/CometChatLocalize/resources/ar/translation.json +4 -1
  156. package/src/shared/resources/CometChatLocalize/resources/de/translation.json +4 -1
  157. package/src/shared/resources/CometChatLocalize/resources/en/translation.json +6 -3
  158. package/src/shared/resources/CometChatLocalize/resources/es/translation.json +4 -1
  159. package/src/shared/resources/CometChatLocalize/resources/fr/translation.json +4 -1
  160. package/src/shared/resources/CometChatLocalize/resources/hi/translation.json +4 -1
  161. package/src/shared/resources/CometChatLocalize/resources/lt/translation.json +4 -1
  162. package/src/shared/resources/CometChatLocalize/resources/ms/translation.json +4 -1
  163. package/src/shared/resources/CometChatLocalize/resources/pt/translation.json +4 -1
  164. package/src/shared/resources/CometChatLocalize/resources/ru/translation.json +4 -1
  165. package/src/shared/resources/CometChatLocalize/resources/sv/translation.json +4 -1
  166. package/src/shared/resources/CometChatLocalize/resources/zh/translation.json +4 -1
  167. package/src/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +4 -1
  168. package/src/shared/resources/CometChatTheme/Palette.ts +79 -45
  169. package/src/shared/resources/CometChatTheme/Typography.ts +18 -0
  170. package/src/shared/utils/CommonUtils.ts +71 -0
  171. package/src/shared/utils/PermissionUtilIOS.ts +104 -0
  172. package/src/shared/views/CometChatActionSheet/ActionSheetStyle.ts +3 -1
  173. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +6 -6
  174. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +28 -5
  175. package/src/shared/views/CometChatAudioBubble/style.ts +4 -2
  176. package/src/shared/views/CometChatAvatar/AvatarStyle.ts +1 -1
  177. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +4 -3
  178. package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +47 -31
  179. package/src/shared/views/CometChatEmojiKeyboard/EmojiKeyboardConfiguration.ts +5 -5
  180. package/src/shared/views/CometChatEmojiKeyboard/EmojiKeyboardStyle.ts +12 -13
  181. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +52 -5
  182. package/src/shared/views/CometChatFileBubble/style.ts +4 -2
  183. package/src/shared/views/CometChatImageBubble/CometChatImageBubble.tsx +25 -2
  184. package/src/shared/views/CometChatList/CometChatList.tsx +2 -1
  185. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +51 -2
  186. package/src/shared/views/CometChatQuickReactions/CometChatQuickReactions.tsx +76 -0
  187. package/src/shared/views/CometChatQuickReactions/QuickReactionsConfiguration.tsx +12 -0
  188. package/src/shared/views/CometChatQuickReactions/QuickReactionsStyle.tsx +35 -0
  189. package/src/shared/views/CometChatQuickReactions/index.ts +12 -0
  190. package/src/shared/views/CometChatReactions/CometChatReactions.tsx +166 -0
  191. package/src/shared/views/CometChatReactions/ReactionsConfiguration.tsx +12 -0
  192. package/src/shared/views/CometChatReactions/ReactionsStyle.tsx +43 -0
  193. package/src/shared/views/CometChatReactions/index.ts +12 -0
  194. package/src/{extensions/Reactions/CometChatMessageReactions → shared/views/CometChatReactions}/style.ts +7 -7
  195. package/src/shared/views/CometChatReactionsList/CometChatReactionsList.tsx +335 -0
  196. package/src/shared/views/CometChatReactionsList/ReactionsListConfiguration.tsx +14 -0
  197. package/src/shared/views/CometChatReactionsList/ReactionsListStyle.tsx +67 -0
  198. package/src/shared/views/CometChatReactionsList/index.ts +12 -0
  199. package/src/shared/views/CometChatReactionsList/resources/Spineer.png +0 -0
  200. package/src/shared/views/CometChatReactionsList/resources/index.ts +5 -0
  201. package/src/shared/views/CometChatReceipt/CometChatReceipt.tsx +21 -4
  202. package/src/shared/views/CometChatReceipt/MessageConfiguration.ts +12 -0
  203. package/src/shared/views/CometChatReceipt/resources/error.png +0 -0
  204. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +1 -1
  205. package/src/shared/views/CometChatVideoBubble/CometChatVideoBubble.tsx +78 -12
  206. package/src/shared/views/CometChatVideoBubble/VideoBubbleStyle.ts +52 -2
  207. package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +134 -0
  208. package/src/shared/views/CometChatVideoPlayer/index.tsx +1 -0
  209. package/src/shared/views/index.ts +30 -0
  210. package/android/.gradle/7.4.2/checksums/checksums.lock +0 -0
  211. package/android/.gradle/7.4.2/fileChanges/last-build.bin +0 -0
  212. package/android/.gradle/7.4.2/fileHashes/fileHashes.lock +0 -0
  213. package/android/.gradle/7.4.2/gc.properties +0 -0
  214. package/android/.gradle/checksums/checksums.lock +0 -0
  215. package/android/.idea/gradle.xml +0 -13
  216. package/android/.idea/misc.xml +0 -8
  217. package/android/.idea/modules/android.iml +0 -18
  218. package/android/.idea/modules.xml +0 -8
  219. package/android/.idea/vcs.xml +0 -6
  220. package/android/local.properties +0 -8
  221. package/src/extensions/Reactions/CometChatMessageReactions/CometChatMessageReactions.tsx +0 -249
  222. package/src/extensions/Reactions/CometChatMessageReactions/index.ts +0 -3
  223. package/src/extensions/Reactions/ReactionsDecorator.tsx +0 -164
  224. package/src/extensions/Reactions/ReactionsExtension.tsx +0 -48
  225. package/src/extensions/Reactions/index.ts +0 -4
  226. /package/src/{extensions/Reactions → shared/views/CometChatQuickReactions}/resources/AddReactions.png +0 -0
  227. /package/src/{extensions/Reactions → shared/views/CometChatQuickReactions}/resources/index.ts +0 -0
@@ -0,0 +1,166 @@
1
+ import React, { useContext } from 'react';
2
+ import { Text, TouchableOpacity, View } from 'react-native';
3
+ import { CometChatContext } from "../../CometChatContext";
4
+ import { Styles } from './style';
5
+ //@ts-ignore
6
+ import { CometChat } from '@cometchat/chat-sdk-react-native';
7
+ import { ReactionsStyle, ReactionsStyleInterface } from './ReactionsStyle';
8
+ import { MessageBubbleAlignmentType } from '../../constants/UIKitConstants';
9
+
10
+ export interface CometChatReactionsInterface {
11
+ messageObject?: CometChat.BaseMessage;
12
+ style?: ReactionsStyleInterface;
13
+ onReactionPress?: (reaction: CometChat.ReactionCount, messageObject: CometChat.BaseMessage) => void;
14
+ onReactionLongPress?: (reaction: CometChat.ReactionCount, messageObject: CometChat.BaseMessage) => void;
15
+ alignment?: MessageBubbleAlignmentType;
16
+ }
17
+ const CometChatReactions = (props: CometChatReactionsInterface) => {
18
+ const {
19
+ messageObject,
20
+ style,
21
+ onReactionPress,
22
+ onReactionLongPress,
23
+ alignment,
24
+ } = props;
25
+
26
+ const { theme } = useContext(CometChatContext);
27
+ const [reactionList, setReactionList] = React.useState([]);
28
+ const reactionRef = React.useRef([]);
29
+
30
+ const _style = new ReactionsStyle({
31
+ emojiFont: style?.emojiFont || theme?.typography?.text1,
32
+ countColor: style?.countColor || theme?.palette?.getAccent(),
33
+ countFont: style?.countFont || theme?.typography?.text1,
34
+ backgroundColor: style?.backgroundColor || theme?.palette?.getAccent100(),
35
+ primaryBackgroundColor: style?.primaryBackgroundColor || theme?.palette?.getPrimary150(),
36
+ primaryBorder: style?.primaryBorder || {
37
+ borderWidth: 1,
38
+ borderColor: theme?.palette?.getPrimary500(),
39
+ },
40
+ border: style?.border || {
41
+ borderWidth: 0,
42
+ borderColor: theme?.palette?.getAccent100(),
43
+ },
44
+ });
45
+
46
+ const {
47
+ emojiFont,
48
+ countColor,
49
+ countFont,
50
+ primaryBackgroundColor,
51
+ backgroundColor,
52
+ border,
53
+ primaryBorder,
54
+ } = _style;
55
+
56
+ const reactionView = (reactionObj) => {
57
+ let count: number = reactionObj?.count;
58
+ let Emoji: string = reactionObj?.reaction;
59
+ let Count: JSX.Element = <Text
60
+ style={[
61
+ Styles.reactionCountStyle,
62
+ { color: countColor },
63
+ countFont,
64
+ ]}
65
+ >
66
+ {count}
67
+ </Text>;
68
+
69
+ return count >= 1 ? (
70
+ <View style={[
71
+ Styles.messageReactionsStyle,
72
+ {
73
+ backgroundColor: reactionObj?.reactedByMe ? primaryBackgroundColor : backgroundColor,
74
+ paddingVertical: 0, paddingHorizontal: 0,
75
+ },
76
+ { backgroundColor: theme.palette.getBackgroundColor() }]}>
77
+ <TouchableOpacity
78
+ onPress={() => {
79
+ onReactionPress(reactionObj, messageObject);
80
+ }}
81
+ onLongPress={() => {
82
+ onReactionLongPress(reactionObj, messageObject);
83
+ }}
84
+ key={Math.random()}
85
+ style={[
86
+ Styles.messageReactionsStyle,
87
+ {
88
+ backgroundColor: reactionObj?.reactedByMe ? primaryBackgroundColor : backgroundColor,
89
+ marginRight: 0, marginBottom: 0,
90
+ ...(reactionObj?.reactedByMe ? primaryBorder : border),
91
+ }
92
+ ]}
93
+ >
94
+ <Text style={[Styles.reactionListStyle, emojiFont]}>
95
+ {Emoji}&nbsp;{Count}
96
+ </Text>
97
+ </TouchableOpacity>
98
+ </View>
99
+ ) : null;
100
+ };
101
+
102
+ const extraEmojisView = (numberOfExtraEmojis: number) => {
103
+ let extraEmojis = reactionRef.current.slice(reactionRef.current.length - numberOfExtraEmojis);
104
+ let hasReactedByMe = extraEmojis.some((reaction) => reaction.reactedByMe);
105
+
106
+ let totalCount = reactionRef.current.reduce((acc, curr) => acc + curr.count, 0);
107
+ let AllObj = new CometChat.ReactionCount("All", totalCount, false); // { reaction: "All", count: totalCount };
108
+
109
+ return (
110
+ <View style={[
111
+ Styles.messageReactionsStyle,
112
+ {
113
+ paddingVertical: 0, paddingHorizontal: 0,
114
+ },
115
+ { backgroundColor: theme.palette.getBackgroundColor() }]}>
116
+ <TouchableOpacity
117
+ onPress={() => {
118
+ onReactionLongPress(AllObj, messageObject);
119
+ }}
120
+ onLongPress={() => {
121
+ onReactionLongPress(AllObj, messageObject);
122
+ }}
123
+ key={Math.random()}
124
+ style={[
125
+ Styles.messageReactionsStyle,
126
+ {
127
+ backgroundColor: hasReactedByMe ? primaryBackgroundColor : backgroundColor,
128
+ ...(hasReactedByMe ? primaryBorder : border),
129
+ marginRight: 0, marginBottom: 0,
130
+ paddingHorizontal: 6,
131
+ },
132
+ ]}
133
+ >
134
+ <Text style={[Styles.reactionListStyle, emojiFont]}>
135
+ +{numberOfExtraEmojis}
136
+ </Text>
137
+ </TouchableOpacity>
138
+ </View>)
139
+ }
140
+
141
+ React.useEffect(() => {
142
+ reactionRef.current = messageObject?.getReactions() || [];
143
+ const messageReactions = reactionRef.current.map(reactionView) || [];
144
+ if (messageReactions.length > 0) {
145
+ if (messageReactions.length > 4) {
146
+ let newMessageReactions = [...messageReactions].slice(0, 3);
147
+ newMessageReactions.push(extraEmojisView(reactionRef.current.length - 3));
148
+ setReactionList(newMessageReactions);
149
+ } else setReactionList(messageReactions);
150
+ }
151
+ }, [messageObject]);
152
+
153
+ return reactionList.length ? (
154
+ <View style={[Styles.messageReactionListStyle, { alignSelf: alignment === "right" ? "flex-end" : alignment === "center" ? "center" : "flex-start" }]}>
155
+ {reactionList}
156
+ </View>
157
+ ) : null;
158
+ };
159
+
160
+ // Specifies the default values for props:
161
+ CometChatReactions.defaultProps = {
162
+ messageObject: null,
163
+ style: {},
164
+ };
165
+
166
+ export { CometChatReactions };
@@ -0,0 +1,12 @@
1
+ import { CometChatReactionsInterface } from './CometChatReactions';
2
+
3
+ export interface ReactionsConfigurationInterface extends Omit<CometChatReactionsInterface, 'messageObject' | 'alignment'> { }
4
+
5
+ export class ReactionsConfiguration {
6
+ constructor(props: ReactionsConfigurationInterface) {
7
+ if (props)
8
+ for (const [key, value] of Object.entries(props)) {
9
+ this[key] = value;
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,43 @@
1
+ import { BaseStyle, BorderStyleInterface, FontStyle } from "../../base";
2
+
3
+ export interface ReactionsStyleInterface extends BaseStyle {
4
+ emojiFont?: FontStyle;
5
+ countColor?: string;
6
+ countFont?: FontStyle;
7
+ primaryBackgroundColor?: string;
8
+ primaryBorder?: BorderStyleInterface;
9
+ }
10
+
11
+ export class ReactionsStyle extends BaseStyle {
12
+ emojiFont?: FontStyle;
13
+ countColor?: string;
14
+ countFont?: FontStyle;
15
+ primaryBackgroundColor?: string;
16
+ primaryBorder?: BorderStyleInterface;
17
+
18
+ constructor({
19
+ height,
20
+ width,
21
+ backgroundColor,
22
+ border,
23
+ borderRadius,
24
+ emojiFont,
25
+ countColor,
26
+ countFont,
27
+ primaryBackgroundColor,
28
+ primaryBorder,
29
+ }: ReactionsStyleInterface) {
30
+ super({
31
+ backgroundColor,
32
+ border,
33
+ borderRadius,
34
+ height,
35
+ width
36
+ })
37
+ this.emojiFont = emojiFont;
38
+ this.countColor = countColor;
39
+ this.countFont = countFont;
40
+ this.primaryBackgroundColor = primaryBackgroundColor;
41
+ this.primaryBorder = primaryBorder;
42
+ }
43
+ }
@@ -0,0 +1,12 @@
1
+ import { CometChatReactions, CometChatReactionsInterface } from './CometChatReactions';
2
+ import { ReactionsConfiguration, ReactionsConfigurationInterface } from './ReactionsConfiguration';
3
+ import { ReactionsStyle, ReactionsStyleInterface } from './ReactionsStyle';
4
+
5
+ export {
6
+ CometChatReactions,
7
+ CometChatReactionsInterface,
8
+ ReactionsConfiguration,
9
+ ReactionsConfigurationInterface,
10
+ ReactionsStyle,
11
+ ReactionsStyleInterface
12
+ };
@@ -2,10 +2,10 @@ import { StyleSheet } from 'react-native';
2
2
 
3
3
  export const Styles = StyleSheet.create({
4
4
  messageReactionListStyle: {
5
- paddingVertical: 8,
5
+ marginTop: -3,
6
6
  flexDirection: 'row',
7
7
  alignItems: 'center',
8
- flexWrap: 'wrap',
8
+ // flexWrap: 'wrap',
9
9
  },
10
10
  reactionListStyle: {
11
11
  alignItems: 'center',
@@ -29,11 +29,11 @@ export const Styles = StyleSheet.create({
29
29
  messageReactionsStyle: {
30
30
  alignItems: 'center',
31
31
  justifyContent: 'center',
32
- paddingVertical: 2,
33
- paddingHorizontal: 4,
34
- marginLeft: 6,
35
- marginBottom: 5,
36
- borderRadius: 11,
32
+ paddingVertical: 4,
33
+ paddingHorizontal: 6,
34
+ marginRight: 2,
35
+ // marginBottom: 5,
36
+ borderRadius: 20,
37
37
  },
38
38
  reactionCountStyle: {
39
39
  paddingRight: 2,
@@ -0,0 +1,335 @@
1
+ import { View, Text, ScrollView, TouchableOpacity, FlatList, Image } from 'react-native'
2
+ import React, { useState, useEffect, useContext, useRef, useCallback } from 'react'
3
+ import { CometChat } from '@cometchat/chat-sdk-react-native';
4
+ import { AvatarStyleInterface } from '../CometChatAvatar';
5
+ import { CometChatListItem, ListItemStyleInterface } from '../CometChatListItem';
6
+ import { CometChatContext } from '../../CometChatContext';
7
+ import { CometChatUIEventHandler, MessageEvents } from '../../events';
8
+ import { messageStatus } from '../../utils/CometChatMessageHelper';
9
+ import { ReactionListStyle, ReactionListStyleInterface } from './ReactionsListStyle';
10
+ import { localize } from '../../resources';
11
+ import { ImageType } from '../../base';
12
+ import { LoadingIcon } from './resources';
13
+ import { CommonUtils } from '../../utils/CommonUtils';
14
+
15
+ export interface CometChatReactionsListInterface {
16
+ messageObject: CometChat.BaseMessage;
17
+ onPress?: (messageReaction: CometChat.Reaction, messageObject: CometChat.BaseMessage) => void;
18
+ reactionRequestBuilder?: CometChat.ReactionsRequestBuilder;
19
+ reactionsListStyle?: ReactionListStyleInterface;
20
+ avatarStyle?: AvatarStyleInterface;
21
+ listItemStyle?: ListItemStyleInterface;
22
+ selectedReaction?: string;
23
+ ErrorStateView?: () => JSX.Element;
24
+ errorStateText?: string;
25
+ loadingIconURL?: ImageType;
26
+ LoadingStateView?: () => JSX.Element;
27
+ }
28
+
29
+ export const CometChatReactionsList = (props: CometChatReactionsListInterface) => {
30
+
31
+ const {
32
+ messageObject, onPress, reactionRequestBuilder, avatarStyle,
33
+ listItemStyle, selectedReaction, reactionsListStyle,
34
+ ErrorStateView,
35
+ errorStateText,
36
+ loadingIconURL,
37
+ LoadingStateView,
38
+ } = props;
39
+ const { theme } = useContext(CometChatContext);
40
+
41
+ const [messageReactions, setMessageReactions] = useState(messageObject?.getReactions() || []);
42
+ const [currentSelectedReaction, setCurrentSelectedReaction] = useState(selectedReaction || "All");
43
+ const [reactionList, setReactionList] = useState([]);
44
+ const [state, setState] = useState<"loading" | "error" | "done">("loading");
45
+ const loggedInUser = useRef<CometChat.User>();
46
+ const newMessageObj = useRef<CometChat.BaseMessage>(CommonUtils.clone(messageObject));
47
+
48
+
49
+ let requestBuilderMap: Record<string, CometChat.ReactionsRequest> = useRef({});
50
+ let reactionListMap: Record<string, CometChat.Reaction[]> = useRef({});
51
+
52
+ const _style = new ReactionListStyle({
53
+ subtitleColor: reactionsListStyle?.subtitleColor || theme.palette.getAccent600(),
54
+ subtitleFont: reactionsListStyle?.subtitleFont || theme.typography.subtitle2,
55
+ activeEmojiBackgroundColor: reactionsListStyle?.activeEmojiBackgroundColor || theme.palette.getAccent100(),
56
+ sliderEmojiCountColor: reactionsListStyle?.sliderEmojiCountColor || theme.palette.getAccent700(),
57
+ tailViewFont: reactionsListStyle?.tailViewFont || theme.typography.title1,
58
+ sliderEmojiCountFont: reactionsListStyle?.sliderEmojiCountFont || theme.typography.subtitle1,
59
+ sliderEmojiFont: reactionsListStyle?.sliderEmojiFont || theme.typography.subtitle1,
60
+ errorTextColor: reactionsListStyle?.errorTextColor || theme?.palette?.getError(),
61
+ errorTextFont: reactionsListStyle?.errorTextFont || theme?.typography?.subtitle1,
62
+ loadingTint: reactionsListStyle?.loadingTint || theme?.palette.getAccent700(),
63
+ separatorColor: reactionsListStyle?.separatorColor || theme.palette.getAccent100(),
64
+ ...reactionsListStyle,
65
+ });
66
+
67
+ const {
68
+ subtitleColor,
69
+ subtitleFont,
70
+ activeEmojiBackgroundColor,
71
+ sliderEmojiCountColor,
72
+ tailViewFont,
73
+ sliderEmojiCountFont,
74
+ sliderEmojiFont,
75
+ errorTextColor,
76
+ errorTextFont,
77
+ loadingTint,
78
+ separatorColor,
79
+ } = _style;
80
+
81
+
82
+ useEffect(() => {
83
+ CometChat.getLoggedinUser()
84
+ .then(user => loggedInUser.current = user)
85
+ .catch(rej => {
86
+ loggedInUser.current = null;
87
+ // onError && onError(rej);
88
+ })
89
+ showReactions(true);
90
+ let newMessageReactions = messageObject?.getReactions() || [];
91
+ _setAllReactions(newMessageReactions);
92
+ }, []);
93
+
94
+ useEffect(() => {
95
+ showReactions();
96
+ }, [currentSelectedReaction])
97
+
98
+ const _setAllReactions = (_messageReactions) => {
99
+ let totalCount = _messageReactions.reduce((acc, curr) => acc + curr.count, 0);
100
+ setMessageReactions([{ reaction: "All", count: totalCount }, ..._messageReactions]);
101
+ }
102
+
103
+
104
+ const showReactions = async (firstFetch?: boolean) => {
105
+ const requestBuilder = getRequestBuilder(currentSelectedReaction);
106
+ const list = await getReactionList(requestBuilder, currentSelectedReaction);
107
+ if (firstFetch && currentSelectedReaction !== "All") {
108
+ await getReactionList(getRequestBuilder("All"), "All");
109
+ }
110
+ setReactionList(list);
111
+ };
112
+
113
+ const getRequestBuilder = (reaction: string): CometChat.ReactionsRequest => {
114
+ let requestBuilder: CometChat.ReactionsRequestBuilder;
115
+ if (requestBuilderMap.current[reaction]) {
116
+ return requestBuilderMap.current[reaction];
117
+ }
118
+
119
+ requestBuilder = reactionRequestBuilder || new CometChat.ReactionsRequestBuilder();
120
+ requestBuilder.setLimit(10).setMessageId(messageObject?.getId());
121
+
122
+ if (reaction !== "All") {
123
+ requestBuilder.setReaction(reaction);
124
+ }
125
+
126
+ const request = requestBuilder.build();
127
+ requestBuilderMap.current[reaction] = request;
128
+ return request;
129
+ };
130
+
131
+ const getReactionList = async (requestBuilder: CometChat.ReactionsRequest, reaction: string) => {
132
+ setState("loading");
133
+
134
+ if (reactionListMap.current[reaction]) {
135
+ setState("done");
136
+ let list = reactionListMap.current[reaction];
137
+ return list;
138
+ }
139
+
140
+ try {
141
+ const list = await requestBuilder.fetchNext();
142
+ reactionListMap.current[reaction] = list;
143
+ setState("done");
144
+ return list;
145
+ } catch (error) {
146
+ console.log("error while fetching reactions", error)
147
+ if (error?.code === "REQUEST_IN_PROGRESS") return;
148
+ setState("error");
149
+ return [];
150
+ }
151
+ };
152
+
153
+ const fetchNext = async () => {
154
+ try {
155
+ const requestBuilder = getRequestBuilder(currentSelectedReaction);
156
+ if (reactionListMap.current[currentSelectedReaction]?.length === 0) {
157
+ return;
158
+ } else {
159
+ const newList = await requestBuilder.fetchNext();
160
+ reactionListMap.current[currentSelectedReaction] = [
161
+ ...(reactionListMap.current?.[currentSelectedReaction] || []),
162
+ ...newList,
163
+ ];
164
+ setReactionList(reactionListMap.current[currentSelectedReaction]);
165
+ }
166
+ setState("done");
167
+ } catch (error) {
168
+ console.log("error while fetching next reactions", error);
169
+ if (error?.code === "REQUEST_IN_PROGRESS") return;
170
+ setState("error");
171
+ }
172
+ };
173
+
174
+ const removeReaction = (reactionObj: CometChat.Reaction) => {
175
+ let reactedByMe = loggedInUser.current.uid === reactionObj?.getReactedBy()?.getUid();
176
+ if (reactedByMe) {
177
+ if (onPress) {
178
+ onPress(reactionObj, newMessageObj.current);
179
+ }
180
+ // const messageId = messageObject?.getId();
181
+ // const emoji = reactionObj?.reaction;
182
+ // CometChat.removeReaction(messageId, emoji)
183
+ // .then((message) => {
184
+ // CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, { message: message, status: messageStatus.success });
185
+
186
+ let newReactionList = [...reactionList]?.filter(reaction => reaction?.id !== reactionObj?.id);
187
+ setReactionList(newReactionList);
188
+
189
+ if (currentSelectedReaction === "All") {
190
+ reactionListMap.current[currentSelectedReaction] = [...newReactionList];
191
+ reactionListMap.current[reactionObj?.reaction] = reactionListMap.current[reactionObj?.reaction]?.filter((reaction: CometChat.Reaction) => reaction?.id !== reactionObj?.id);
192
+ } else {
193
+ reactionListMap.current[currentSelectedReaction] = [...newReactionList];
194
+ reactionListMap.current['All'] = reactionListMap.current['All']?.filter((reaction: CometChat.Reaction) => reaction?.id !== reactionObj?.id);
195
+ }
196
+
197
+ let newMessageReactions = [...messageReactions];
198
+
199
+ let messageReactionIndex = newMessageReactions.findIndex(reaction => reaction?.reaction === reactionObj?.reaction);
200
+ if (messageReactionIndex > -1) {
201
+ if (newMessageReactions[messageReactionIndex]?.getCount() > 1) {
202
+ newMessageReactions[messageReactionIndex].setCount(newMessageReactions[messageReactionIndex].getCount() - 1);
203
+ newMessageReactions[messageReactionIndex].setReactedByMe(false);
204
+ newMessageReactions.shift();
205
+ _setAllReactions(newMessageReactions);
206
+ } else {
207
+ newMessageReactions.splice(messageReactionIndex, 1);
208
+ newMessageReactions.shift();
209
+ _setAllReactions(newMessageReactions);
210
+ setCurrentSelectedReaction("All");
211
+ }
212
+ }
213
+
214
+ newMessageObj.current.setReactions(newMessageReactions);
215
+
216
+ // })
217
+ // .catch(err => console.log("Some error occured in removing reaction", err));
218
+ }
219
+ };
220
+
221
+ const subtitleView = useCallback((item) => {
222
+ let reactedByMe = loggedInUser.current.uid === item?.reactedBy?.uid;
223
+ return (reactedByMe ?
224
+ <Text style={[{ color: subtitleColor }, subtitleFont]}>
225
+ {localize("TAP_TO_REMOVE")}
226
+ </Text>
227
+ : null
228
+ )
229
+ }, []);
230
+
231
+ const _render = ({ item, index }) => {
232
+
233
+ function getName() {
234
+ let reactedByMe = loggedInUser.current.uid === item?.reactedBy?.uid;
235
+ return reactedByMe ? localize("YOU") : item?.reactedBy?.name;
236
+ }
237
+
238
+ return (
239
+ <>
240
+ <CometChatListItem
241
+ id={item?.id || index}
242
+ title={getName()}
243
+ avatarStyle={avatarStyle}
244
+ avatarName={item?.reactedBy?.name}
245
+ avatarURL={item?.reactedBy?.avatar ? { uri: item?.reactedBy?.avatar } : undefined}
246
+ SubtitleView={() => subtitleView(item)}
247
+ TailView={() => <Text style={[tailViewFont, { color: theme?.palette?.getPrimary() }]}>{item?.reaction}</Text>}
248
+ listItemStyle={{ height: 60, ...listItemStyle }}
249
+ onPress={(id) => removeReaction(item)}
250
+ />
251
+ <View
252
+ style={{
253
+ height: 1,
254
+ backgroundColor: separatorColor
255
+ }}
256
+ />
257
+ </>
258
+ )
259
+ };
260
+
261
+
262
+ const ErrorView = () => {
263
+ if (ErrorStateView)
264
+ return <ErrorStateView />
265
+ return <View style={{
266
+ marginTop: 100,
267
+ justifyContent: "center",
268
+ alignItems: "center",
269
+ }}>
270
+ <Text style={[{ color: errorTextColor, ...errorTextFont }]}>{errorStateText || localize("SOMETHING_WRONG")}</Text>
271
+ </View>
272
+ }
273
+
274
+ const LoadingView = () => {
275
+ if (LoadingStateView)
276
+ return <LoadingStateView />
277
+ return <View style={{
278
+ marginTop: 100,
279
+ justifyContent: "center",
280
+ alignItems: "center",
281
+ }}>
282
+ <Image source={loadingIconURL || LoadingIcon} style={[{
283
+ height: 24, width: 24, alignSelf: "center", tintColor: loadingTint
284
+ }]} />
285
+ </View>
286
+ }
287
+
288
+ return (
289
+ <View>
290
+
291
+ {/* Slider for reactions */}
292
+ <ScrollView style={{ paddingBottom: 5 }}
293
+ contentContainerStyle={{
294
+ paddingLeft: 5,
295
+ }}
296
+ showsHorizontalScrollIndicator={false} horizontal={true}>
297
+ {messageReactions?.length > 0 && messageReactions.map((reactionObject, index) => (
298
+ <TouchableOpacity style={[{
299
+ paddingHorizontal: 10,
300
+ flexDirection: "row", marginRight: 5,
301
+ backgroundColor: currentSelectedReaction === reactionObject?.reaction ? activeEmojiBackgroundColor : undefined,
302
+ borderRadius: 20,
303
+ alignItems: "center", justifyContent: "center"
304
+ }]} key={index} onPress={() => setCurrentSelectedReaction(reactionObject?.reaction)}>
305
+ <Text style={[{
306
+ borderWidth: .5,
307
+ borderColor: "transparent",
308
+ paddingVertical: 5,
309
+ marginRight: 4, color: reactionObject?.reaction === "All" ? sliderEmojiCountColor : theme?.palette?.getPrimary()
310
+ }, sliderEmojiFont]}>{reactionObject?.reaction === "All" ? localize("ALL") : reactionObject?.reaction}</Text>
311
+ <Text style={[{ color: sliderEmojiCountColor }, sliderEmojiCountFont]}>{reactionObject?.count}</Text>
312
+ </TouchableOpacity>
313
+ ))}
314
+ </ScrollView>
315
+
316
+ {state === "error" ? <ErrorView /> : state === "loading" ? <LoadingView /> :
317
+ <FlatList
318
+ data={reactionList}
319
+ keyExtractor={(item, index) => index.toString()}
320
+ renderItem={_render}
321
+ onEndReached={({ distanceFromEnd }) => {
322
+ if (distanceFromEnd < 0) return;
323
+ fetchNext();
324
+ }}
325
+ onEndReachedThreshold={0.1}
326
+ contentContainerStyle={{
327
+ paddingBottom: 25,
328
+ paddingHorizontal: 5,
329
+ }}
330
+ />}
331
+
332
+ </View>
333
+ );
334
+ };
335
+
@@ -0,0 +1,14 @@
1
+ import { CometChatReactionsListInterface } from './CometChatReactionsList';
2
+
3
+ export interface ReactionsListConfigurationInterface extends Omit<CometChatReactionsListInterface,
4
+ 'messageObject' | 'errorStateText'
5
+ > { }
6
+
7
+ export class ReactionsListConfiguration {
8
+ constructor(props: ReactionsListConfigurationInterface) {
9
+ if (props)
10
+ for (const [key, value] of Object.entries(props)) {
11
+ this[key] = value;
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,67 @@
1
+ import { BaseStyle, FontStyle } from "../../base";
2
+
3
+ export interface ReactionListStyleInterface extends BaseStyle {
4
+ subtitleColor?: string;
5
+ subtitleFont?: FontStyle;
6
+ tailViewFont?: FontStyle;
7
+ activeEmojiBackgroundColor?: string;
8
+ sliderEmojiCountFont?: FontStyle;
9
+ sliderEmojiCountColor?: string;
10
+ sliderEmojiFont?: FontStyle;
11
+ errorTextColor?: string;
12
+ errorTextFont?: FontStyle;
13
+ loadingTint?: string;
14
+ separatorColor?: string;
15
+ }
16
+
17
+ export class ReactionListStyle extends BaseStyle {
18
+ subtitleColor?: string;
19
+ subtitleFont?: FontStyle;
20
+ tailViewFont?: FontStyle;
21
+ activeEmojiBackgroundColor?: string;
22
+ sliderEmojiCountFont?: FontStyle;
23
+ sliderEmojiCountColor?: string;
24
+ sliderEmojiFont?: FontStyle;
25
+ errorTextColor?: string;
26
+ errorTextFont?: FontStyle;
27
+ loadingTint?: string;
28
+ separatorColor?: string;
29
+
30
+ constructor({
31
+ height,
32
+ width,
33
+ backgroundColor,
34
+ border,
35
+ borderRadius,
36
+ subtitleColor,
37
+ subtitleFont,
38
+ tailViewFont,
39
+ activeEmojiBackgroundColor,
40
+ sliderEmojiCountFont,
41
+ sliderEmojiCountColor,
42
+ sliderEmojiFont,
43
+ errorTextColor,
44
+ errorTextFont,
45
+ loadingTint,
46
+ separatorColor
47
+ }: ReactionListStyleInterface) {
48
+ super({
49
+ backgroundColor,
50
+ border,
51
+ borderRadius,
52
+ height,
53
+ width
54
+ })
55
+ this.subtitleColor = subtitleColor;
56
+ this.subtitleFont = subtitleFont;
57
+ this.tailViewFont = tailViewFont;
58
+ this.activeEmojiBackgroundColor = activeEmojiBackgroundColor;
59
+ this.sliderEmojiCountFont = sliderEmojiCountFont;
60
+ this.sliderEmojiCountColor = sliderEmojiCountColor;
61
+ this.sliderEmojiFont = sliderEmojiFont;
62
+ this.errorTextColor = errorTextColor;
63
+ this.errorTextFont = errorTextFont;
64
+ this.loadingTint = loadingTint;
65
+ this.separatorColor = separatorColor;
66
+ }
67
+ }