2017-12-02 13:19:58 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { StyleSheet, View } from 'react-native';
|
2017-12-02 13:19:58 +00:00
|
|
|
import Modal from 'react-native-modal';
|
|
|
|
import VideoPlayer from 'react-native-video-controls';
|
2019-04-08 12:35:28 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2018-09-19 14:18:32 +00:00
|
|
|
|
2017-12-02 13:19:58 +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';
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default class Video extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
file: PropTypes.object.isRequired,
|
|
|
|
baseUrl: PropTypes.string.isRequired,
|
2018-09-11 16:32:52 +00:00
|
|
|
user: PropTypes.object.isRequired,
|
|
|
|
customEmojis: PropTypes.object.isRequired
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
state = { isVisible: false };
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2018-08-31 18:15:05 +00:00
|
|
|
get uri() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { baseUrl, user, file } = this.props;
|
|
|
|
const { video_url } = file;
|
2018-08-31 18:15:05 +00:00
|
|
|
return `${ baseUrl }${ video_url }?rc_uid=${ user.id }&rc_token=${ user.token }`;
|
|
|
|
}
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
toggleModal = () => {
|
2018-09-25 19:28:42 +00:00
|
|
|
this.setState(prevState => ({
|
|
|
|
isVisible: !prevState.isVisible
|
|
|
|
}));
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
open = () => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { file } = this.props;
|
|
|
|
if (isTypeSupported(file.video_type)) {
|
2017-12-02 13:19:58 +00:00
|
|
|
return this.toggleModal();
|
|
|
|
}
|
2018-08-31 18:15:05 +00:00
|
|
|
openLink(this.uri);
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-03-23 16:49:51 +00:00
|
|
|
const { isVisible } = this.state;
|
2018-09-25 19:28:42 +00:00
|
|
|
const {
|
|
|
|
baseUrl, user, customEmojis, file
|
|
|
|
} = this.props;
|
|
|
|
const { description } = file;
|
2018-09-14 19:39:52 +00:00
|
|
|
|
|
|
|
if (!baseUrl) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-12-02 13:19:58 +00:00
|
|
|
return (
|
2018-04-24 19:34:03 +00:00
|
|
|
[
|
2018-09-11 16:32:52 +00:00
|
|
|
<View key='button'>
|
2019-04-08 12:35:28 +00:00
|
|
|
<Touchable
|
|
|
|
onPress={this.open}
|
2018-09-11 16:32:52 +00:00
|
|
|
style={styles.button}
|
2019-04-08 12:35:28 +00:00
|
|
|
background={Touchable.Ripple('#fff')}
|
2018-09-11 16:32:52 +00:00
|
|
|
>
|
2019-03-01 16:49:11 +00:00
|
|
|
<CustomIcon
|
|
|
|
name='play'
|
|
|
|
size={54}
|
2018-09-11 16:32:52 +00:00
|
|
|
style={styles.image}
|
|
|
|
/>
|
2019-04-08 12:35:28 +00:00
|
|
|
</Touchable>
|
2018-09-11 16:32:52 +00:00
|
|
|
<Markdown msg={description} customEmojis={customEmojis} baseUrl={baseUrl} username={user.username} />
|
|
|
|
</View>,
|
2017-12-02 13:19:58 +00:00
|
|
|
<Modal
|
2018-04-24 19:34:03 +00:00
|
|
|
key='modal'
|
2017-12-02 13:19:58 +00:00
|
|
|
isVisible={isVisible}
|
|
|
|
style={styles.modal}
|
|
|
|
supportedOrientations={['portrait', 'landscape']}
|
2018-03-23 16:49:51 +00:00
|
|
|
onBackButtonPress={() => this.toggleModal()}
|
2017-12-02 13:19:58 +00:00
|
|
|
>
|
|
|
|
<VideoPlayer
|
2018-08-31 18:15:05 +00:00
|
|
|
source={{ uri: this.uri }}
|
2019-04-08 12:35:28 +00:00
|
|
|
onBack={this.toggleModal}
|
2017-12-02 13:19:58 +00:00
|
|
|
disableVolume
|
|
|
|
/>
|
|
|
|
</Modal>
|
2018-04-24 19:34:03 +00:00
|
|
|
]
|
2017-12-02 13:19:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|