2017-12-02 13:19:58 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-04-24 19:34:03 +00:00
|
|
|
import { StyleSheet, TouchableOpacity, Image, Platform } from 'react-native';
|
2017-12-02 13:19:58 +00:00
|
|
|
import Modal from 'react-native-modal';
|
|
|
|
import VideoPlayer from 'react-native-video-controls';
|
2018-04-24 19:34:03 +00:00
|
|
|
import { connect } from 'react-redux';
|
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';
|
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({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
height: 100,
|
|
|
|
margin: 5
|
|
|
|
},
|
|
|
|
modal: {
|
|
|
|
margin: 0,
|
|
|
|
backgroundColor: '#000'
|
|
|
|
},
|
|
|
|
image: {
|
|
|
|
flex: 1,
|
|
|
|
width: null,
|
|
|
|
height: null,
|
|
|
|
resizeMode: 'contain'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
@connect(state => ({
|
|
|
|
baseUrl: state.settings.Site_Url || state.server ? state.server.server : ''
|
|
|
|
}))
|
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,
|
|
|
|
user: PropTypes.object.isRequired
|
|
|
|
}
|
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
state = { isVisible: false };
|
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();
|
|
|
|
}
|
2017-12-28 17:40:10 +00:00
|
|
|
openLink(this.state.uri);
|
2017-12-02 13:19:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-03-23 16:49:51 +00:00
|
|
|
const { isVisible } = this.state;
|
|
|
|
const { video_url, description } = this.props.file;
|
|
|
|
const { baseUrl, user } = this.props;
|
|
|
|
const uri = `${ baseUrl }${ video_url }?rc_uid=${ user.id }&rc_token=${ user.token }`;
|
2017-12-02 13:19:58 +00:00
|
|
|
return (
|
2018-04-24 19:34:03 +00:00
|
|
|
[
|
2017-12-02 13:19:58 +00:00
|
|
|
<TouchableOpacity
|
2018-04-24 19:34:03 +00:00
|
|
|
key='button'
|
2017-12-02 13:19:58 +00:00
|
|
|
style={styles.container}
|
|
|
|
onPress={() => this.open()}
|
|
|
|
>
|
|
|
|
<Image
|
2018-04-24 19:34:03 +00:00
|
|
|
source={require('../../static/images/logo.png')}
|
2017-12-02 13:19:58 +00:00
|
|
|
style={styles.image}
|
|
|
|
/>
|
|
|
|
<Markdown msg={description} />
|
2018-04-24 19:34:03 +00:00
|
|
|
</TouchableOpacity>,
|
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
|
|
|
|
source={{ uri }}
|
|
|
|
onBack={() => this.toggleModal()}
|
|
|
|
disableVolume
|
|
|
|
/>
|
|
|
|
</Modal>
|
2018-04-24 19:34:03 +00:00
|
|
|
]
|
2017-12-02 13:19:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|