2017-12-02 13:19:58 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-09-11 16:32:52 +00:00
|
|
|
import { StyleSheet, TouchableOpacity, Image, Platform, 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';
|
|
|
|
import Markdown from './Markdown';
|
2017-12-28 17:40:10 +00:00
|
|
|
import openLink from '../../utils/openLink';
|
2017-12-02 13:19:58 +00:00
|
|
|
|
|
|
|
const SUPPORTED_TYPES = ['video/quicktime', 'video/mp4', ...(Platform.OS === 'ios' ? [] : ['video/webm', 'video/3gp', 'video/mkv'])];
|
|
|
|
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',
|
|
|
|
marginBottom: 10,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center'
|
2017-12-02 13:19:58 +00:00
|
|
|
},
|
|
|
|
modal: {
|
|
|
|
margin: 0,
|
|
|
|
backgroundColor: '#000'
|
|
|
|
},
|
|
|
|
image: {
|
2018-09-11 16:32:52 +00:00
|
|
|
width: 54,
|
|
|
|
height: 54
|
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() {
|
|
|
|
const { video_url } = this.props.file;
|
|
|
|
const { baseUrl, user } = this.props;
|
|
|
|
return `${ baseUrl }${ video_url }?rc_uid=${ user.id }&rc_token=${ user.token }`;
|
|
|
|
}
|
|
|
|
|
2017-12-02 13:19:58 +00:00
|
|
|
toggleModal() {
|
|
|
|
this.setState({
|
|
|
|
isVisible: !this.state.isVisible
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
open() {
|
|
|
|
if (isTypeSupported(this.props.file.video_type)) {
|
|
|
|
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-08-31 18:15:05 +00:00
|
|
|
const { description } = this.props.file;
|
2018-09-11 16:32:52 +00:00
|
|
|
const { baseUrl, user, customEmojis } = this.props;
|
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'>
|
|
|
|
<TouchableOpacity
|
|
|
|
style={styles.button}
|
|
|
|
onPress={() => this.open()}
|
|
|
|
>
|
|
|
|
<Image
|
|
|
|
source={{ uri: 'play_video' }}
|
|
|
|
style={styles.image}
|
|
|
|
/>
|
|
|
|
</TouchableOpacity>
|
|
|
|
<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 }}
|
2017-12-02 13:19:58 +00:00
|
|
|
onBack={() => this.toggleModal()}
|
|
|
|
disableVolume
|
|
|
|
/>
|
|
|
|
</Modal>
|
2018-04-24 19:34:03 +00:00
|
|
|
]
|
2017-12-02 13:19:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|