@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.
- package/README.md +7 -7
- package/lib/commonjs/SendbirdUIKitContainer.js +5 -2
- package/lib/commonjs/SendbirdUIKitContainer.js.map +1 -1
- package/lib/commonjs/components/FileViewer.js +326 -0
- package/lib/commonjs/components/FileViewer.js.map +1 -0
- package/lib/commonjs/components/GroupChannelPreviewContainer.js +180 -0
- package/lib/commonjs/components/GroupChannelPreviewContainer.js.map +1 -0
- package/lib/commonjs/components/MessageRenderer/FileMessage/VideoFileMessage.js +116 -0
- package/lib/commonjs/components/MessageRenderer/FileMessage/VideoFileMessage.js.map +1 -0
- package/lib/commonjs/components/MessageRenderer/FileMessage/index.js +8 -0
- package/lib/commonjs/components/MessageRenderer/FileMessage/index.js.map +1 -1
- package/lib/commonjs/components/MessageRenderer/MessageOutgoingStatus.js +15 -24
- package/lib/commonjs/components/MessageRenderer/MessageOutgoingStatus.js.map +1 -1
- package/lib/commonjs/components/SBUPressable.js +45 -0
- package/lib/commonjs/components/SBUPressable.js.map +1 -0
- package/lib/commonjs/components/UserActionBar.js +1 -3
- package/lib/commonjs/components/UserActionBar.js.map +1 -1
- package/lib/commonjs/components/UserSelectableBar.js +1 -3
- package/lib/commonjs/components/UserSelectableBar.js.map +1 -1
- package/lib/commonjs/constants.js +7 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/contexts/PlatformService.js +4 -2
- package/lib/commonjs/contexts/PlatformService.js.map +1 -1
- package/lib/commonjs/contexts/SendbirdChat.js +6 -2
- package/lib/commonjs/contexts/SendbirdChat.js.map +1 -1
- package/lib/commonjs/domain/groupChannel/component/GroupChannelInput/SendInput.js +1 -1
- package/lib/commonjs/domain/groupChannel/component/GroupChannelInput/SendInput.js.map +1 -1
- package/lib/commonjs/domain/groupChannel/component/GroupChannelMessageList.js +30 -7
- package/lib/commonjs/domain/groupChannel/component/GroupChannelMessageList.js.map +1 -1
- package/lib/commonjs/domain/groupChannel/module/moduleContext.js +2 -3
- package/lib/commonjs/domain/groupChannel/module/moduleContext.js.map +1 -1
- package/lib/commonjs/domain/groupChannel/types.js.map +1 -1
- package/lib/commonjs/domain/groupChannelList/types.js.map +1 -1
- package/lib/commonjs/domain/groupChannelSettings/module/moduleContext.js +1 -1
- package/lib/commonjs/domain/groupChannelSettings/module/moduleContext.js.map +1 -1
- package/lib/commonjs/fragments/createGroupChannelCreateFragment.js +3 -7
- package/lib/commonjs/fragments/createGroupChannelCreateFragment.js.map +1 -1
- package/lib/commonjs/fragments/createGroupChannelFragment.js +13 -11
- package/lib/commonjs/fragments/createGroupChannelFragment.js.map +1 -1
- package/lib/commonjs/fragments/createGroupChannelListFragment.js +7 -37
- package/lib/commonjs/fragments/createGroupChannelListFragment.js.map +1 -1
- package/lib/commonjs/fragments/createGroupChannelMembersFragment.js +1 -1
- package/lib/commonjs/fragments/createGroupChannelMembersFragment.js.map +1 -1
- package/lib/commonjs/hooks/useContext.js.map +1 -1
- package/lib/commonjs/index.js +29 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/localization/StringSet.type.js +8 -0
- package/lib/commonjs/localization/StringSet.type.js.map +1 -1
- package/lib/commonjs/platform/createFileService.expo.js +21 -2
- package/lib/commonjs/platform/createFileService.expo.js.map +1 -1
- package/lib/commonjs/platform/createFileService.native.js +20 -3
- package/lib/commonjs/platform/createFileService.native.js.map +1 -1
- package/lib/commonjs/platform/createMediaService.expo.js +64 -0
- package/lib/commonjs/platform/createMediaService.expo.js.map +1 -0
- package/lib/commonjs/platform/createMediaService.native.js +67 -0
- package/lib/commonjs/platform/createMediaService.native.js.map +1 -0
- package/lib/commonjs/platform/createNotificationService.expo.js.map +1 -1
- package/lib/commonjs/platform/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/SendbirdUIKitContainer.js +5 -2
- package/lib/module/SendbirdUIKitContainer.js.map +1 -1
- package/lib/module/components/FileViewer.js +304 -0
- package/lib/module/components/FileViewer.js.map +1 -0
- package/lib/module/components/GroupChannelPreviewContainer.js +158 -0
- package/lib/module/components/GroupChannelPreviewContainer.js.map +1 -0
- package/lib/module/components/MessageRenderer/FileMessage/VideoFileMessage.js +100 -0
- package/lib/module/components/MessageRenderer/FileMessage/VideoFileMessage.js.map +1 -0
- package/lib/module/components/MessageRenderer/FileMessage/index.js +6 -0
- package/lib/module/components/MessageRenderer/FileMessage/index.js.map +1 -1
- package/lib/module/components/MessageRenderer/MessageOutgoingStatus.js +17 -26
- package/lib/module/components/MessageRenderer/MessageOutgoingStatus.js.map +1 -1
- package/lib/module/components/SBUPressable.js +33 -0
- package/lib/module/components/SBUPressable.js.map +1 -0
- package/lib/module/components/UserActionBar.js +1 -1
- package/lib/module/components/UserActionBar.js.map +1 -1
- package/lib/module/components/UserSelectableBar.js +1 -1
- package/lib/module/components/UserSelectableBar.js.map +1 -1
- package/lib/module/constants.js +5 -0
- package/lib/module/constants.js.map +1 -1
- package/lib/module/contexts/PlatformService.js +4 -2
- package/lib/module/contexts/PlatformService.js.map +1 -1
- package/lib/module/contexts/SendbirdChat.js +6 -2
- package/lib/module/contexts/SendbirdChat.js.map +1 -1
- package/lib/module/domain/groupChannel/component/GroupChannelInput/SendInput.js +1 -1
- package/lib/module/domain/groupChannel/component/GroupChannelInput/SendInput.js.map +1 -1
- package/lib/module/domain/groupChannel/component/GroupChannelMessageList.js +28 -7
- package/lib/module/domain/groupChannel/component/GroupChannelMessageList.js.map +1 -1
- package/lib/module/domain/groupChannel/module/moduleContext.js +2 -3
- package/lib/module/domain/groupChannel/module/moduleContext.js.map +1 -1
- package/lib/module/domain/groupChannel/types.js.map +1 -1
- package/lib/module/domain/groupChannelList/types.js.map +1 -1
- package/lib/module/domain/groupChannelSettings/module/moduleContext.js +1 -1
- package/lib/module/domain/groupChannelSettings/module/moduleContext.js.map +1 -1
- package/lib/module/fragments/createGroupChannelCreateFragment.js +4 -4
- package/lib/module/fragments/createGroupChannelCreateFragment.js.map +1 -1
- package/lib/module/fragments/createGroupChannelFragment.js +15 -13
- package/lib/module/fragments/createGroupChannelFragment.js.map +1 -1
- package/lib/module/fragments/createGroupChannelListFragment.js +11 -38
- package/lib/module/fragments/createGroupChannelListFragment.js.map +1 -1
- package/lib/module/fragments/createGroupChannelMembersFragment.js +1 -1
- package/lib/module/fragments/createGroupChannelMembersFragment.js.map +1 -1
- package/lib/module/hooks/useContext.js.map +1 -1
- package/lib/module/index.js +4 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/localization/StringSet.type.js +8 -0
- package/lib/module/localization/StringSet.type.js.map +1 -1
- package/lib/module/platform/createFileService.expo.js +21 -2
- package/lib/module/platform/createFileService.expo.js.map +1 -1
- package/lib/module/platform/createFileService.native.js +20 -3
- package/lib/module/platform/createFileService.native.js.map +1 -1
- package/lib/module/platform/createMediaService.expo.js +54 -0
- package/lib/module/platform/createMediaService.expo.js.map +1 -0
- package/lib/module/platform/createMediaService.native.js +57 -0
- package/lib/module/platform/createMediaService.native.js.map +1 -0
- package/lib/module/platform/createNotificationService.expo.js.map +1 -1
- package/lib/module/platform/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/src/SendbirdUIKitContainer.d.ts +7 -3
- package/lib/typescript/src/components/FileViewer.d.ts +12 -0
- package/lib/typescript/src/components/GroupChannelPreviewContainer.d.ts +8 -0
- package/lib/typescript/src/components/MessageRenderer/FileMessage/VideoFileMessage.d.ts +3 -0
- package/lib/typescript/src/components/SBUPressable.d.ts +18 -0
- package/lib/typescript/src/components/UserActionBar.d.ts +2 -3
- package/lib/typescript/src/components/UserSelectableBar.d.ts +2 -3
- package/lib/typescript/src/constants.d.ts +5 -0
- package/lib/typescript/src/contexts/PlatformService.d.ts +3 -2
- package/lib/typescript/src/contexts/SendbirdChat.d.ts +5 -1
- package/lib/typescript/src/domain/groupChannel/component/GroupChannelMessageList.d.ts +3 -2
- package/lib/typescript/src/domain/groupChannel/types.d.ts +6 -2
- package/lib/typescript/src/hooks/useContext.d.ts +7 -5
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/localization/StringSet.type.d.ts +4 -0
- package/lib/typescript/src/platform/createMediaService.expo.d.ts +9 -0
- package/lib/typescript/src/platform/createMediaService.native.d.ts +9 -0
- package/lib/typescript/src/platform/createNotificationService.expo.d.ts +1 -1
- package/lib/typescript/src/platform/types.d.ts +20 -1
- package/lib/typescript/src/version.d.ts +1 -1
- package/package.json +14 -5
- package/src/SendbirdUIKitContainer.tsx +14 -2
- package/src/components/FileViewer.tsx +284 -0
- package/src/components/GroupChannelPreviewContainer.tsx +134 -0
- package/src/components/MessageRenderer/FileMessage/VideoFileMessage.tsx +91 -0
- package/src/components/MessageRenderer/FileMessage/index.tsx +6 -0
- package/src/components/MessageRenderer/MessageOutgoingStatus.tsx +25 -32
- package/src/components/SBUPressable.tsx +40 -0
- package/src/components/UserActionBar.tsx +1 -1
- package/src/components/UserSelectableBar.tsx +1 -1
- package/src/constants.ts +5 -0
- package/src/contexts/PlatformService.tsx +15 -3
- package/src/contexts/SendbirdChat.tsx +13 -5
- package/src/domain/groupChannel/component/GroupChannelInput/SendInput.tsx +1 -1
- package/src/domain/groupChannel/component/GroupChannelMessageList.tsx +23 -6
- package/src/domain/groupChannel/module/moduleContext.tsx +6 -13
- package/src/domain/groupChannel/types.ts +8 -2
- package/src/domain/groupChannelList/types.ts +1 -0
- package/src/domain/groupChannelSettings/module/moduleContext.tsx +5 -10
- package/src/fragments/createGroupChannelCreateFragment.tsx +38 -41
- package/src/fragments/createGroupChannelFragment.tsx +23 -33
- package/src/fragments/createGroupChannelListFragment.tsx +10 -32
- package/src/fragments/createGroupChannelMembersFragment.tsx +34 -39
- package/src/hooks/useContext.ts +3 -5
- package/src/index.ts +5 -1
- package/src/localization/StringSet.type.ts +8 -0
- package/src/platform/createFileService.expo.ts +17 -2
- package/src/platform/createFileService.native.ts +16 -3
- package/src/platform/createMediaService.expo.tsx +30 -0
- package/src/platform/createMediaService.native.tsx +37 -0
- package/src/platform/createNotificationService.expo.ts +1 -1
- package/src/platform/types.ts +26 -1
- package/src/version.ts +1 -1
|
@@ -0,0 +1,284 @@
|
|
|
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
|
+
|
|
5
|
+
import {
|
|
6
|
+
Icon,
|
|
7
|
+
Image,
|
|
8
|
+
LoadingSpinner,
|
|
9
|
+
Text,
|
|
10
|
+
createStyleSheet,
|
|
11
|
+
useAlert,
|
|
12
|
+
useHeaderStyle,
|
|
13
|
+
useToast,
|
|
14
|
+
useUIKitTheme,
|
|
15
|
+
} from '@sendbird/uikit-react-native-foundation';
|
|
16
|
+
import type { SendbirdFileMessage } from '@sendbird/uikit-utils';
|
|
17
|
+
import { Logger, getFileExtension, getFileType, isMyMessage, toMegabyte, useIIFE } from '@sendbird/uikit-utils';
|
|
18
|
+
|
|
19
|
+
import { useLocalization, usePlatformService, useSendbirdChat } from '../hooks/useContext';
|
|
20
|
+
import SBUPressable from './SBUPressable';
|
|
21
|
+
|
|
22
|
+
type Props = {
|
|
23
|
+
fileMessage: SendbirdFileMessage;
|
|
24
|
+
deleteMessage: () => Promise<void>;
|
|
25
|
+
|
|
26
|
+
onClose: () => void;
|
|
27
|
+
onPressDownload?: (message: SendbirdFileMessage) => void;
|
|
28
|
+
onPressDelete?: (message: SendbirdFileMessage) => void;
|
|
29
|
+
|
|
30
|
+
headerShown?: boolean;
|
|
31
|
+
headerTopInset?: number;
|
|
32
|
+
};
|
|
33
|
+
const FileViewer = ({
|
|
34
|
+
headerShown = true,
|
|
35
|
+
deleteMessage,
|
|
36
|
+
headerTopInset,
|
|
37
|
+
fileMessage,
|
|
38
|
+
onPressDownload,
|
|
39
|
+
onPressDelete,
|
|
40
|
+
onClose,
|
|
41
|
+
}: Props) => {
|
|
42
|
+
const [loading, setLoading] = useState(true);
|
|
43
|
+
|
|
44
|
+
const { bottom } = useSafeAreaInsets();
|
|
45
|
+
|
|
46
|
+
const { currentUser } = useSendbirdChat();
|
|
47
|
+
const { palette } = useUIKitTheme();
|
|
48
|
+
const { topInset, statusBarTranslucent, defaultHeight } = useHeaderStyle();
|
|
49
|
+
const { STRINGS } = useLocalization();
|
|
50
|
+
const { fileService, mediaService } = usePlatformService();
|
|
51
|
+
const toast = useToast();
|
|
52
|
+
const { alert } = useAlert();
|
|
53
|
+
|
|
54
|
+
const basicTopInset = statusBarTranslucent ? topInset : 0;
|
|
55
|
+
const canDelete = isMyMessage(fileMessage, currentUser?.userId);
|
|
56
|
+
const fileType = getFileType(fileMessage.type || getFileExtension(fileMessage.url));
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!mediaService?.VideoComponent || fileType === 'file') {
|
|
60
|
+
onClose();
|
|
61
|
+
}
|
|
62
|
+
}, [mediaService]);
|
|
63
|
+
|
|
64
|
+
const fileViewer = useIIFE(() => {
|
|
65
|
+
switch (fileType) {
|
|
66
|
+
case 'image': {
|
|
67
|
+
return (
|
|
68
|
+
<Image
|
|
69
|
+
source={{ uri: fileMessage.url }}
|
|
70
|
+
style={StyleSheet.absoluteFill}
|
|
71
|
+
resizeMode={'contain'}
|
|
72
|
+
onLoadEnd={() => setLoading(false)}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
case 'video':
|
|
78
|
+
case 'audio': {
|
|
79
|
+
if (!mediaService?.VideoComponent) return null;
|
|
80
|
+
return (
|
|
81
|
+
<mediaService.VideoComponent
|
|
82
|
+
source={{ uri: fileMessage.url }}
|
|
83
|
+
style={[StyleSheet.absoluteFill, { top: basicTopInset + defaultHeight, bottom: defaultHeight + bottom }]}
|
|
84
|
+
resizeMode={'contain'}
|
|
85
|
+
onLoad={() => setLoading(false)}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
default: {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const _onPressDelete = () => {
|
|
97
|
+
if (!canDelete) return;
|
|
98
|
+
|
|
99
|
+
if (onPressDelete) {
|
|
100
|
+
onPressDelete(fileMessage);
|
|
101
|
+
} else {
|
|
102
|
+
alert({
|
|
103
|
+
title: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_TITLE,
|
|
104
|
+
buttons: [
|
|
105
|
+
{
|
|
106
|
+
text: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_CANCEL,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
text: STRINGS.GROUP_CHANNEL.DIALOG_MESSAGE_DELETE_CONFIRM_OK,
|
|
110
|
+
style: 'destructive',
|
|
111
|
+
onPress: () => {
|
|
112
|
+
deleteMessage()
|
|
113
|
+
.then(() => {
|
|
114
|
+
onClose();
|
|
115
|
+
})
|
|
116
|
+
.catch(() => {
|
|
117
|
+
toast.show(STRINGS.TOAST.DELETE_MSG_ERROR, 'error');
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const _onPressDownload = () => {
|
|
127
|
+
if (onPressDownload) {
|
|
128
|
+
onPressDownload(fileMessage);
|
|
129
|
+
} else {
|
|
130
|
+
if (toMegabyte(fileMessage.size) > 4) {
|
|
131
|
+
toast.show(STRINGS.TOAST.DOWNLOAD_START, 'success');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
fileService
|
|
135
|
+
.save({ fileUrl: fileMessage.url, fileName: fileMessage.name, fileType: fileMessage.type })
|
|
136
|
+
.then((response) => {
|
|
137
|
+
toast.show(STRINGS.TOAST.DOWNLOAD_OK, 'success');
|
|
138
|
+
Logger.log('File saved to', response);
|
|
139
|
+
})
|
|
140
|
+
.catch((err) => {
|
|
141
|
+
toast.show(STRINGS.TOAST.DOWNLOAD_ERROR, 'error');
|
|
142
|
+
Logger.log('File save failure', err);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<View style={{ flex: 1, backgroundColor: palette.background700 }}>
|
|
149
|
+
<StatusBar barStyle={'light-content'} animated />
|
|
150
|
+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
|
151
|
+
{fileViewer}
|
|
152
|
+
{loading && <LoadingSpinner style={{ position: 'absolute' }} size={40} color={palette.primary300} />}
|
|
153
|
+
</View>
|
|
154
|
+
{headerShown && (
|
|
155
|
+
<FileViewerHeader
|
|
156
|
+
title={STRINGS.FILE_VIEWER.TITLE(fileMessage)}
|
|
157
|
+
subtitle={STRINGS.FILE_VIEWER.SUBTITLE(fileMessage)}
|
|
158
|
+
topInset={headerTopInset ?? basicTopInset}
|
|
159
|
+
onClose={onClose}
|
|
160
|
+
/>
|
|
161
|
+
)}
|
|
162
|
+
<FileViewerFooter
|
|
163
|
+
bottomInset={bottom}
|
|
164
|
+
deleteShown={canDelete}
|
|
165
|
+
onPressDelete={_onPressDelete}
|
|
166
|
+
onPressDownload={_onPressDownload}
|
|
167
|
+
/>
|
|
168
|
+
</View>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
type HeaderProps = {
|
|
173
|
+
topInset: number;
|
|
174
|
+
onClose: () => void;
|
|
175
|
+
title: string;
|
|
176
|
+
subtitle: string;
|
|
177
|
+
};
|
|
178
|
+
const FileViewerHeader = ({ topInset, onClose, subtitle, title }: HeaderProps) => {
|
|
179
|
+
const { palette } = useUIKitTheme();
|
|
180
|
+
const { defaultHeight } = useHeaderStyle();
|
|
181
|
+
const { left, right } = useSafeAreaInsets();
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<View
|
|
185
|
+
style={[
|
|
186
|
+
styles.headerContainer,
|
|
187
|
+
{
|
|
188
|
+
paddingLeft: styles.headerContainer.paddingHorizontal + left,
|
|
189
|
+
paddingRight: styles.headerContainer.paddingHorizontal + right,
|
|
190
|
+
},
|
|
191
|
+
{ paddingTop: topInset, height: defaultHeight + topInset, backgroundColor: palette.overlay01 },
|
|
192
|
+
]}
|
|
193
|
+
>
|
|
194
|
+
<SBUPressable as={'TouchableOpacity'} onPress={onClose} style={styles.barButton}>
|
|
195
|
+
<Icon icon={'close'} size={24} color={palette.onBackgroundDark01} />
|
|
196
|
+
</SBUPressable>
|
|
197
|
+
<View style={styles.barTitleContainer}>
|
|
198
|
+
<Text h2 color={palette.onBackgroundDark01} style={styles.headerTitle}>
|
|
199
|
+
{title}
|
|
200
|
+
</Text>
|
|
201
|
+
<Text caption2 color={palette.onBackgroundDark01}>
|
|
202
|
+
{subtitle}
|
|
203
|
+
</Text>
|
|
204
|
+
</View>
|
|
205
|
+
<View style={styles.barButton} />
|
|
206
|
+
</View>
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
type FooterProps = {
|
|
211
|
+
bottomInset: number;
|
|
212
|
+
deleteShown: boolean;
|
|
213
|
+
onPressDelete: () => void;
|
|
214
|
+
onPressDownload: () => void;
|
|
215
|
+
};
|
|
216
|
+
const FileViewerFooter = ({ bottomInset, deleteShown, onPressDelete, onPressDownload }: FooterProps) => {
|
|
217
|
+
const { palette } = useUIKitTheme();
|
|
218
|
+
const { defaultHeight } = useHeaderStyle();
|
|
219
|
+
const { left, right } = useSafeAreaInsets();
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
<View
|
|
223
|
+
style={[
|
|
224
|
+
styles.footerContainer,
|
|
225
|
+
{
|
|
226
|
+
paddingLeft: styles.headerContainer.paddingHorizontal + left,
|
|
227
|
+
paddingRight: styles.headerContainer.paddingHorizontal + right,
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
paddingBottom: bottomInset,
|
|
231
|
+
height: defaultHeight + bottomInset,
|
|
232
|
+
backgroundColor: palette.overlay01,
|
|
233
|
+
},
|
|
234
|
+
]}
|
|
235
|
+
>
|
|
236
|
+
<SBUPressable as={'TouchableOpacity'} onPress={onPressDownload} style={styles.barButton}>
|
|
237
|
+
<Icon icon={'download'} size={24} color={palette.onBackgroundDark01} />
|
|
238
|
+
</SBUPressable>
|
|
239
|
+
<View style={styles.barTitleContainer} />
|
|
240
|
+
<SBUPressable as={'TouchableOpacity'} onPress={onPressDelete} style={styles.barButton} disabled={!deleteShown}>
|
|
241
|
+
{deleteShown && <Icon icon={'delete'} size={24} color={palette.onBackgroundDark01} />}
|
|
242
|
+
</SBUPressable>
|
|
243
|
+
</View>
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const styles = createStyleSheet({
|
|
248
|
+
headerContainer: {
|
|
249
|
+
top: 0,
|
|
250
|
+
left: 0,
|
|
251
|
+
right: 0,
|
|
252
|
+
position: 'absolute',
|
|
253
|
+
flexDirection: 'row',
|
|
254
|
+
alignItems: 'center',
|
|
255
|
+
justifyContent: 'center',
|
|
256
|
+
paddingHorizontal: 12,
|
|
257
|
+
},
|
|
258
|
+
barButton: {
|
|
259
|
+
width: 32,
|
|
260
|
+
height: 32,
|
|
261
|
+
alignItems: 'center',
|
|
262
|
+
justifyContent: 'center',
|
|
263
|
+
},
|
|
264
|
+
barTitleContainer: {
|
|
265
|
+
flex: 1,
|
|
266
|
+
alignItems: 'center',
|
|
267
|
+
justifyContent: 'center',
|
|
268
|
+
},
|
|
269
|
+
headerTitle: {
|
|
270
|
+
marginBottom: 2,
|
|
271
|
+
},
|
|
272
|
+
footerContainer: {
|
|
273
|
+
position: 'absolute',
|
|
274
|
+
left: 0,
|
|
275
|
+
right: 0,
|
|
276
|
+
bottom: 0,
|
|
277
|
+
flexDirection: 'row',
|
|
278
|
+
alignItems: 'center',
|
|
279
|
+
justifyContent: 'center',
|
|
280
|
+
paddingHorizontal: 12,
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
export default FileViewer;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useChannelHandler } from '@sendbird/uikit-chat-hooks';
|
|
4
|
+
import {
|
|
5
|
+
GroupChannelPreview,
|
|
6
|
+
LoadingSpinner,
|
|
7
|
+
createStyleSheet,
|
|
8
|
+
useUIKitTheme,
|
|
9
|
+
} from '@sendbird/uikit-react-native-foundation';
|
|
10
|
+
import Icon from '@sendbird/uikit-react-native-foundation/src/ui/Icon';
|
|
11
|
+
import {
|
|
12
|
+
SendbirdGroupChannel,
|
|
13
|
+
SendbirdUser,
|
|
14
|
+
getFileExtension,
|
|
15
|
+
getFileType,
|
|
16
|
+
isDifferentChannel,
|
|
17
|
+
isMyMessage,
|
|
18
|
+
useForceUpdate,
|
|
19
|
+
useIIFE,
|
|
20
|
+
useUniqId,
|
|
21
|
+
} from '@sendbird/uikit-utils';
|
|
22
|
+
|
|
23
|
+
import { useLocalization, useSendbirdChat } from '../hooks/useContext';
|
|
24
|
+
import ChannelCover from './ChannelCover';
|
|
25
|
+
import SBUPressable from './SBUPressable';
|
|
26
|
+
|
|
27
|
+
const iconMapper = { audio: 'file-audio', image: 'photo', video: 'play', file: 'file-document' } as const;
|
|
28
|
+
|
|
29
|
+
type Props = {
|
|
30
|
+
channel: SendbirdGroupChannel;
|
|
31
|
+
onPress: () => void;
|
|
32
|
+
onLongPress: () => void;
|
|
33
|
+
};
|
|
34
|
+
const GroupChannelPreviewContainer = ({ onPress, onLongPress, channel }: Props) => {
|
|
35
|
+
const { currentUser, sdk, features } = useSendbirdChat();
|
|
36
|
+
const { STRINGS } = useLocalization();
|
|
37
|
+
const { colors } = useUIKitTheme();
|
|
38
|
+
|
|
39
|
+
const [typingUsers, setTypingUsers] = useState<SendbirdUser[]>([]);
|
|
40
|
+
const forceUpdate = useForceUpdate();
|
|
41
|
+
|
|
42
|
+
if (features.channelListTypingIndicatorEnabled) {
|
|
43
|
+
const typingId = useUniqId('GroupChannelPreviewContainer');
|
|
44
|
+
useChannelHandler(sdk, `GroupChannelPreviewContainer_TypingIndicator_${typingId}`, {
|
|
45
|
+
onTypingStatusUpdated(eventChannel) {
|
|
46
|
+
if (isDifferentChannel(channel, eventChannel)) return;
|
|
47
|
+
setTypingUsers(eventChannel.getTypingUsers());
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (features.channelListMessageReceiptStatusEnabled) {
|
|
53
|
+
const receiptId = useUniqId('GroupChannelPreviewContainer');
|
|
54
|
+
useChannelHandler(sdk, `GroupChannelPreviewContainer_ReceiptStatus_${receiptId}`, {
|
|
55
|
+
onDeliveryReceiptUpdated(eventChannel) {
|
|
56
|
+
if (isDifferentChannel(channel, eventChannel)) return;
|
|
57
|
+
if (!eventChannel.isGroupChannel() || !eventChannel.lastMessage) return;
|
|
58
|
+
if (!isMyMessage(eventChannel.lastMessage, currentUser?.userId)) return;
|
|
59
|
+
|
|
60
|
+
forceUpdate();
|
|
61
|
+
},
|
|
62
|
+
onReadReceiptUpdated(eventChannel) {
|
|
63
|
+
if (isDifferentChannel(channel, eventChannel)) return;
|
|
64
|
+
if (!eventChannel.isGroupChannel() || !eventChannel.lastMessage) return;
|
|
65
|
+
if (!isMyMessage(eventChannel.lastMessage, currentUser?.userId)) return;
|
|
66
|
+
|
|
67
|
+
forceUpdate();
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const bodyText = useIIFE(() => {
|
|
73
|
+
if (typingUsers.length > 0) return STRINGS.LABELS.TYPING_INDICATOR_TYPINGS(typingUsers) || '';
|
|
74
|
+
else return STRINGS.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_BODY(channel);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const bodyIcon = useIIFE(() => {
|
|
78
|
+
if (!channel.lastMessage?.isFileMessage()) return undefined;
|
|
79
|
+
return iconMapper[getFileType(channel.lastMessage.type || getFileExtension(channel.lastMessage.name))];
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const titleCaptionIcon = useIIFE(() => {
|
|
83
|
+
if (!channel.lastMessage) return undefined;
|
|
84
|
+
if (!features.channelListMessageReceiptStatusEnabled) return undefined;
|
|
85
|
+
if (!isMyMessage(channel.lastMessage, currentUser?.userId)) return undefined;
|
|
86
|
+
|
|
87
|
+
if (channel.lastMessage.sendingStatus === 'pending') {
|
|
88
|
+
return <LoadingSpinner size={16} style={styles.titleCaptionIcon} />;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (channel.lastMessage.sendingStatus === 'failed') {
|
|
92
|
+
return <Icon icon={'error'} size={16} color={colors.error} style={styles.titleCaptionIcon} />;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (channel.getUnreadMemberCount(channel.lastMessage) === 0) {
|
|
96
|
+
return <Icon icon={'done-all'} size={16} color={colors.secondary} style={styles.titleCaptionIcon} />;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (features.deliveryReceiptEnabled) {
|
|
100
|
+
if (channel.getUndeliveredMemberCount(channel.lastMessage) === 0) {
|
|
101
|
+
return <Icon icon={'done-all'} size={16} color={colors.onBackground03} style={styles.titleCaptionIcon} />;
|
|
102
|
+
}
|
|
103
|
+
return <Icon icon={'done'} size={16} color={colors.onBackground03} containerStyle={styles.titleCaptionIcon} />;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return <Icon icon={'done-all'} size={16} color={colors.onBackground03} style={styles.titleCaptionIcon} />;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<SBUPressable onPress={onPress} onLongPress={onLongPress}>
|
|
111
|
+
<GroupChannelPreview
|
|
112
|
+
customCover={<ChannelCover channel={channel} size={56} />}
|
|
113
|
+
coverUrl={channel.coverUrl}
|
|
114
|
+
title={STRINGS.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_TITLE(currentUser?.userId ?? '', channel)}
|
|
115
|
+
titleCaptionLeft={titleCaptionIcon}
|
|
116
|
+
titleCaption={STRINGS.GROUP_CHANNEL_LIST.CHANNEL_PREVIEW_TITLE_CAPTION(channel)}
|
|
117
|
+
body={bodyText}
|
|
118
|
+
bodyIcon={bodyIcon}
|
|
119
|
+
badgeCount={channel.unreadMessageCount}
|
|
120
|
+
memberCount={channel.memberCount > 2 ? channel.memberCount : undefined}
|
|
121
|
+
frozen={channel.isFrozen}
|
|
122
|
+
notificationOff={channel.myPushTriggerOption === 'off'}
|
|
123
|
+
/>
|
|
124
|
+
</SBUPressable>
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const styles = createStyleSheet({
|
|
129
|
+
titleCaptionIcon: {
|
|
130
|
+
marginRight: 4,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export default GroupChannelPreviewContainer;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { Icon, Image, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
|
|
5
|
+
import { getAvailableUriFromFileMessage } from '@sendbird/uikit-utils';
|
|
6
|
+
|
|
7
|
+
import { usePlatformService } from '../../../hooks/useContext';
|
|
8
|
+
import type { FileMessageProps } from './index';
|
|
9
|
+
|
|
10
|
+
const VideoFileMessage = ({ message }: FileMessageProps) => {
|
|
11
|
+
const { colors } = useUIKitTheme();
|
|
12
|
+
|
|
13
|
+
const { mediaService } = usePlatformService();
|
|
14
|
+
const fileUrl = getAvailableUriFromFileMessage(message);
|
|
15
|
+
const style = [styles.image, { backgroundColor: colors.onBackground04 }];
|
|
16
|
+
|
|
17
|
+
const [state, setState] = useState({
|
|
18
|
+
thumbnail: null as null | string,
|
|
19
|
+
loading: true,
|
|
20
|
+
imageNotFound: false,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
mediaService
|
|
25
|
+
?.getVideoThumbnail({ url: fileUrl, timeMills: 1000 })
|
|
26
|
+
.then((result) => {
|
|
27
|
+
if (result?.path) {
|
|
28
|
+
setState((prev) => ({ ...prev, loading: false, thumbnail: result.path }));
|
|
29
|
+
} else {
|
|
30
|
+
throw new Error('Cannot generate thumbnail');
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
.catch(() => {
|
|
34
|
+
setState((prev) => ({ ...prev, loading: false, imageNotFound: true }));
|
|
35
|
+
});
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
if (state.loading || state.imageNotFound) {
|
|
39
|
+
return (
|
|
40
|
+
<View style={[style, styles.container]}>
|
|
41
|
+
<PlayIcon />
|
|
42
|
+
</View>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<View style={styles.container}>
|
|
48
|
+
<Image
|
|
49
|
+
source={{ uri: state.thumbnail || fileUrl }}
|
|
50
|
+
style={style}
|
|
51
|
+
resizeMode={'cover'}
|
|
52
|
+
resizeMethod={'resize'}
|
|
53
|
+
onError={() => setState((prev) => ({ ...prev, imageNotFound: true }))}
|
|
54
|
+
/>
|
|
55
|
+
<PlayIcon />
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const PlayIcon = () => {
|
|
61
|
+
const { colors } = useUIKitTheme();
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Icon
|
|
65
|
+
icon={'play'}
|
|
66
|
+
size={28}
|
|
67
|
+
color={colors.onBackground02}
|
|
68
|
+
containerStyle={[styles.playIcon, { backgroundColor: colors.onBackgroundReverse01 }]}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const styles = createStyleSheet({
|
|
74
|
+
container: {
|
|
75
|
+
alignItems: 'center',
|
|
76
|
+
justifyContent: 'center',
|
|
77
|
+
},
|
|
78
|
+
image: {
|
|
79
|
+
width: 240,
|
|
80
|
+
maxWidth: 240,
|
|
81
|
+
height: 160,
|
|
82
|
+
borderRadius: 16,
|
|
83
|
+
},
|
|
84
|
+
playIcon: {
|
|
85
|
+
position: 'absolute',
|
|
86
|
+
padding: 10,
|
|
87
|
+
borderRadius: 50,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export default VideoFileMessage;
|
|
@@ -2,15 +2,21 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { SendbirdFileMessage, getFileExtension, getFileType } from '@sendbird/uikit-utils';
|
|
4
4
|
|
|
5
|
+
import { usePlatformService } from '../../../hooks/useContext';
|
|
5
6
|
import type { MessageRendererInterface } from '../index';
|
|
6
7
|
import BaseFileMessage from './BaseFileMessage';
|
|
7
8
|
import ImageFileMessage from './ImageFileMessage';
|
|
9
|
+
import VideoFileMessage from './VideoFileMessage';
|
|
8
10
|
|
|
9
11
|
export type FileMessageProps = MessageRendererInterface<SendbirdFileMessage>;
|
|
10
12
|
const FileMessage = (props: FileMessageProps) => {
|
|
13
|
+
const { mediaService } = usePlatformService();
|
|
14
|
+
|
|
11
15
|
const fileType = getFileType(props.message.type || getFileExtension(props.message.name));
|
|
12
16
|
|
|
13
17
|
if (fileType === 'image') return <ImageFileMessage {...props} />;
|
|
18
|
+
if (fileType === 'video' && mediaService?.getVideoThumbnail) return <VideoFileMessage {...props} />;
|
|
19
|
+
|
|
14
20
|
return <BaseFileMessage {...props} type={fileType} />;
|
|
15
21
|
};
|
|
16
22
|
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import React, { useEffect
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
import { Icon, LoadingSpinner, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
SendbirdGroupChannel,
|
|
7
|
-
SendbirdMessage,
|
|
8
|
-
SendbirdUserMessage,
|
|
9
|
-
} from '@sendbird/uikit-utils';
|
|
10
|
-
import { useUniqId } from '@sendbird/uikit-utils';
|
|
4
|
+
import type { SendbirdGroupChannel, SendbirdMessage } from '@sendbird/uikit-utils';
|
|
5
|
+
import { isDifferentChannel, useForceUpdate, useUniqId } from '@sendbird/uikit-utils';
|
|
11
6
|
|
|
12
7
|
import { useSendbirdChat } from '../../hooks/useContext';
|
|
13
8
|
|
|
@@ -17,43 +12,41 @@ type Props = { channel: SendbirdGroupChannel; message: SendbirdMessage };
|
|
|
17
12
|
const MessageOutgoingStatus = ({ channel, message }: Props) => {
|
|
18
13
|
if (!message.isUserMessage() && !message.isFileMessage()) return null;
|
|
19
14
|
|
|
20
|
-
const handlerId = useUniqId('MessageOutgoingStatus');
|
|
21
|
-
|
|
22
15
|
const { sdk, features } = useSendbirdChat();
|
|
23
16
|
const { colors } = useUIKitTheme();
|
|
24
17
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
undeliveredCount: channel.getUndeliveredMemberCount(message),
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
const getCounts = (channel: SendbirdGroupChannel, message: SendbirdUserMessage | SendbirdFileMessage) => {
|
|
31
|
-
return {
|
|
32
|
-
unreadCount: channel.getUnreadMemberCount(message),
|
|
33
|
-
undeliveredCount: channel.getUndeliveredMemberCount(message),
|
|
34
|
-
};
|
|
35
|
-
};
|
|
18
|
+
const uniqId = useUniqId('MessageOutgoingStatus');
|
|
19
|
+
const forceUpdate = useForceUpdate();
|
|
36
20
|
|
|
37
21
|
useEffect(() => {
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
const handlerId = `MessageOutgoingStatus_${uniqId}`;
|
|
23
|
+
|
|
24
|
+
if (
|
|
25
|
+
message.sendingStatus === 'succeeded' &&
|
|
26
|
+
channel.getUnreadMemberCount(message) === 0 &&
|
|
27
|
+
channel.getUndeliveredMemberCount(message) === 0
|
|
28
|
+
) {
|
|
29
|
+
sdk.removeChannelHandler(handlerId);
|
|
41
30
|
} else {
|
|
42
31
|
const handler = new sdk.ChannelHandler();
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
|
|
33
|
+
handler.onReadReceiptUpdated = (eventChannel) => {
|
|
34
|
+
if (isDifferentChannel(channel, eventChannel)) return;
|
|
35
|
+
forceUpdate();
|
|
45
36
|
};
|
|
46
37
|
|
|
47
38
|
if (features.deliveryReceiptEnabled) {
|
|
48
|
-
handler.onDeliveryReceiptUpdated = (
|
|
49
|
-
if (
|
|
39
|
+
handler.onDeliveryReceiptUpdated = (eventChannel) => {
|
|
40
|
+
if (isDifferentChannel(channel, eventChannel)) return;
|
|
41
|
+
forceUpdate();
|
|
50
42
|
};
|
|
51
43
|
}
|
|
52
|
-
|
|
44
|
+
|
|
45
|
+
sdk.addChannelHandler(handlerId, handler);
|
|
53
46
|
}
|
|
54
47
|
|
|
55
48
|
return () => {
|
|
56
|
-
sdk.removeChannelHandler(
|
|
49
|
+
sdk.removeChannelHandler(handlerId);
|
|
57
50
|
};
|
|
58
51
|
}, [message.sendingStatus]);
|
|
59
52
|
|
|
@@ -65,12 +58,12 @@ const MessageOutgoingStatus = ({ channel, message }: Props) => {
|
|
|
65
58
|
return <Icon icon={'error'} size={SIZE} color={colors.error} style={styles.container} />;
|
|
66
59
|
}
|
|
67
60
|
|
|
68
|
-
if (
|
|
61
|
+
if (channel.getUnreadMemberCount(message) === 0) {
|
|
69
62
|
return <Icon icon={'done-all'} size={SIZE} color={colors.secondary} style={styles.container} />;
|
|
70
63
|
}
|
|
71
64
|
|
|
72
65
|
if (features.deliveryReceiptEnabled) {
|
|
73
|
-
if (
|
|
66
|
+
if (channel.getUndeliveredMemberCount(message) === 0) {
|
|
74
67
|
return <Icon icon={'done-all'} size={SIZE} color={colors.onBackground03} style={styles.container} />;
|
|
75
68
|
}
|
|
76
69
|
return <Icon icon={'done'} size={SIZE} color={colors.onBackground03} style={styles.container} />;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Pressable, PressableProps, TouchableOpacity, TouchableOpacityProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { DEFAULT_LONG_PRESS_DELAY } from '../constants';
|
|
5
|
+
|
|
6
|
+
type Components = 'Pressable' | 'TouchableOpacity';
|
|
7
|
+
type Props<T extends Components = 'Pressable'> = {
|
|
8
|
+
as?: T;
|
|
9
|
+
} & ExtractProps<T, AsProps>;
|
|
10
|
+
|
|
11
|
+
type AsProps =
|
|
12
|
+
| {
|
|
13
|
+
type: 'Pressable';
|
|
14
|
+
props: PressableProps;
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
type: 'TouchableOpacity';
|
|
18
|
+
props: TouchableOpacityProps;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type ExtractProps<T extends Components, U extends AsProps> = U extends { type: T; props: infer P } ? P : never;
|
|
22
|
+
|
|
23
|
+
function getComponent(as?: Components) {
|
|
24
|
+
switch (as) {
|
|
25
|
+
case 'Pressable':
|
|
26
|
+
return Pressable;
|
|
27
|
+
case 'TouchableOpacity':
|
|
28
|
+
return TouchableOpacity;
|
|
29
|
+
default:
|
|
30
|
+
return Pressable;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const SBUPressable = <T extends Components>({ as, ...props }: Props<T>) => {
|
|
35
|
+
const Renderer = getComponent(as);
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
return <Renderer delayLongPress={DEFAULT_LONG_PRESS_DELAY} {...props} />;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default SBUPressable;
|