remove generate thumbnail
This commit is contained in:
parent
71ec9698c9
commit
7e81d41eec
|
@ -1,7 +1,6 @@
|
||||||
import React, { useContext, useEffect, useState } from 'react';
|
import React, { useContext, useEffect, useState } from 'react';
|
||||||
import { StyleProp, StyleSheet, TextStyle, View, Text } from 'react-native';
|
import { StyleProp, StyleSheet, TextStyle, View, Text } from 'react-native';
|
||||||
import { dequal } from 'dequal';
|
import { dequal } from 'dequal';
|
||||||
import * as VideoThumbnails from 'expo-video-thumbnails';
|
|
||||||
import FastImage from 'react-native-fast-image';
|
import FastImage from 'react-native-fast-image';
|
||||||
|
|
||||||
import messageStyles from './styles';
|
import messageStyles from './styles';
|
||||||
|
@ -18,17 +17,10 @@ import { IAttachment } from '../../definitions/IAttachment';
|
||||||
import { TGetCustomEmoji } from '../../definitions/IEmoji';
|
import { TGetCustomEmoji } from '../../definitions/IEmoji';
|
||||||
import { useTheme } from '../../theme';
|
import { useTheme } from '../../theme';
|
||||||
import { formatAttachmentUrl } from '../../lib/methods/helpers/formatAttachmentUrl';
|
import { formatAttachmentUrl } from '../../lib/methods/helpers/formatAttachmentUrl';
|
||||||
import {
|
import { cancelDownload, downloadMediaFile, isDownloadActive, getMediaCache } from '../../lib/methods/handleMediaDownload';
|
||||||
cancelDownload,
|
|
||||||
downloadMediaFile,
|
|
||||||
isDownloadActive,
|
|
||||||
getMediaCache,
|
|
||||||
getFileInfoAsync
|
|
||||||
} from '../../lib/methods/handleMediaDownload';
|
|
||||||
import { fetchAutoDownloadEnabled } from '../../lib/methods/autoDownloadPreference';
|
import { fetchAutoDownloadEnabled } from '../../lib/methods/autoDownloadPreference';
|
||||||
import sharedStyles from '../../views/Styles';
|
import sharedStyles from '../../views/Styles';
|
||||||
import BlurComponent from './Components/BlurComponent';
|
import BlurComponent from './Components/BlurComponent';
|
||||||
import { useUserPreferences } from '../../lib/methods';
|
|
||||||
|
|
||||||
const SUPPORTED_TYPES = ['video/quicktime', 'video/mp4', ...(isIOS ? [] : ['video/3gp', 'video/mkv'])];
|
const SUPPORTED_TYPES = ['video/quicktime', 'video/mp4', ...(isIOS ? [] : ['video/3gp', 'video/mkv'])];
|
||||||
const isTypeSupported = (type: string) => SUPPORTED_TYPES.indexOf(type) !== -1;
|
const isTypeSupported = (type: string) => SUPPORTED_TYPES.indexOf(type) !== -1;
|
||||||
|
@ -75,38 +67,10 @@ const CancelIndicator = () => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Thumbnail = ({ loading, video, cached }: { loading: boolean; video: string; cached: boolean }) => {
|
// TODO: Wait backend send the thumbnailUrl as prop
|
||||||
const [thumbnailImage, setThumbnailImage] = useUserPreferences(`thumbnail-${video}`, '');
|
const Thumbnail = ({ loading, thumbnailUrl, cached }: { loading: boolean; thumbnailUrl?: string; cached: boolean }) => (
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const generateThumbnail = async () => {
|
|
||||||
try {
|
|
||||||
const { uri } = await VideoThumbnails.getThumbnailAsync(video, {
|
|
||||||
time: 1
|
|
||||||
});
|
|
||||||
setThumbnailImage(uri);
|
|
||||||
} catch (e) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleThumbnailSearch = async () => {
|
|
||||||
const file = await getFileInfoAsync(thumbnailImage);
|
|
||||||
if (!file.exists) {
|
|
||||||
generateThumbnail();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!thumbnailImage) {
|
|
||||||
generateThumbnail();
|
|
||||||
} else {
|
|
||||||
handleThumbnailSearch();
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
<>
|
||||||
{thumbnailImage ? <FastImage style={styles.thumbnailImage} source={{ uri: thumbnailImage }} /> : null}
|
{thumbnailUrl ? <FastImage style={styles.thumbnailImage} source={{ uri: thumbnailUrl }} /> : null}
|
||||||
<BlurComponent
|
<BlurComponent
|
||||||
iconName={cached ? 'play-filled' : 'arrow-down-circle'}
|
iconName={cached ? 'play-filled' : 'arrow-down-circle'}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
|
@ -115,8 +79,7 @@ const Thumbnail = ({ loading, video, cached }: { loading: boolean; video: string
|
||||||
/>
|
/>
|
||||||
{loading ? <CancelIndicator /> : null}
|
{loading ? <CancelIndicator /> : null}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
const Video = React.memo(
|
const Video = React.memo(
|
||||||
({ file, showAttachment, getCustomEmoji, style, isReply }: IMessageVideo) => {
|
({ file, showAttachment, getCustomEmoji, style, isReply }: IMessageVideo) => {
|
||||||
|
@ -245,7 +208,7 @@ const Video = React.memo(
|
||||||
style={[styles.button, messageStyles.mustWrapBlur, { backgroundColor: themes[theme].videoBackground }]}
|
style={[styles.button, messageStyles.mustWrapBlur, { backgroundColor: themes[theme].videoBackground }]}
|
||||||
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
||||||
>
|
>
|
||||||
<Thumbnail loading={loading} video={video} cached={cached} />
|
<Thumbnail loading={loading} cached={cached} />
|
||||||
</Touchable>
|
</Touchable>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue