vn-verdnaturachat/app/containers/message/Video.js

73 lines
2.1 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { StyleSheet } from 'react-native';
2019-04-08 12:35:28 +00:00
import Touchable from 'react-native-platform-touchable';
import isEqual from 'deep-equal';
import Markdown from '../markdown';
import openLink from '../../utils/openLink';
2019-11-25 20:01:17 +00:00
import { isIOS, isTablet } from '../../utils/deviceInfo';
import { CustomIcon } from '../../lib/Icons';
import { formatAttachmentUrl } from '../../lib/utils';
2019-12-04 16:39:53 +00:00
import { themes } from '../../constants/colors';
2019-11-25 20:01:17 +00:00
import sharedStyles from '../../views/Styles';
const SUPPORTED_TYPES = ['video/quicktime', 'video/mp4', ...(isIOS ? [] : ['video/3gp', 'video/mkv'])];
const isTypeSupported = type => SUPPORTED_TYPES.indexOf(type) !== -1;
const styles = StyleSheet.create({
button: {
flex: 1,
borderRadius: 4,
height: 150,
2019-03-29 19:36:07 +00:00
marginBottom: 6,
alignItems: 'center',
justifyContent: 'center'
}
});
const Video = React.memo(({
2019-12-04 16:39:53 +00:00
file, baseUrl, user, useMarkdown, onOpenFileModal, getCustomEmoji, theme
}) => {
if (!baseUrl) {
return null;
}
const onPress = () => {
if (isTypeSupported(file.video_type)) {
return onOpenFileModal(file);
}
const uri = formatAttachmentUrl(file.video_url, user.id, user.token, baseUrl);
2019-12-04 16:39:53 +00:00
openLink(uri, theme);
};
return (
<>
<Touchable
onPress={onPress}
2019-12-04 16:39:53 +00:00
style={[styles.button, { backgroundColor: themes[theme].videoBackground }, isTablet && sharedStyles.tabletContent]}
background={Touchable.Ripple(themes[theme].bannerBackground)}
>
<CustomIcon
name='play'
size={54}
2019-12-04 16:39:53 +00:00
color={themes[theme].buttonText}
/>
</Touchable>
2019-12-04 16:39:53 +00:00
<Markdown msg={file.description} baseUrl={baseUrl} username={user.username} getCustomEmoji={getCustomEmoji} useMarkdown={useMarkdown} theme={theme} />
</>
);
2019-12-04 16:39:53 +00:00
}, (prevProps, nextProps) => isEqual(prevProps.file, nextProps.file) && prevProps.theme === nextProps.theme);
Video.propTypes = {
file: PropTypes.object,
baseUrl: PropTypes.string,
user: PropTypes.object,
useMarkdown: PropTypes.bool,
onOpenFileModal: PropTypes.func,
2019-12-04 16:39:53 +00:00
getCustomEmoji: PropTypes.func,
theme: PropTypes.string
};
export default Video;