diff --git a/app/containers/message/Components/Attachments/Video.tsx b/app/containers/message/Components/Attachments/Video.tsx index 23b72e6e46..c867fe638e 100644 --- a/app/containers/message/Components/Attachments/Video.tsx +++ b/app/containers/message/Components/Attachments/Video.tsx @@ -1,5 +1,5 @@ -import React, { useContext } from 'react'; -import { StyleProp, StyleSheet, Text, TextStyle, View } from 'react-native'; +import React, { useContext, useEffect, useState } from 'react'; +import { StyleProp, StyleSheet, TextStyle, View } from 'react-native'; import { IUserMessage } from '../../../../definitions'; import { IAttachment } from '../../../../definitions/IAttachment'; @@ -9,31 +9,96 @@ import { fileDownload, isIOS } from '../../../../lib/methods/helpers'; import EventEmitter from '../../../../lib/methods/helpers/events'; import { useTheme } from '../../../../theme'; import sharedStyles from '../../../../views/Styles'; -import { TIconsName } from '../../../CustomIcon'; import { LISTENER } from '../../../Toast'; import Markdown from '../../../markdown'; import MessageContext from '../../Context'; import Touchable from '../../Touchable'; import { useMediaAutoDownload } from '../../hooks/useMediaAutoDownload'; -import BlurComponent from '../OverlayComponent'; -import { TDownloadState } from '../../../../lib/methods/handleMediaDownload'; import messageStyles from '../../styles'; +import { getThumbnailAsync } from 'expo-video-thumbnails'; +import OverlayComponent from '../OverlayComponent'; +import FastImage from 'react-native-fast-image'; +import { CustomIcon } from '../../../CustomIcon'; const SUPPORTED_TYPES = ['video/quicktime', 'video/mp4', ...(isIOS ? [] : ['video/3gp', 'video/mkv'])]; const isTypeSupported = (type: string) => SUPPORTED_TYPES.indexOf(type) !== -1; const styles = StyleSheet.create({ - cancelContainer: { - position: 'absolute', - top: 8, - right: 8 + container: { + flex: 1, + alignItems: 'center', + justifyContent: 'center' + }, + overlay: { + flex: 1 + }, + image: { + width: '100%', + height: '100%' }, - text: { - ...sharedStyles.textRegular, - fontSize: 12 + playerIcon: { + position: 'absolute', + shadowColor: '#000', + shadowOpacity: 0.3, + shadowOffset: { + width: 1, + height: 1 + } } }); +type Image = { + loading: boolean; + uri: string | null; +}; + +type ThumbnailProps = { + url: string; + encrypted?: boolean; +}; + +const Thumbnail = ({ url, encrypted = false }: ThumbnailProps) => { + const icon = encrypted ? 'encrypted' : 'play-filled'; + + const [image, setImage] = useState({ + loading: true, + uri: null + }); + + const generateThumbnail = async () => { + try { + if (!url) return; + + const { uri } = await getThumbnailAsync(url, { + time: 1 + }); + setImage({ + loading: false, + uri + }); + } catch (e) { + console.warn(e); + } + }; + + useEffect(() => { + generateThumbnail(); + }, [url]); + + return ( + + {image.loading || !image.uri ? ( + + ) : ( + <> + + + + )} + + ); +}; + interface IMessageVideo { file: IAttachment; showAttachment?: (file: IAttachment) => void; @@ -44,34 +109,6 @@ interface IMessageVideo { msg?: string; } -const CancelIndicator = () => { - const { colors } = useTheme(); - return ( - - {I18n.t('Cancel')} - - ); -}; - -const Thumbnail = ({ status, encrypted = false }: { status: TDownloadState; encrypted: boolean }) => { - const { colors } = useTheme(); - let icon: TIconsName = status === 'downloaded' ? 'play-filled' : 'arrow-down-circle'; - if (encrypted && status === 'downloaded') { - icon = 'encrypted'; - } - - return ( - <> - - {status === 'loading' ? : null} - - ); -}; - const Video = ({ file, showAttachment, @@ -112,7 +149,7 @@ const Video = ({ <> - + );