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-09-03 19:27:57 +00:00
|
|
|
import Markdown from '../markdown';
|
2017-12-28 17:40:10 +00:00
|
|
|
import openLink from '../../utils/openLink';
|
2019-12-11 23:01:12 +00:00
|
|
|
import { isIOS, isTablet } 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-11 23:01:12 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import sharedStyles from '../../views/Styles';
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-09-03 19:27:57 +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(({
|
2019-12-11 23:01:12 +00:00
|
|
|
file, baseUrl, user, useMarkdown, onOpenFileModal, getCustomEmoji, theme
|
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-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);
|
2019-12-11 23:01:12 +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-10-07 20:56:30 +00:00
|
|
|
<>
|
2019-05-20 20:43:50 +00:00
|
|
|
<Touchable
|
|
|
|
onPress={onPress}
|
2019-12-11 23:01:12 +00:00
|
|
|
style={[styles.button, { backgroundColor: themes[theme].videoBackground }, isTablet && sharedStyles.tabletContent]}
|
|
|
|
background={Touchable.Ripple(themes[theme].bannerBackground)}
|
2019-05-20 20:43:50 +00:00
|
|
|
>
|
|
|
|
<CustomIcon
|
|
|
|
name='play'
|
|
|
|
size={54}
|
2019-12-11 23:01:12 +00:00
|
|
|
color={themes[theme].buttonText}
|
2019-05-20 20:43:50 +00:00
|
|
|
/>
|
|
|
|
</Touchable>
|
2019-12-11 23:01:12 +00:00
|
|
|
<Markdown msg={file.description} baseUrl={baseUrl} username={user.username} getCustomEmoji={getCustomEmoji} useMarkdown={useMarkdown} theme={theme} />
|
2019-10-07 20:56:30 +00:00
|
|
|
</>
|
2019-05-20 20:43:50 +00:00
|
|
|
);
|
2019-12-11 23:01:12 +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,
|
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
user: PropTypes.object,
|
|
|
|
useMarkdown: PropTypes.bool,
|
|
|
|
onOpenFileModal: PropTypes.func,
|
2019-12-11 23:01:12 +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;
|