Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: remove video thumbnails #5963

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 40 additions & 79 deletions app/containers/message/Components/Attachments/Video.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useContext, useEffect, useState } from 'react';
import { StyleProp, StyleSheet, TextStyle, View } from 'react-native';
import FastImage from 'react-native-fast-image';
import { getThumbnailAsync } from 'expo-video-thumbnails';
import React, { useContext } from 'react';
import { StyleProp, StyleSheet, Text, TextStyle, View } from 'react-native';

import { IUserMessage } from '../../../../definitions';
import { IAttachment } from '../../../../definitions/IAttachment';
Expand All @@ -10,107 +8,70 @@ import I18n from '../../../../i18n';
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 messageStyles from '../../styles';
import OverlayComponent from '../OverlayComponent';
import { CustomIcon, TIconsName } from '../../../CustomIcon';
import { themes } from '../../../../lib/constants';
import BlurComponent from '../OverlayComponent';
import { TDownloadState } from '../../../../lib/methods/handleMediaDownload';
import messageStyles from '../../styles';

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({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
},
overlay: {
flex: 1
},
image: {
width: '100%',
height: '100%'
},
playerIcon: {
cancelContainer: {
position: 'absolute',
textShadowRadius: 3,
textShadowOffset: {
width: 0.5,
height: 0.5
}
top: 8,
right: 8
},
text: {
...sharedStyles.textRegular,
fontSize: 12
}
});

type TThumbnailImage = string | null;
interface IMessageVideo {
file: IAttachment;
showAttachment?: (file: IAttachment) => void;
getCustomEmoji: TGetCustomEmoji;
author?: IUserMessage;
style?: StyleProp<TextStyle>[];
isReply?: boolean;
msg?: string;
}

type ThumbnailProps = {
url: string;
status: TDownloadState;
encrypted?: boolean;
const CancelIndicator = () => {
const { colors } = useTheme();
return (
<View style={styles.cancelContainer}>
<Text style={[styles.text, { color: colors.fontSecondaryInfo }]}>{I18n.t('Cancel')}</Text>
</View>
);
};

const Thumbnail = ({ url, status, encrypted = false }: ThumbnailProps) => {
const { theme } = useTheme();

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';
}

const [image, setImage] = useState<TThumbnailImage>(null);

const generateThumbnail = async () => {
try {
if (!url) return;

const { uri } = await getThumbnailAsync(url, {
time: 1
});
setImage(uri);
} catch (e) {
console.warn(e);
}
};

useEffect(() => {
generateThumbnail();
}, [url]);

return (
<View style={styles.container}>
{status === 'loading' || !image || encrypted ? (
<OverlayComponent style={styles.overlay} loading={status === 'loading'} iconName={icon} />
) : (
<>
<FastImage style={styles.image} resizeMode='cover' source={{ uri: image }} />
<CustomIcon
name={icon}
size={54}
color={themes[theme].fontPureWhite}
style={[styles.playerIcon, { textShadowColor: themes[theme].backdropColor }]}
/>
</>
)}
</View>
<>
<BlurComponent
iconName={icon}
loading={status === 'loading'}
style={[messageStyles.image, { borderColor: colors.strokeLight, borderWidth: 1 }]}
/>
{status === 'loading' ? <CancelIndicator /> : null}
</>
);
};

interface IMessageVideo {
file: IAttachment;
showAttachment?: (file: IAttachment) => void;
getCustomEmoji: TGetCustomEmoji;
author?: IUserMessage;
style?: StyleProp<TextStyle>[];
isReply?: boolean;
msg?: string;
}

const Video = ({
file,
showAttachment,
Expand Down Expand Up @@ -151,7 +112,7 @@ const Video = ({
<>
<Markdown msg={msg} username={user.username} getCustomEmoji={getCustomEmoji} style={[isReply && style]} theme={theme} />
<Touchable onPress={_onPress} style={messageStyles.image} background={Touchable.Ripple(colors.surfaceNeutral)}>
<Thumbnail status={status} url={url} encrypted={isEncrypted} />
<Thumbnail status={status} encrypted={isEncrypted} />
</Touchable>
</>
);
Expand Down