@sendbird/uikit-react-native 1.0.2 → 1.1.0

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 (172) hide show
  1. package/README.md +7 -7
  2. package/lib/commonjs/SendbirdUIKitContainer.js +5 -2
  3. package/lib/commonjs/SendbirdUIKitContainer.js.map +1 -1
  4. package/lib/commonjs/components/FileViewer.js +326 -0
  5. package/lib/commonjs/components/FileViewer.js.map +1 -0
  6. package/lib/commonjs/components/GroupChannelPreviewContainer.js +180 -0
  7. package/lib/commonjs/components/GroupChannelPreviewContainer.js.map +1 -0
  8. package/lib/commonjs/components/MessageRenderer/FileMessage/VideoFileMessage.js +116 -0
  9. package/lib/commonjs/components/MessageRenderer/FileMessage/VideoFileMessage.js.map +1 -0
  10. package/lib/commonjs/components/MessageRenderer/FileMessage/index.js +8 -0
  11. package/lib/commonjs/components/MessageRenderer/FileMessage/index.js.map +1 -1
  12. package/lib/commonjs/components/MessageRenderer/MessageOutgoingStatus.js +15 -24
  13. package/lib/commonjs/components/MessageRenderer/MessageOutgoingStatus.js.map +1 -1
  14. package/lib/commonjs/components/SBUPressable.js +45 -0
  15. package/lib/commonjs/components/SBUPressable.js.map +1 -0
  16. package/lib/commonjs/components/UserActionBar.js +1 -3
  17. package/lib/commonjs/components/UserActionBar.js.map +1 -1
  18. package/lib/commonjs/components/UserSelectableBar.js +1 -3
  19. package/lib/commonjs/components/UserSelectableBar.js.map +1 -1
  20. package/lib/commonjs/constants.js +7 -1
  21. package/lib/commonjs/constants.js.map +1 -1
  22. package/lib/commonjs/contexts/PlatformService.js +4 -2
  23. package/lib/commonjs/contexts/PlatformService.js.map +1 -1
  24. package/lib/commonjs/contexts/SendbirdChat.js +6 -2
  25. package/lib/commonjs/contexts/SendbirdChat.js.map +1 -1
  26. package/lib/commonjs/domain/groupChannel/component/GroupChannelInput/SendInput.js +1 -1
  27. package/lib/commonjs/domain/groupChannel/component/GroupChannelInput/SendInput.js.map +1 -1
  28. package/lib/commonjs/domain/groupChannel/component/GroupChannelMessageList.js +30 -7
  29. package/lib/commonjs/domain/groupChannel/component/GroupChannelMessageList.js.map +1 -1
  30. package/lib/commonjs/domain/groupChannel/module/moduleContext.js +2 -3
  31. package/lib/commonjs/domain/groupChannel/module/moduleContext.js.map +1 -1
  32. package/lib/commonjs/domain/groupChannel/types.js.map +1 -1
  33. package/lib/commonjs/domain/groupChannelList/types.js.map +1 -1
  34. package/lib/commonjs/domain/groupChannelSettings/module/moduleContext.js +1 -1
  35. package/lib/commonjs/domain/groupChannelSettings/module/moduleContext.js.map +1 -1
  36. package/lib/commonjs/fragments/createGroupChannelCreateFragment.js +3 -7
  37. package/lib/commonjs/fragments/createGroupChannelCreateFragment.js.map +1 -1
  38. package/lib/commonjs/fragments/createGroupChannelFragment.js +13 -11
  39. package/lib/commonjs/fragments/createGroupChannelFragment.js.map +1 -1
  40. package/lib/commonjs/fragments/createGroupChannelListFragment.js +7 -37
  41. package/lib/commonjs/fragments/createGroupChannelListFragment.js.map +1 -1
  42. package/lib/commonjs/fragments/createGroupChannelMembersFragment.js +1 -1
  43. package/lib/commonjs/fragments/createGroupChannelMembersFragment.js.map +1 -1
  44. package/lib/commonjs/hooks/useContext.js.map +1 -1
  45. package/lib/commonjs/index.js +29 -2
  46. package/lib/commonjs/index.js.map +1 -1
  47. package/lib/commonjs/localization/StringSet.type.js +8 -0
  48. package/lib/commonjs/localization/StringSet.type.js.map +1 -1
  49. package/lib/commonjs/platform/createFileService.expo.js +21 -2
  50. package/lib/commonjs/platform/createFileService.expo.js.map +1 -1
  51. package/lib/commonjs/platform/createFileService.native.js +20 -3
  52. package/lib/commonjs/platform/createFileService.native.js.map +1 -1
  53. package/lib/commonjs/platform/createMediaService.expo.js +64 -0
  54. package/lib/commonjs/platform/createMediaService.expo.js.map +1 -0
  55. package/lib/commonjs/platform/createMediaService.native.js +67 -0
  56. package/lib/commonjs/platform/createMediaService.native.js.map +1 -0
  57. package/lib/commonjs/platform/createNotificationService.expo.js.map +1 -1
  58. package/lib/commonjs/platform/types.js.map +1 -1
  59. package/lib/commonjs/version.js +1 -1
  60. package/lib/commonjs/version.js.map +1 -1
  61. package/lib/module/SendbirdUIKitContainer.js +5 -2
  62. package/lib/module/SendbirdUIKitContainer.js.map +1 -1
  63. package/lib/module/components/FileViewer.js +304 -0
  64. package/lib/module/components/FileViewer.js.map +1 -0
  65. package/lib/module/components/GroupChannelPreviewContainer.js +158 -0
  66. package/lib/module/components/GroupChannelPreviewContainer.js.map +1 -0
  67. package/lib/module/components/MessageRenderer/FileMessage/VideoFileMessage.js +100 -0
  68. package/lib/module/components/MessageRenderer/FileMessage/VideoFileMessage.js.map +1 -0
  69. package/lib/module/components/MessageRenderer/FileMessage/index.js +6 -0
  70. package/lib/module/components/MessageRenderer/FileMessage/index.js.map +1 -1
  71. package/lib/module/components/MessageRenderer/MessageOutgoingStatus.js +17 -26
  72. package/lib/module/components/MessageRenderer/MessageOutgoingStatus.js.map +1 -1
  73. package/lib/module/components/SBUPressable.js +33 -0
  74. package/lib/module/components/SBUPressable.js.map +1 -0
  75. package/lib/module/components/UserActionBar.js +1 -1
  76. package/lib/module/components/UserActionBar.js.map +1 -1
  77. package/lib/module/components/UserSelectableBar.js +1 -1
  78. package/lib/module/components/UserSelectableBar.js.map +1 -1
  79. package/lib/module/constants.js +5 -0
  80. package/lib/module/constants.js.map +1 -1
  81. package/lib/module/contexts/PlatformService.js +4 -2
  82. package/lib/module/contexts/PlatformService.js.map +1 -1
  83. package/lib/module/contexts/SendbirdChat.js +6 -2
  84. package/lib/module/contexts/SendbirdChat.js.map +1 -1
  85. package/lib/module/domain/groupChannel/component/GroupChannelInput/SendInput.js +1 -1
  86. package/lib/module/domain/groupChannel/component/GroupChannelInput/SendInput.js.map +1 -1
  87. package/lib/module/domain/groupChannel/component/GroupChannelMessageList.js +28 -7
  88. package/lib/module/domain/groupChannel/component/GroupChannelMessageList.js.map +1 -1
  89. package/lib/module/domain/groupChannel/module/moduleContext.js +2 -3
  90. package/lib/module/domain/groupChannel/module/moduleContext.js.map +1 -1
  91. package/lib/module/domain/groupChannel/types.js.map +1 -1
  92. package/lib/module/domain/groupChannelList/types.js.map +1 -1
  93. package/lib/module/domain/groupChannelSettings/module/moduleContext.js +1 -1
  94. package/lib/module/domain/groupChannelSettings/module/moduleContext.js.map +1 -1
  95. package/lib/module/fragments/createGroupChannelCreateFragment.js +4 -4
  96. package/lib/module/fragments/createGroupChannelCreateFragment.js.map +1 -1
  97. package/lib/module/fragments/createGroupChannelFragment.js +15 -13
  98. package/lib/module/fragments/createGroupChannelFragment.js.map +1 -1
  99. package/lib/module/fragments/createGroupChannelListFragment.js +11 -38
  100. package/lib/module/fragments/createGroupChannelListFragment.js.map +1 -1
  101. package/lib/module/fragments/createGroupChannelMembersFragment.js +1 -1
  102. package/lib/module/fragments/createGroupChannelMembersFragment.js.map +1 -1
  103. package/lib/module/hooks/useContext.js.map +1 -1
  104. package/lib/module/index.js +4 -1
  105. package/lib/module/index.js.map +1 -1
  106. package/lib/module/localization/StringSet.type.js +8 -0
  107. package/lib/module/localization/StringSet.type.js.map +1 -1
  108. package/lib/module/platform/createFileService.expo.js +21 -2
  109. package/lib/module/platform/createFileService.expo.js.map +1 -1
  110. package/lib/module/platform/createFileService.native.js +20 -3
  111. package/lib/module/platform/createFileService.native.js.map +1 -1
  112. package/lib/module/platform/createMediaService.expo.js +54 -0
  113. package/lib/module/platform/createMediaService.expo.js.map +1 -0
  114. package/lib/module/platform/createMediaService.native.js +57 -0
  115. package/lib/module/platform/createMediaService.native.js.map +1 -0
  116. package/lib/module/platform/createNotificationService.expo.js.map +1 -1
  117. package/lib/module/platform/types.js.map +1 -1
  118. package/lib/module/version.js +1 -1
  119. package/lib/module/version.js.map +1 -1
  120. package/lib/typescript/src/SendbirdUIKitContainer.d.ts +7 -3
  121. package/lib/typescript/src/components/FileViewer.d.ts +12 -0
  122. package/lib/typescript/src/components/GroupChannelPreviewContainer.d.ts +8 -0
  123. package/lib/typescript/src/components/MessageRenderer/FileMessage/VideoFileMessage.d.ts +3 -0
  124. package/lib/typescript/src/components/SBUPressable.d.ts +18 -0
  125. package/lib/typescript/src/components/UserActionBar.d.ts +2 -3
  126. package/lib/typescript/src/components/UserSelectableBar.d.ts +2 -3
  127. package/lib/typescript/src/constants.d.ts +5 -0
  128. package/lib/typescript/src/contexts/PlatformService.d.ts +3 -2
  129. package/lib/typescript/src/contexts/SendbirdChat.d.ts +5 -1
  130. package/lib/typescript/src/domain/groupChannel/component/GroupChannelMessageList.d.ts +3 -2
  131. package/lib/typescript/src/domain/groupChannel/types.d.ts +6 -2
  132. package/lib/typescript/src/hooks/useContext.d.ts +7 -5
  133. package/lib/typescript/src/index.d.ts +3 -0
  134. package/lib/typescript/src/localization/StringSet.type.d.ts +4 -0
  135. package/lib/typescript/src/platform/createMediaService.expo.d.ts +9 -0
  136. package/lib/typescript/src/platform/createMediaService.native.d.ts +9 -0
  137. package/lib/typescript/src/platform/createNotificationService.expo.d.ts +1 -1
  138. package/lib/typescript/src/platform/types.d.ts +20 -1
  139. package/lib/typescript/src/version.d.ts +1 -1
  140. package/package.json +14 -5
  141. package/src/SendbirdUIKitContainer.tsx +14 -2
  142. package/src/components/FileViewer.tsx +284 -0
  143. package/src/components/GroupChannelPreviewContainer.tsx +134 -0
  144. package/src/components/MessageRenderer/FileMessage/VideoFileMessage.tsx +91 -0
  145. package/src/components/MessageRenderer/FileMessage/index.tsx +6 -0
  146. package/src/components/MessageRenderer/MessageOutgoingStatus.tsx +25 -32
  147. package/src/components/SBUPressable.tsx +40 -0
  148. package/src/components/UserActionBar.tsx +1 -1
  149. package/src/components/UserSelectableBar.tsx +1 -1
  150. package/src/constants.ts +5 -0
  151. package/src/contexts/PlatformService.tsx +15 -3
  152. package/src/contexts/SendbirdChat.tsx +13 -5
  153. package/src/domain/groupChannel/component/GroupChannelInput/SendInput.tsx +1 -1
  154. package/src/domain/groupChannel/component/GroupChannelMessageList.tsx +23 -6
  155. package/src/domain/groupChannel/module/moduleContext.tsx +6 -13
  156. package/src/domain/groupChannel/types.ts +8 -2
  157. package/src/domain/groupChannelList/types.ts +1 -0
  158. package/src/domain/groupChannelSettings/module/moduleContext.tsx +5 -10
  159. package/src/fragments/createGroupChannelCreateFragment.tsx +38 -41
  160. package/src/fragments/createGroupChannelFragment.tsx +23 -33
  161. package/src/fragments/createGroupChannelListFragment.tsx +10 -32
  162. package/src/fragments/createGroupChannelMembersFragment.tsx +34 -39
  163. package/src/hooks/useContext.ts +3 -5
  164. package/src/index.ts +5 -1
  165. package/src/localization/StringSet.type.ts +8 -0
  166. package/src/platform/createFileService.expo.ts +17 -2
  167. package/src/platform/createFileService.native.ts +16 -3
  168. package/src/platform/createMediaService.expo.tsx +30 -0
  169. package/src/platform/createMediaService.native.tsx +37 -0
  170. package/src/platform/createNotificationService.expo.ts +1 -1
  171. package/src/platform/types.ts +26 -1
  172. package/src/version.ts +1 -1
@@ -0,0 +1,304 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { StatusBar, StyleSheet, View } from 'react-native';
3
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
4
+ import { Icon, Image, LoadingSpinner, Text, createStyleSheet, useAlert, useHeaderStyle, useToast, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
5
+ import { Logger, getFileExtension, getFileType, isMyMessage, toMegabyte, useIIFE } from '@sendbird/uikit-utils';
6
+ import { useLocalization, usePlatformService, useSendbirdChat } from '../hooks/useContext';
7
+ import SBUPressable from './SBUPressable';
8
+
9
+ const FileViewer = _ref => {
10
+ let {
11
+ headerShown = true,
12
+ deleteMessage,
13
+ headerTopInset,
14
+ fileMessage,
15
+ onPressDownload,
16
+ onPressDelete,
17
+ onClose
18
+ } = _ref;
19
+ const [loading, setLoading] = useState(true);
20
+ const {
21
+ bottom
22
+ } = useSafeAreaInsets();
23
+ const {
24
+ currentUser
25
+ } = useSendbirdChat();
26
+ const {
27
+ palette
28
+ } = useUIKitTheme();
29
+ const {
30
+ topInset,
31
+ statusBarTranslucent,
32
+ defaultHeight
33
+ } = useHeaderStyle();
34
+ const {
35
+ STRINGS
36
+ } = useLocalization();
37
+ const {
38
+ fileService,
39
+ mediaService
40
+ } = usePlatformService();
41
+ const toast = useToast();
42
+ const {
43
+ alert
44
+ } = useAlert();
45
+ const basicTopInset = statusBarTranslucent ? topInset : 0;
46
+ const canDelete = isMyMessage(fileMessage, currentUser === null || currentUser === void 0 ? void 0 : currentUser.userId);
47
+ const fileType = getFileType(fileMessage.type || getFileExtension(fileMessage.url));
48
+ useEffect(() => {
49
+ if (!(mediaService !== null && mediaService !== void 0 && mediaService.VideoComponent) || fileType === 'file') {
50
+ onClose();
51
+ }
52
+ }, [mediaService]);
53
+ const fileViewer = useIIFE(() => {
54
+ switch (fileType) {
55
+ case 'image':
56
+ {
57
+ return /*#__PURE__*/React.createElement(Image, {
58
+ source: {
59
+ uri: fileMessage.url
60
+ },
61
+ style: StyleSheet.absoluteFill,
62
+ resizeMode: 'contain',
63
+ onLoadEnd: () => setLoading(false)
64
+ });
65
+ }
66
+
67
+ case 'video':
68
+ case 'audio':
69
+ {
70
+ if (!(mediaService !== null && mediaService !== void 0 && mediaService.VideoComponent)) return null;
71
+ return /*#__PURE__*/React.createElement(mediaService.VideoComponent, {
72
+ source: {
73
+ uri: fileMessage.url
74
+ },
75
+ style: [StyleSheet.absoluteFill, {
76
+ top: basicTopInset + defaultHeight,
77
+ bottom: defaultHeight + bottom
78
+ }],
79
+ resizeMode: 'contain',
80
+ onLoad: () => setLoading(false)
81
+ });
82
+ }
83
+
84
+ default:
85
+ {
86
+ return null;
87
+ }
88
+ }
89
+ });
90
+
91
+ const _onPressDelete = () => {
92
+ if (!canDelete) return;
93
+
94
+ if (onPressDelete) {
95
+ onPressDelete(fileMessage);
96
+ } else {
97
+ alert({
98
+ title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_TITLE,
99
+ buttons: [{
100
+ text: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_CANCEL
101
+ }, {
102
+ text: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_OK,
103
+ style: 'destructive',
104
+ onPress: () => {
105
+ deleteMessage().then(() => {
106
+ onClose();
107
+ }).catch(() => {
108
+ toast.show(STRINGS.TOAST.DELETE_MSG_ERROR, 'error');
109
+ });
110
+ }
111
+ }]
112
+ });
113
+ }
114
+ };
115
+
116
+ const _onPressDownload = () => {
117
+ if (onPressDownload) {
118
+ onPressDownload(fileMessage);
119
+ } else {
120
+ if (toMegabyte(fileMessage.size) > 4) {
121
+ toast.show(STRINGS.TOAST.DOWNLOAD_START, 'success');
122
+ }
123
+
124
+ fileService.save({
125
+ fileUrl: fileMessage.url,
126
+ fileName: fileMessage.name,
127
+ fileType: fileMessage.type
128
+ }).then(response => {
129
+ toast.show(STRINGS.TOAST.DOWNLOAD_OK, 'success');
130
+ Logger.log('File saved to', response);
131
+ }).catch(err => {
132
+ toast.show(STRINGS.TOAST.DOWNLOAD_ERROR, 'error');
133
+ Logger.log('File save failure', err);
134
+ });
135
+ }
136
+ };
137
+
138
+ return /*#__PURE__*/React.createElement(View, {
139
+ style: {
140
+ flex: 1,
141
+ backgroundColor: palette.background700
142
+ }
143
+ }, /*#__PURE__*/React.createElement(StatusBar, {
144
+ barStyle: 'light-content',
145
+ animated: true
146
+ }), /*#__PURE__*/React.createElement(View, {
147
+ style: {
148
+ flex: 1,
149
+ alignItems: 'center',
150
+ justifyContent: 'center'
151
+ }
152
+ }, fileViewer, loading && /*#__PURE__*/React.createElement(LoadingSpinner, {
153
+ style: {
154
+ position: 'absolute'
155
+ },
156
+ size: 40,
157
+ color: palette.primary300
158
+ })), headerShown && /*#__PURE__*/React.createElement(FileViewerHeader, {
159
+ title: STRINGS.FILE_VIEWER.TITLE(fileMessage),
160
+ subtitle: STRINGS.FILE_VIEWER.SUBTITLE(fileMessage),
161
+ topInset: headerTopInset ?? basicTopInset,
162
+ onClose: onClose
163
+ }), /*#__PURE__*/React.createElement(FileViewerFooter, {
164
+ bottomInset: bottom,
165
+ deleteShown: canDelete,
166
+ onPressDelete: _onPressDelete,
167
+ onPressDownload: _onPressDownload
168
+ }));
169
+ };
170
+
171
+ const FileViewerHeader = _ref2 => {
172
+ let {
173
+ topInset,
174
+ onClose,
175
+ subtitle,
176
+ title
177
+ } = _ref2;
178
+ const {
179
+ palette
180
+ } = useUIKitTheme();
181
+ const {
182
+ defaultHeight
183
+ } = useHeaderStyle();
184
+ const {
185
+ left,
186
+ right
187
+ } = useSafeAreaInsets();
188
+ return /*#__PURE__*/React.createElement(View, {
189
+ style: [styles.headerContainer, {
190
+ paddingLeft: styles.headerContainer.paddingHorizontal + left,
191
+ paddingRight: styles.headerContainer.paddingHorizontal + right
192
+ }, {
193
+ paddingTop: topInset,
194
+ height: defaultHeight + topInset,
195
+ backgroundColor: palette.overlay01
196
+ }]
197
+ }, /*#__PURE__*/React.createElement(SBUPressable, {
198
+ as: 'TouchableOpacity',
199
+ onPress: onClose,
200
+ style: styles.barButton
201
+ }, /*#__PURE__*/React.createElement(Icon, {
202
+ icon: 'close',
203
+ size: 24,
204
+ color: palette.onBackgroundDark01
205
+ })), /*#__PURE__*/React.createElement(View, {
206
+ style: styles.barTitleContainer
207
+ }, /*#__PURE__*/React.createElement(Text, {
208
+ h2: true,
209
+ color: palette.onBackgroundDark01,
210
+ style: styles.headerTitle
211
+ }, title), /*#__PURE__*/React.createElement(Text, {
212
+ caption2: true,
213
+ color: palette.onBackgroundDark01
214
+ }, subtitle)), /*#__PURE__*/React.createElement(View, {
215
+ style: styles.barButton
216
+ }));
217
+ };
218
+
219
+ const FileViewerFooter = _ref3 => {
220
+ let {
221
+ bottomInset,
222
+ deleteShown,
223
+ onPressDelete,
224
+ onPressDownload
225
+ } = _ref3;
226
+ const {
227
+ palette
228
+ } = useUIKitTheme();
229
+ const {
230
+ defaultHeight
231
+ } = useHeaderStyle();
232
+ const {
233
+ left,
234
+ right
235
+ } = useSafeAreaInsets();
236
+ return /*#__PURE__*/React.createElement(View, {
237
+ style: [styles.footerContainer, {
238
+ paddingLeft: styles.headerContainer.paddingHorizontal + left,
239
+ paddingRight: styles.headerContainer.paddingHorizontal + right
240
+ }, {
241
+ paddingBottom: bottomInset,
242
+ height: defaultHeight + bottomInset,
243
+ backgroundColor: palette.overlay01
244
+ }]
245
+ }, /*#__PURE__*/React.createElement(SBUPressable, {
246
+ as: 'TouchableOpacity',
247
+ onPress: onPressDownload,
248
+ style: styles.barButton
249
+ }, /*#__PURE__*/React.createElement(Icon, {
250
+ icon: 'download',
251
+ size: 24,
252
+ color: palette.onBackgroundDark01
253
+ })), /*#__PURE__*/React.createElement(View, {
254
+ style: styles.barTitleContainer
255
+ }), /*#__PURE__*/React.createElement(SBUPressable, {
256
+ as: 'TouchableOpacity',
257
+ onPress: onPressDelete,
258
+ style: styles.barButton,
259
+ disabled: !deleteShown
260
+ }, deleteShown && /*#__PURE__*/React.createElement(Icon, {
261
+ icon: 'delete',
262
+ size: 24,
263
+ color: palette.onBackgroundDark01
264
+ })));
265
+ };
266
+
267
+ const styles = createStyleSheet({
268
+ headerContainer: {
269
+ top: 0,
270
+ left: 0,
271
+ right: 0,
272
+ position: 'absolute',
273
+ flexDirection: 'row',
274
+ alignItems: 'center',
275
+ justifyContent: 'center',
276
+ paddingHorizontal: 12
277
+ },
278
+ barButton: {
279
+ width: 32,
280
+ height: 32,
281
+ alignItems: 'center',
282
+ justifyContent: 'center'
283
+ },
284
+ barTitleContainer: {
285
+ flex: 1,
286
+ alignItems: 'center',
287
+ justifyContent: 'center'
288
+ },
289
+ headerTitle: {
290
+ marginBottom: 2
291
+ },
292
+ footerContainer: {
293
+ position: 'absolute',
294
+ left: 0,
295
+ right: 0,
296
+ bottom: 0,
297
+ flexDirection: 'row',
298
+ alignItems: 'center',
299
+ justifyContent: 'center',
300
+ paddingHorizontal: 12
301
+ }
302
+ });
303
+ export default FileViewer;
304
+ //# sourceMappingURL=FileViewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useEffect","useState","StatusBar","StyleSheet","View","useSafeAreaInsets","Icon","Image","LoadingSpinner","Text","createStyleSheet","useAlert","useHeaderStyle","useToast","useUIKitTheme","Logger","getFileExtension","getFileType","isMyMessage","toMegabyte","useIIFE","useLocalization","usePlatformService","useSendbirdChat","SBUPressable","FileViewer","headerShown","deleteMessage","headerTopInset","fileMessage","onPressDownload","onPressDelete","onClose","loading","setLoading","bottom","currentUser","palette","topInset","statusBarTranslucent","defaultHeight","STRINGS","fileService","mediaService","toast","alert","basicTopInset","canDelete","userId","fileType","type","url","VideoComponent","fileViewer","uri","absoluteFill","top","_onPressDelete","title","GROUP_CHANNEL","DIALOG_MESSAGE_DELETE_CONFIRM_TITLE","buttons","text","DIALOG_MESSAGE_DELETE_CONFIRM_CANCEL","DIALOG_MESSAGE_DELETE_CONFIRM_OK","style","onPress","then","catch","show","TOAST","DELETE_MSG_ERROR","_onPressDownload","size","DOWNLOAD_START","save","fileUrl","fileName","name","response","DOWNLOAD_OK","log","err","DOWNLOAD_ERROR","flex","backgroundColor","background700","alignItems","justifyContent","position","primary300","FILE_VIEWER","TITLE","SUBTITLE","FileViewerHeader","subtitle","left","right","styles","headerContainer","paddingLeft","paddingHorizontal","paddingRight","paddingTop","height","overlay01","barButton","onBackgroundDark01","barTitleContainer","headerTitle","FileViewerFooter","bottomInset","deleteShown","footerContainer","paddingBottom","flexDirection","width","marginBottom"],"sources":["FileViewer.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport { StatusBar, StyleSheet, View } from 'react-native';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\n\nimport {\n Icon,\n Image,\n LoadingSpinner,\n Text,\n createStyleSheet,\n useAlert,\n useHeaderStyle,\n useToast,\n useUIKitTheme,\n} from '@sendbird/uikit-react-native-foundation';\nimport type { SendbirdFileMessage } from '@sendbird/uikit-utils';\nimport { Logger, getFileExtension, getFileType, isMyMessage, toMegabyte, useIIFE } from '@sendbird/uikit-utils';\n\nimport { useLocalization, usePlatformService, useSendbirdChat } from '../hooks/useContext';\nimport SBUPressable from './SBUPressable';\n\ntype Props = {\n fileMessage: SendbirdFileMessage;\n deleteMessage: () => Promise<void>;\n\n onClose: () => void;\n onPressDownload?: (message: SendbirdFileMessage) => void;\n onPressDelete?: (message: SendbirdFileMessage) => void;\n\n headerShown?: boolean;\n headerTopInset?: number;\n};\nconst FileViewer = ({\n headerShown = true,\n deleteMessage,\n headerTopInset,\n fileMessage,\n onPressDownload,\n onPressDelete,\n onClose,\n}: Props) => {\n const [loading, setLoading] = useState(true);\n\n const { bottom } = useSafeAreaInsets();\n\n const { currentUser } = useSendbirdChat();\n const { palette } = useUIKitTheme();\n const { topInset, statusBarTranslucent, defaultHeight } = useHeaderStyle();\n const { STRINGS } = useLocalization();\n const { fileService, mediaService } = usePlatformService();\n const toast = useToast();\n const { alert } = useAlert();\n\n const basicTopInset = statusBarTranslucent ? topInset : 0;\n const canDelete = isMyMessage(fileMessage, currentUser?.userId);\n const fileType = getFileType(fileMessage.type || getFileExtension(fileMessage.url));\n\n useEffect(() => {\n if (!mediaService?.VideoComponent || fileType === 'file') {\n onClose();\n }\n }, [mediaService]);\n\n const fileViewer = useIIFE(() => {\n switch (fileType) {\n case 'image': {\n return (\n <Image\n source={{ uri: fileMessage.url }}\n style={StyleSheet.absoluteFill}\n resizeMode={'contain'}\n onLoadEnd={() => setLoading(false)}\n />\n );\n }\n\n case 'video':\n case 'audio': {\n if (!mediaService?.VideoComponent) return null;\n return (\n <mediaService.VideoComponent\n source={{ uri: fileMessage.url }}\n style={[StyleSheet.absoluteFill, { top: basicTopInset + defaultHeight, bottom: defaultHeight + bottom }]}\n resizeMode={'contain'}\n onLoad={() => setLoading(false)}\n />\n );\n }\n\n default: {\n return null;\n }\n }\n });\n\n const _onPressDelete = () => {\n if (!canDelete) return;\n\n if (onPressDelete) {\n onPressDelete(fileMessage);\n } else {\n alert({\n title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_TITLE,\n buttons: [\n {\n text: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_CANCEL,\n },\n {\n text: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_OK,\n style: 'destructive',\n onPress: () => {\n deleteMessage()\n .then(() => {\n onClose();\n })\n .catch(() => {\n toast.show(STRINGS.TOAST.DELETE_MSG_ERROR, 'error');\n });\n },\n },\n ],\n });\n }\n };\n\n const _onPressDownload = () => {\n if (onPressDownload) {\n onPressDownload(fileMessage);\n } else {\n if (toMegabyte(fileMessage.size) > 4) {\n toast.show(STRINGS.TOAST.DOWNLOAD_START, 'success');\n }\n\n fileService\n .save({ fileUrl: fileMessage.url, fileName: fileMessage.name, fileType: fileMessage.type })\n .then((response) => {\n toast.show(STRINGS.TOAST.DOWNLOAD_OK, 'success');\n Logger.log('File saved to', response);\n })\n .catch((err) => {\n toast.show(STRINGS.TOAST.DOWNLOAD_ERROR, 'error');\n Logger.log('File save failure', err);\n });\n }\n };\n\n return (\n <View style={{ flex: 1, backgroundColor: palette.background700 }}>\n <StatusBar barStyle={'light-content'} animated />\n <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>\n {fileViewer}\n {loading && <LoadingSpinner style={{ position: 'absolute' }} size={40} color={palette.primary300} />}\n </View>\n {headerShown && (\n <FileViewerHeader\n title={STRINGS.FILE_VIEWER.TITLE(fileMessage)}\n subtitle={STRINGS.FILE_VIEWER.SUBTITLE(fileMessage)}\n topInset={headerTopInset ?? basicTopInset}\n onClose={onClose}\n />\n )}\n <FileViewerFooter\n bottomInset={bottom}\n deleteShown={canDelete}\n onPressDelete={_onPressDelete}\n onPressDownload={_onPressDownload}\n />\n </View>\n );\n};\n\ntype HeaderProps = {\n topInset: number;\n onClose: () => void;\n title: string;\n subtitle: string;\n};\nconst FileViewerHeader = ({ topInset, onClose, subtitle, title }: HeaderProps) => {\n const { palette } = useUIKitTheme();\n const { defaultHeight } = useHeaderStyle();\n const { left, right } = useSafeAreaInsets();\n\n return (\n <View\n style={[\n styles.headerContainer,\n {\n paddingLeft: styles.headerContainer.paddingHorizontal + left,\n paddingRight: styles.headerContainer.paddingHorizontal + right,\n },\n { paddingTop: topInset, height: defaultHeight + topInset, backgroundColor: palette.overlay01 },\n ]}\n >\n <SBUPressable as={'TouchableOpacity'} onPress={onClose} style={styles.barButton}>\n <Icon icon={'close'} size={24} color={palette.onBackgroundDark01} />\n </SBUPressable>\n <View style={styles.barTitleContainer}>\n <Text h2 color={palette.onBackgroundDark01} style={styles.headerTitle}>\n {title}\n </Text>\n <Text caption2 color={palette.onBackgroundDark01}>\n {subtitle}\n </Text>\n </View>\n <View style={styles.barButton} />\n </View>\n );\n};\n\ntype FooterProps = {\n bottomInset: number;\n deleteShown: boolean;\n onPressDelete: () => void;\n onPressDownload: () => void;\n};\nconst FileViewerFooter = ({ bottomInset, deleteShown, onPressDelete, onPressDownload }: FooterProps) => {\n const { palette } = useUIKitTheme();\n const { defaultHeight } = useHeaderStyle();\n const { left, right } = useSafeAreaInsets();\n\n return (\n <View\n style={[\n styles.footerContainer,\n {\n paddingLeft: styles.headerContainer.paddingHorizontal + left,\n paddingRight: styles.headerContainer.paddingHorizontal + right,\n },\n {\n paddingBottom: bottomInset,\n height: defaultHeight + bottomInset,\n backgroundColor: palette.overlay01,\n },\n ]}\n >\n <SBUPressable as={'TouchableOpacity'} onPress={onPressDownload} style={styles.barButton}>\n <Icon icon={'download'} size={24} color={palette.onBackgroundDark01} />\n </SBUPressable>\n <View style={styles.barTitleContainer} />\n <SBUPressable as={'TouchableOpacity'} onPress={onPressDelete} style={styles.barButton} disabled={!deleteShown}>\n {deleteShown && <Icon icon={'delete'} size={24} color={palette.onBackgroundDark01} />}\n </SBUPressable>\n </View>\n );\n};\n\nconst styles = createStyleSheet({\n headerContainer: {\n top: 0,\n left: 0,\n right: 0,\n position: 'absolute',\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'center',\n paddingHorizontal: 12,\n },\n barButton: {\n width: 32,\n height: 32,\n alignItems: 'center',\n justifyContent: 'center',\n },\n barTitleContainer: {\n flex: 1,\n alignItems: 'center',\n justifyContent: 'center',\n },\n headerTitle: {\n marginBottom: 2,\n },\n footerContainer: {\n position: 'absolute',\n left: 0,\n right: 0,\n bottom: 0,\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'center',\n paddingHorizontal: 12,\n },\n});\n\nexport default FileViewer;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,QAA3B,QAA2C,OAA3C;AACA,SAASC,SAAT,EAAoBC,UAApB,EAAgCC,IAAhC,QAA4C,cAA5C;AACA,SAASC,iBAAT,QAAkC,gCAAlC;AAEA,SACEC,IADF,EAEEC,KAFF,EAGEC,cAHF,EAIEC,IAJF,EAKEC,gBALF,EAMEC,QANF,EAOEC,cAPF,EAQEC,QARF,EASEC,aATF,QAUO,yCAVP;AAYA,SAASC,MAAT,EAAiBC,gBAAjB,EAAmCC,WAAnC,EAAgDC,WAAhD,EAA6DC,UAA7D,EAAyEC,OAAzE,QAAwF,uBAAxF;AAEA,SAASC,eAAT,EAA0BC,kBAA1B,EAA8CC,eAA9C,QAAqE,qBAArE;AACA,OAAOC,YAAP,MAAyB,gBAAzB;;AAaA,MAAMC,UAAU,GAAG,QAQN;EAAA,IARO;IAClBC,WAAW,GAAG,IADI;IAElBC,aAFkB;IAGlBC,cAHkB;IAIlBC,WAJkB;IAKlBC,eALkB;IAMlBC,aANkB;IAOlBC;EAPkB,CAQP;EACX,MAAM,CAACC,OAAD,EAAUC,UAAV,IAAwBjC,QAAQ,CAAC,IAAD,CAAtC;EAEA,MAAM;IAAEkC;EAAF,IAAa9B,iBAAiB,EAApC;EAEA,MAAM;IAAE+B;EAAF,IAAkBb,eAAe,EAAvC;EACA,MAAM;IAAEc;EAAF,IAAcvB,aAAa,EAAjC;EAC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elPreview, LoadingSpinner, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
4
+ import Icon from '@sendbird/uikit-react-native-foundation/src/ui/Icon';
5
+ import { getFileExtension, getFileType, isDifferentChannel, isMyMessage, useForceUpdate, useIIFE, useUniqId } from '@sendbird/uikit-utils';
6
+ import { useLocalization, useSendbirdChat } from '../hooks/useContext';
7
+ import ChannelCover from './ChannelCover';
8
+ import SBUPressable from './SBUPressable';
9
+ const iconMapper = {
10
+ audio: 'file-audio',
11
+ image: 'photo',
12
+ video: 'play',
13
+ file: 'file-document'
14
+ };
15
+
16
+ const GroupChannelPreviewContainer = _ref => {
17
+ let {
18
+ onPress,
19
+ onLongPress,
20
+ channel
21
+ } = _ref;
22
+ const {
23
+ currentUser,
24
+ sdk,
25
+ features
26
+ } = useSendbirdChat();
27
+ const {
28
+ STRINGS
29
+ } = useLocalization();
30
+ const {
31
+ colors
32
+ } = useUIKitTheme();
33
+ const [typingUsers, setTypingUsers] = useState([]);
34
+ const forceUpdate = useForceUpdate();
35
+
36
+ if (features.channelListTypingIndicatorEnabled) {
37
+ const typingId = useUniqId('GroupChannelPreviewContainer');
38
+ useChannelHandler(sdk, `GroupChannelPreviewContainer_TypingIndicator_${typingId}`, {
39
+ onTypingStatusUpdated(eventChannel) {
40
+ if (isDifferentChannel(channel, eventChannel)) return;
41
+ setTypingUsers(eventChannel.getTypingUsers());
42
+ }
43
+
44
+ });
45
+ }
46
+
47
+ if (features.channelListMessageReceiptStatusEnabled) {
48
+ const receiptId = useUniqId('GroupChannelPreviewContainer');
49
+ useChannelHandler(sdk, `GroupChannelPreviewContainer_ReceiptStatus_${receiptId}`, {
50
+ onDeliveryReceiptUpdated(eventChannel) {
51
+ if (isDifferentChannel(channel, eventChannel)) return;
52
+ if (!eventChannel.isGroupChannel() || !eventChannel.lastMessage) return;
53
+ if (!isMyMessage(eventChannel.lastMessage, currentUser === null || currentUser === void 0 ? void 0 : currentUser.userId)) return;
54
+ forceUpdate();
55
+ },
56
+
57
+ onReadReceiptUpdated(eventChannel) {
58
+ if (isDifferentChannel(channel, eventChannel)) return;
59
+ if (!eventChannel.isGroupChannel() || !eventChannel.lastMessage) return;
60
+ if (!isMyMessage(eventChannel.lastMessage, currentUser === null || currentUser === void 0 ? void 0 : currentUser.userId)) return;
61
+ forceUpdate();
62
+ }
63
+
64
+ });
65
+ }
66
+
67
+ const bodyText = useIIFE(() => {
68
+ if (typingUsers.length > 0) return STRINGS.LABELS.TYPING_INDICATOR_TYPINGS(typingUsers) || '';else return STRINGS.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_BODY(channel);
69
+ });
70
+ const bodyIcon = useIIFE(() => {
71
+ var _channel$lastMessage;
72
+
73
+ if (!((_channel$lastMessage = channel.lastMessage) !== null && _channel$lastMessage !== void 0 && _channel$lastMessage.isFileMessage())) return undefined;
74
+ return iconMapper[getFileType(channel.lastMessage.type || getFileExtension(channel.lastMessage.name))];
75
+ });
76
+ const titleCaptionIcon = useIIFE(() => {
77
+ if (!channel.lastMessage) return undefined;
78
+ if (!features.channelListMessageReceiptStatusEnabled) return undefined;
79
+ if (!isMyMessage(channel.lastMessage, currentUser === null || currentUser === void 0 ? void 0 : currentUser.userId)) return undefined;
80
+
81
+ if (channel.lastMessage.sendingStatus === 'pending') {
82
+ return /*#__PURE__*/React.createElement(LoadingSpinner, {
83
+ size: 16,
84
+ style: styles.titleCaptionIcon
85
+ });
86
+ }
87
+
88
+ if (channel.lastMessage.sendingStatus === 'failed') {
89
+ return /*#__PURE__*/React.createElement(Icon, {
90
+ icon: 'error',
91
+ size: 16,
92
+ color: colors.error,
93
+ style: styles.titleCaptionIcon
94
+ });
95
+ }
96
+
97
+ if (channel.getUnreadMemberCount(channel.lastMessage) === 0) {
98
+ return /*#__PURE__*/React.createElement(Icon, {
99
+ icon: 'done-all',
100
+ size: 16,
101
+ color: colors.secondary,
102
+ style: styles.titleCaptionIcon
103
+ });
104
+ }
105
+
106
+ if (features.deliveryReceiptEnabled) {
107
+ if (channel.getUndeliveredMemberCount(channel.lastMessage) === 0) {
108
+ return /*#__PURE__*/React.createElement(Icon, {
109
+ icon: 'done-all',
110
+ size: 16,
111
+ color: colors.onBackground03,
112
+ style: styles.titleCaptionIcon
113
+ });
114
+ }
115
+
116
+ return /*#__PURE__*/React.createElement(Icon, {
117
+ icon: 'done',
118
+ size: 16,
119
+ color: colors.onBackground03,
120
+ containerStyle: styles.titleCaptionIcon
121
+ });
122
+ }
123
+
124
+ return /*#__PURE__*/React.createElement(Icon, {
125
+ icon: 'done-all',
126
+ size: 16,
127
+ color: colors.onBackground03,
128
+ style: styles.titleCaptionIcon
129
+ });
130
+ });
131
+ return /*#__PURE__*/React.createElement(SBUPressable, {
132
+ onPress: onPress,
133
+ onLongPress: onLongPress
134
+ }, /*#__PURE__*/React.createElement(GroupChannelPreview, {
135
+ customCover: /*#__PURE__*/React.createElement(ChannelCover, {
136
+ channel: channel,
137
+ size: 56
138
+ }),
139
+ coverUrl: channel.coverUrl,
140
+ title: STRINGS.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_TITLE((currentUser === null || currentUser === void 0 ? void 0 : currentUser.userId) ?? '', channel),
141
+ titleCaptionLeft: titleCaptionIcon,
142
+ titleCaption: STRINGS.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_TITLE_CAPTION(channel),
143
+ body: bodyText,
144
+ bodyIcon: bodyIcon,
145
+ badgeCount: channel.unreadMessageCount,
146
+ memberCount: channel.memberCount > 2 ? channel.memberCount : undefined,
147
+ frozen: channel.isFrozen,
148
+ notificationOff: channel.myPushTriggerOption === 'off'
149
+ }));
150
+ };
151
+
152
+ const styles = createStyleSheet({
153
+ titleCaptionIcon: {
154
+ marginRight: 4
155
+ }
156
+ });
157
+ export default GroupChannelPreviewContainer;
158
+ //# sourceMappingURL=GroupChannelPreviewContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useState","useChannelHandler","GroupChannelPreview","LoadingSpinner","createStyleSheet","useUIKitTheme","Icon","getFileExtension","getFileType","isDifferentChannel","isMyMessage","useForceUpdate","useIIFE","useUniqId","useLocalization","useSendbirdChat","ChannelCover","SBUPressable","iconMapper","audio","image","video","file","GroupChannelPreviewContainer","onPress","onLongPress","channel","currentUser","sdk","features","STRINGS","colors","typingUsers","setTypingUsers","forceUpdate","channelListTypingIndicatorEnabled","typingId","onTypingStatusUpdated","eventChannel","getTypingUsers","channelListMessageReceiptStatusEnabled","receiptId","onDeliveryReceiptUpdated","isGroupChannel","lastMessage","userId","onReadReceiptUpdated","bodyText","length","LABELS","TYPING_INDICATOR_TYPINGS","GROUP_CHANNEL_LIST","CHANNEL_PREVIEW_BODY","bodyIcon","isFileMessage","undefined","type","name","titleCaptionIcon","sendingStatus","styles","error","getUnreadMemberCount","secondary","deliveryReceiptEnabled","getUndeliveredMemberCount","onBackground03","coverUrl","CHANNEL_PREVIEW_TITLE","CHANNEL_PREVIEW_TITLE_CAPTION","unreadMessageCount","memberCount","isFrozen","myPushTriggerOption","marginRight"],"sources":["GroupChannelPreviewContainer.tsx"],"sourcesContent":["import React, { useState } from 'react';\n\nimport { useChannelHandler } from '@sendbird/uikit-chat-hooks';\nimport {\n GroupChannelPreview,\n LoadingSpinner,\n createStyleSheet,\n useUIKitTheme,\n} from '@sendbird/uikit-react-native-foundation';\nimport Icon from '@sendbird/uikit-react-native-foundation/src/ui/Icon';\nimport {\n SendbirdGroupChannel,\n SendbirdUser,\n getFileExtension,\n getFileType,\n isDifferentChannel,\n isMyMessage,\n useForceUpdate,\n useIIFE,\n useUniqId,\n} from '@sendbird/uikit-utils';\n\nimport { useLocalization, useSendbirdChat } from '../hooks/useContext';\nimport ChannelCover from './ChannelCover';\nimport SBUPressable from './SBUPressable';\n\nconst iconMapper = { audio: 'file-audio', image: 'photo', video: 'play', file: 'file-document' } as const;\n\ntype Props = {\n channel: SendbirdGroupChannel;\n onPress: () => void;\n onLongPress: () => void;\n};\nconst GroupChannelPreviewContainer = ({ onPress, onLongPress, channel }: Props) => {\n const { currentUser, sdk, features } = useSendbirdChat();\n const { STRINGS } = useLocalization();\n const { colors } = useUIKitTheme();\n\n const [typingUsers, setTypingUsers] = useState<SendbirdUser[]>([]);\n const forceUpdate = useForceUpdate();\n\n if (features.channelListTypingIndicatorEnabled) {\n const typingId = useUniqId('GroupChannelPreviewContainer');\n useChannelHandler(sdk, `GroupChannelPreviewContainer_TypingIndicator_${typingId}`, {\n onTypingStatusUpdated(eventChannel) {\n if (isDifferentChannel(channel, eventChannel)) return;\n setTypingUsers(eventChannel.getTypingUsers());\n },\n });\n }\n\n if (features.channelListMessageReceiptStatusEnabled) {\n const receiptId = useUniqId('GroupChannelPreviewContainer');\n useChannelHandler(sdk, `GroupChannelPreviewContainer_ReceiptStatus_${receiptId}`, {\n onDeliveryReceiptUpdated(eventChannel) {\n if (isDifferentChannel(channel, eventChannel)) return;\n if (!eventChannel.isGroupChannel() || !eventChannel.lastMessage) return;\n if (!isMyMessage(eventChannel.lastMessage, currentUser?.userId)) return;\n\n forceUpdate();\n },\n onReadReceiptUpdated(eventChannel) {\n if (isDifferentChannel(channel, eventChannel)) return;\n if (!eventChannel.isGroupChannel() || !eventChannel.lastMessage) return;\n if (!isMyMessage(eventChannel.lastMessage, currentUser?.userId)) return;\n\n forceUpdate();\n },\n });\n }\n\n const bodyText = useIIFE(() => {\n if (typingUsers.length > 0) return STRINGS.LABELS.TYPING_INDICATOR_TYPINGS(typingUsers) || '';\n else return STRINGS.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_BODY(channel);\n });\n\n const bodyIcon = useIIFE(() => {\n if (!channel.lastMessage?.isFileMessage()) return undefined;\n return iconMapper[getFileType(channel.lastMessage.type || getFileExtension(channel.lastMessage.name))];\n });\n\n const titleCaptionIcon = useIIFE(() => {\n if (!channel.lastMessage) return undefined;\n if (!features.channelListMessageReceiptStatusEnabled) return undefined;\n if (!isMyMessage(channel.lastMessage, currentUser?.userId)) return undefined;\n\n if (channel.lastMessage.sendingStatus === 'pending') {\n return <LoadingSpinner size={16} style={styles.titleCaptionIcon} />;\n }\n\n if (channel.lastMessage.sendingStatus === 'failed') {\n return <Icon icon={'error'} size={16} color={colors.error} style={styles.titleCaptionIcon} />;\n }\n\n if (channel.getUnreadMemberCount(channel.lastMessage) === 0) {\n return <Icon icon={'done-all'} size={16} color={colors.secondary} style={styles.titleCaptionIcon} />;\n }\n\n if (features.deliveryReceiptEnabled) {\n if (channel.getUndeliveredMemberCount(channel.lastMessage) === 0) {\n return <Icon icon={'done-all'} size={16} color={colors.onBackground03} style={styles.titleCaptionIcon} />;\n }\n return <Icon icon={'done'} size={16} color={colors.onBackground03} containerStyle={styles.titleCaptionIcon} />;\n }\n\n return <Icon icon={'done-all'} size={16} color={colors.onBackground03} style={styles.titleCaptionIcon} />;\n });\n\n return (\n <SBUPressable onPress={onPress} onLongPress={onLongPress}>\n <GroupChannelPreview\n customCover={<ChannelCover channel={channel} size={56} />}\n coverUrl={channel.coverUrl}\n title={STRINGS.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_TITLE(currentUser?.userId ?? '', channel)}\n titleCaptionLeft={titleCaptionIcon}\n titleCaption={STRINGS.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_TITLE_CAPTION(channel)}\n body={bodyText}\n bodyIcon={bodyIcon}\n badgeCount={channel.unreadMessageCount}\n memberCount={channel.memberCount > 2 ? channel.memberCount : undefined}\n frozen={channel.isFrozen}\n notificationOff={channel.myPushTriggerOption === 'off'}\n />\n </SBUPressable>\n );\n};\n\nconst styles = createStyleSheet({\n titleCaptionIcon: {\n marginRight: 4,\n },\n});\n\nexport default GroupChannelPreviewContainer;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,QAAhB,QAAgC,OAAhC;AAEA,SAASC,iBAAT,QAAkC,4BAAlC;AACA,SACEC,mBADF,EAEEC,cAFF,EAGEC,gBAHF,EAIEC,aAJF,QAKO,yCALP;AAMA,OAAOC,IAAP,MAAiB,qDAAjB;AACA,SAGEC,g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C8C,QAVlB;IAWE,eAAe,EAAE9C,OAAO,CAAC+C,mBAAR,KAAgC;EAXnD,EADF,CADF;AAiBD,CA5FD;;AA8FA,MAAMb,MAAM,GAAGxD,gBAAgB,CAAC;EAC9BsD,gBAAgB,EAAE;IAChBgB,WAAW,EAAE;EADG;AADY,CAAD,CAA/B;AAMA,eAAenD,4BAAf"}
@@ -0,0 +1,100 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { View } from 'react-native';
3
+ import { Icon, Image, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
4
+ import { getAvailableUriFromFileMessage } from '@sendbird/uikit-utils';
5
+ import { usePlatformService } from '../../../hooks/useContext';
6
+
7
+ const VideoFileMessage = _ref => {
8
+ let {
9
+ message
10
+ } = _ref;
11
+ const {
12
+ colors
13
+ } = useUIKitTheme();
14
+ const {
15
+ mediaService
16
+ } = usePlatformService();
17
+ const fileUrl = getAvailableUriFromFileMessage(message);
18
+ const style = [styles.image, {
19
+ backgroundColor: colors.onBackground04
20
+ }];
21
+ const [state, setState] = useState({
22
+ thumbnail: null,
23
+ loading: true,
24
+ imageNotFound: false
25
+ });
26
+ useEffect(() => {
27
+ mediaService === null || mediaService === void 0 ? void 0 : mediaService.getVideoThumbnail({
28
+ url: fileUrl,
29
+ timeMills: 1000
30
+ }).then(result => {
31
+ if (result !== null && result !== void 0 && result.path) {
32
+ setState(prev => ({ ...prev,
33
+ loading: false,
34
+ thumbnail: result.path
35
+ }));
36
+ } else {
37
+ throw new Error('Cannot generate thumbnail');
38
+ }
39
+ }).catch(() => {
40
+ setState(prev => ({ ...prev,
41
+ loading: false,
42
+ imageNotFound: true
43
+ }));
44
+ });
45
+ }, []);
46
+
47
+ if (state.loading || state.imageNotFound) {
48
+ return /*#__PURE__*/React.createElement(View, {
49
+ style: [style, styles.container]
50
+ }, /*#__PURE__*/React.createElement(PlayIcon, null));
51
+ }
52
+
53
+ return /*#__PURE__*/React.createElement(View, {
54
+ style: styles.container
55
+ }, /*#__PURE__*/React.createElement(Image, {
56
+ source: {
57
+ uri: state.thumbnail || fileUrl
58
+ },
59
+ style: style,
60
+ resizeMode: 'cover',
61
+ resizeMethod: 'resize',
62
+ onError: () => setState(prev => ({ ...prev,
63
+ imageNotFound: true
64
+ }))
65
+ }), /*#__PURE__*/React.createElement(PlayIcon, null));
66
+ };
67
+
68
+ const PlayIcon = () => {
69
+ const {
70
+ colors
71
+ } = useUIKitTheme();
72
+ return /*#__PURE__*/React.createElement(Icon, {
73
+ icon: 'play',
74
+ size: 28,
75
+ color: colors.onBackground02,
76
+ containerStyle: [styles.playIcon, {
77
+ backgroundColor: colors.onBackgroundReverse01
78
+ }]
79
+ });
80
+ };
81
+
82
+ const styles = createStyleSheet({
83
+ container: {
84
+ alignItems: 'center',
85
+ justifyContent: 'center'
86
+ },
87
+ image: {
88
+ width: 240,
89
+ maxWidth: 240,
90
+ height: 160,
91
+ borderRadius: 16
92
+ },
93
+ playIcon: {
94
+ position: 'absolute',
95
+ padding: 10,
96
+ borderRadius: 50
97
+ }
98
+ });
99
+ export default VideoFileMessage;
100
+ //# sourceMappingURL=VideoFileMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useEffect","useState","View","Icon","Image","createStyleSheet","useUIKitTheme","getAvailableUriFromFileMessage","usePlatformService","VideoFileMessage","message","colors","mediaService","fileUrl","style","styles","image","backgroundColor","onBackground04","state","setState","thumbnail","loading","imageNotFound","getVideoThumbnail","url","timeMills","then","result","path","prev","Error","catch","container","uri","PlayIcon","onBackground02","playIcon","onBackgroundReverse01","alignItems","justifyContent","width","maxWidth","height","borderRadius","position","padding"],"sources":["VideoFileMessage.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport { View } from 'react-native';\n\nimport { Icon, Image, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';\nimport { getAvailableUriFromFileMessage } from '@sendbird/uikit-utils';\n\nimport { usePlatformService } from '../../../hooks/useContext';\nimport type { FileMessageProps } from './index';\n\nconst VideoFileMessage = ({ message }: FileMessageProps) => {\n const { colors } = useUIKitTheme();\n\n const { mediaService } = usePlatformService();\n const fileUrl = getAvailableUriFromFileMessage(message);\n const style = [styles.image, { backgroundColor: colors.onBackground04 }];\n\n const [state, setState] = useState({\n thumbnail: null as null | string,\n loading: true,\n imageNotFound: false,\n });\n\n useEffect(() => {\n mediaService\n ?.getVideoThumbnail({ url: fileUrl, timeMills: 1000 })\n .then((result) => {\n if (result?.path) {\n setState((prev) => ({ ...prev, loading: false, thumbnail: result.path }));\n } else {\n throw new Error('Cannot generate thumbnail');\n }\n })\n .catch(() => {\n setState((prev) => ({ ...prev, loading: false, imageNotFound: true }));\n });\n }, []);\n\n if (state.loading || state.imageNotFound) {\n return (\n <View style={[style, styles.container]}>\n <PlayIcon />\n </View>\n );\n }\n\n return (\n <View style={styles.container}>\n <Image\n source={{ uri: state.thumbnail || fileUrl }}\n style={style}\n resizeMode={'cover'}\n resizeMethod={'resize'}\n onError={() => setState((prev) => ({ ...prev, imageNotFound: true }))}\n />\n <PlayIcon />\n </View>\n );\n};\n\nconst PlayIcon = () => {\n const { colors } = useUIKitTheme();\n\n return (\n <Icon\n icon={'play'}\n size={28}\n color={colors.onBackground02}\n containerStyle={[styles.playIcon, { backgroundColor: colors.onBackgroundReverse01 }]}\n />\n );\n};\n\nconst styles = createStyleSheet({\n container: {\n alignItems: 'center',\n justifyContent: 'center',\n },\n image: {\n width: 240,\n maxWidth: 240,\n height: 160,\n borderRadius: 16,\n },\n playIcon: {\n position: 'absolute',\n padding: 10,\n borderRadius: 50,\n },\n});\n\nexport default VideoFileMessage;\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,QAA3B,QAA2C,OAA3C;AACA,SAASC,IAAT,QAAqB,cAArB;AAEA,SAASC,IAAT,EAAeC,KAAf,EAAsBC,gBAAtB,EAAwCC,aAAxC,QAA6D,yCAA7D;AACA,SAASC,8BAAT,QAA+C,uBAA/C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f"}
@@ -2,12 +2,18 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
2
2
 
3
3
  import React from 'react';
4
4
  import { getFileExtension, getFileType } from '@sendbird/uikit-utils';
5
+ import { usePlatformService } from '../../../hooks/useContext';
5
6
  import BaseFileMessage from './BaseFileMessage';
6
7
  import ImageFileMessage from './ImageFileMessage';
8
+ import VideoFileMessage from './VideoFileMessage';
7
9
 
8
10
  const FileMessage = props => {
11
+ const {
12
+ mediaService
13
+ } = usePlatformService();
9
14
  const fileType = getFileType(props.message.type || getFileExtension(props.message.name));
10
15
  if (fileType === 'image') return /*#__PURE__*/React.createElement(ImageFileMessage, props);
16
+ if (fileType === 'video' && mediaService !== null && mediaService !== void 0 && mediaService.getVideoThumbnail) return /*#__PURE__*/React.createElement(VideoFileMessage, props);
11
17
  return /*#__PURE__*/React.createElement(BaseFileMessage, _extends({}, props, {
12
18
  type: fileType
13
19
  }));