2020-04-30 20:05:59 +00:00
|
|
|
import React, { useContext } from 'react';
|
2017-12-02 13:19:58 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { StyleSheet } from 'react-native';
|
|
|
|
import isEqual from 'deep-equal';
|
2018-09-19 14:18:32 +00:00
|
|
|
|
2020-04-30 20:05:59 +00:00
|
|
|
import Touchable from './Touchable';
|
2019-08-27 12:25:38 +00:00
|
|
|
import Markdown from '../markdown';
|
2017-12-28 17:40:10 +00:00
|
|
|
import openLink from '../../utils/openLink';
|
2020-06-15 14:00:46 +00:00
|
|
|
import { isIOS } from '../../utils/deviceInfo';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { formatAttachmentUrl } from '../../lib/utils';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2020-04-30 20:05:59 +00:00
|
|
|
import MessageContext from './Context';
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-08-30 12:45:56 +00:00
|
|
|
const SUPPORTED_TYPES = ['video/quicktime', 'video/mp4', ...(isIOS ? [] : ['video/3gp', 'video/mkv'])];
|
2017-12-02 13:19:58 +00:00
|
|
|
const isTypeSupported = type => SUPPORTED_TYPES.indexOf(type) !== -1;
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2018-09-11 16:32:52 +00:00
|
|
|
button: {
|
2017-12-02 13:19:58 +00:00
|
|
|
flex: 1,
|
2018-09-11 16:32:52 +00:00
|
|
|
borderRadius: 4,
|
|
|
|
height: 150,
|
2019-03-29 19:36:07 +00:00
|
|
|
marginBottom: 6,
|
2018-09-11 16:32:52 +00:00
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center'
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
const Video = React.memo(({
|
2020-04-30 20:05:59 +00:00
|
|
|
file, showAttachment, getCustomEmoji, theme
|
2019-05-20 20:43:50 +00:00
|
|
|
}) => {
|
2020-04-30 20:05:59 +00:00
|
|
|
const { baseUrl, user } = useContext(MessageContext);
|
2019-05-20 20:43:50 +00:00
|
|
|
if (!baseUrl) {
|
|
|
|
return null;
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
const onPress = () => {
|
2018-09-25 19:28:42 +00:00
|
|
|
if (isTypeSupported(file.video_type)) {
|
2019-12-18 21:13:11 +00:00
|
|
|
return showAttachment(file);
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
const uri = formatAttachmentUrl(file.video_url, user.id, user.token, baseUrl);
|
2019-12-04 16:39:53 +00:00
|
|
|
openLink(uri, theme);
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-05-20 20:43:50 +00:00
|
|
|
<Touchable
|
|
|
|
onPress={onPress}
|
2020-06-15 14:00:46 +00:00
|
|
|
style={[styles.button, { backgroundColor: themes[theme].videoBackground }]}
|
2019-12-04 16:39:53 +00:00
|
|
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
2019-05-20 20:43:50 +00:00
|
|
|
>
|
|
|
|
<CustomIcon
|
2020-07-27 19:53:33 +00:00
|
|
|
name='play-filled'
|
2019-05-20 20:43:50 +00:00
|
|
|
size={54}
|
2019-12-04 16:39:53 +00:00
|
|
|
color={themes[theme].buttonText}
|
2019-05-20 20:43:50 +00:00
|
|
|
/>
|
|
|
|
</Touchable>
|
2020-02-27 18:34:20 +00:00
|
|
|
<Markdown msg={file.description} baseUrl={baseUrl} username={user.username} getCustomEmoji={getCustomEmoji} theme={theme} />
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-05-20 20:43:50 +00:00
|
|
|
);
|
2019-12-04 16:39:53 +00:00
|
|
|
}, (prevProps, nextProps) => isEqual(prevProps.file, nextProps.file) && prevProps.theme === nextProps.theme);
|
2018-09-14 19:39:52 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
Video.propTypes = {
|
|
|
|
file: PropTypes.object,
|
2019-12-18 21:13:11 +00:00
|
|
|
showAttachment: PropTypes.func,
|
2019-12-04 16:39:53 +00:00
|
|
|
getCustomEmoji: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
2018-09-14 19:39:52 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
export default Video;
|