2017-12-02 13:19:58 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { StyleSheet } from 'react-native';
|
2019-04-08 12:35:28 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2019-05-20 20:43:50 +00:00
|
|
|
import isEqual from 'deep-equal';
|
2018-09-19 14:18:32 +00:00
|
|
|
|
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';
|
2019-01-29 19:52:56 +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';
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-01-29 19:52:56 +00:00
|
|
|
const SUPPORTED_TYPES = ['video/quicktime', 'video/mp4', ...(isIOS ? [] : ['video/webm', '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,
|
|
|
|
backgroundColor: '#1f2329',
|
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
|
|
|
},
|
|
|
|
modal: {
|
|
|
|
margin: 0,
|
|
|
|
backgroundColor: '#000'
|
|
|
|
},
|
|
|
|
image: {
|
2019-03-01 16:49:11 +00:00
|
|
|
color: 'white'
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
const Video = React.memo(({
|
|
|
|
file, baseUrl, user, useMarkdown, onOpenFileModal, getCustomEmoji
|
|
|
|
}) => {
|
|
|
|
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-05-20 20:43:50 +00:00
|
|
|
return onOpenFileModal(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);
|
|
|
|
openLink(uri);
|
|
|
|
};
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<Touchable
|
|
|
|
onPress={onPress}
|
|
|
|
style={styles.button}
|
|
|
|
background={Touchable.Ripple('#fff')}
|
|
|
|
>
|
|
|
|
<CustomIcon
|
|
|
|
name='play'
|
|
|
|
size={54}
|
|
|
|
style={styles.image}
|
|
|
|
/>
|
|
|
|
</Touchable>
|
|
|
|
<Markdown msg={file.description} baseUrl={baseUrl} username={user.username} getCustomEmoji={getCustomEmoji} useMarkdown={useMarkdown} />
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}, (prevProps, nextProps) => isEqual(prevProps.file, nextProps.file));
|
2018-09-14 19:39:52 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
Video.propTypes = {
|
|
|
|
file: PropTypes.object,
|
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
user: PropTypes.object,
|
|
|
|
useMarkdown: PropTypes.bool,
|
|
|
|
onOpenFileModal: PropTypes.func,
|
|
|
|
getCustomEmoji: PropTypes.func
|
|
|
|
};
|
2018-09-14 19:39:52 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
export default Video;
|