Merge remote-tracking branch 'origin/master' into keep-awake
This commit is contained in:
commit
5a55beee7b
4 changed files with 78 additions and 14 deletions
|
@ -41,7 +41,8 @@ class MediaPlayer extends React.PureComponent {
|
||||||
controlsTimeout: -1,
|
controlsTimeout: -1,
|
||||||
seekerOffset: 0,
|
seekerOffset: 0,
|
||||||
seekerPosition: 0,
|
seekerPosition: 0,
|
||||||
firstPlay: true
|
firstPlay: true,
|
||||||
|
seekTimeout: -1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,6 +177,9 @@ class MediaPlayer extends React.PureComponent {
|
||||||
|
|
||||||
onPanResponderGrant: (evt, gestureState) => {
|
onPanResponderGrant: (evt, gestureState) => {
|
||||||
this.clearControlsTimeout();
|
this.clearControlsTimeout();
|
||||||
|
if (this.state.seekTimeout > 0) {
|
||||||
|
clearTimeout(this.state.seekTimeout);
|
||||||
|
}
|
||||||
this.setState({ seeking: true });
|
this.setState({ seeking: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -191,7 +195,7 @@ class MediaPlayer extends React.PureComponent {
|
||||||
this.onEnd();
|
this.onEnd();
|
||||||
} else {
|
} else {
|
||||||
this.seekTo(time);
|
this.seekTo(time);
|
||||||
this.setState({ seeking: false });
|
this.setState({ seekTimeout: setTimeout(() => { this.setState({ seeking: false }); }, 100) });
|
||||||
}
|
}
|
||||||
this.hidePlayerControls();
|
this.hidePlayerControls();
|
||||||
}
|
}
|
||||||
|
@ -262,7 +266,7 @@ class MediaPlayer extends React.PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { backgroundPlayEnabled, fileInfo, thumbnail, style } = this.props;
|
const { backgroundPlayEnabled, fileInfo, thumbnail, onLayout, style } = this.props;
|
||||||
const flexCompleted = this.getCurrentTimePercentage() * 100;
|
const flexCompleted = this.getCurrentTimePercentage() * 100;
|
||||||
const flexRemaining = (1 - this.getCurrentTimePercentage()) * 100;
|
const flexRemaining = (1 - this.getCurrentTimePercentage()) * 100;
|
||||||
let styles = [this.state.fullscreenMode ? mediaPlayerStyle.fullscreenContainer : mediaPlayerStyle.container];
|
let styles = [this.state.fullscreenMode ? mediaPlayerStyle.fullscreenContainer : mediaPlayerStyle.container];
|
||||||
|
@ -278,7 +282,7 @@ class MediaPlayer extends React.PureComponent {
|
||||||
mediaPlayerStyle.fullscreenTrackingControls : mediaPlayerStyle.containedTrackingControls];
|
mediaPlayerStyle.fullscreenTrackingControls : mediaPlayerStyle.containedTrackingControls];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles}>
|
<View style={styles} onLayout={onLayout}>
|
||||||
<Video source={{ uri: 'file:///' + fileInfo.download_path }}
|
<Video source={{ uri: 'file:///' + fileInfo.download_path }}
|
||||||
ref={(ref: Video) => { this.video = ref }}
|
ref={(ref: Video) => { this.video = ref }}
|
||||||
resizeMode={this.state.resizeMode}
|
resizeMode={this.state.resizeMode}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
ActivityIndicator,
|
ActivityIndicator,
|
||||||
Alert,
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
|
Dimensions,
|
||||||
NativeModules,
|
NativeModules,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
StatusBar,
|
StatusBar,
|
||||||
|
@ -25,12 +26,17 @@ import MediaPlayer from '../../component/mediaPlayer';
|
||||||
import UriBar from '../../component/uriBar';
|
import UriBar from '../../component/uriBar';
|
||||||
import Video from 'react-native-video';
|
import Video from 'react-native-video';
|
||||||
import filePageStyle from '../../styles/filePage';
|
import filePageStyle from '../../styles/filePage';
|
||||||
|
import uriBarStyle from '../../styles/uriBar';
|
||||||
|
|
||||||
class FilePage extends React.PureComponent {
|
class FilePage extends React.PureComponent {
|
||||||
static navigationOptions = {
|
static navigationOptions = {
|
||||||
title: ''
|
title: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
playerBackground = null;
|
||||||
|
|
||||||
|
player = null;
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -39,7 +45,10 @@ class FilePage extends React.PureComponent {
|
||||||
fullscreenMode: false,
|
fullscreenMode: false,
|
||||||
showImageViewer: false,
|
showImageViewer: false,
|
||||||
showWebView: false,
|
showWebView: false,
|
||||||
imageUrls: null
|
imageUrls: null,
|
||||||
|
playerBgHeight: 0,
|
||||||
|
playerHeight: 0,
|
||||||
|
isLandscape: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +100,8 @@ class FilePage extends React.PureComponent {
|
||||||
// fullscreen, so change orientation to landscape mode
|
// fullscreen, so change orientation to landscape mode
|
||||||
NativeModules.ScreenOrientation.lockOrientationLandscape();
|
NativeModules.ScreenOrientation.lockOrientationLandscape();
|
||||||
} else {
|
} else {
|
||||||
NativeModules.ScreenOrientation.unlockOrientation();
|
// Switch back to portrait mode when the media is not fullscreen
|
||||||
|
NativeModules.ScreenOrientation.lockOrientationPortrait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,6 +180,24 @@ class FilePage extends React.PureComponent {
|
||||||
return linkifiedContent;
|
return linkifiedContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkOrientation = () => {
|
||||||
|
if (this.state.fullscreenMode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const screenDimension = Dimensions.get('window');
|
||||||
|
const screenWidth = screenDimension.width;
|
||||||
|
const screenHeight = screenDimension.height;
|
||||||
|
const isLandscape = screenWidth > screenHeight;
|
||||||
|
this.setState({ isLandscape });
|
||||||
|
|
||||||
|
if (isLandscape) {
|
||||||
|
this.playerBackground.setNativeProps({ height: screenHeight - StyleSheet.flatten(uriBarStyle.uriContainer).height });
|
||||||
|
} else if (this.state.playerBgHeight > 0) {
|
||||||
|
this.playerBackground.setNativeProps({ height: this.state.playerBgHeight });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
claim,
|
claim,
|
||||||
|
@ -218,8 +246,9 @@ class FilePage extends React.PureComponent {
|
||||||
const channelClaimId =
|
const channelClaimId =
|
||||||
value && value.publisherSignature && value.publisherSignature.certificateId;
|
value && value.publisherSignature && value.publisherSignature.certificateId;
|
||||||
|
|
||||||
const playerStyle = [filePageStyle.player, this.state.fullscreenMode ?
|
const playerStyle = [filePageStyle.player,
|
||||||
filePageStyle.fullscreenPlayer : filePageStyle.containedPlayer];
|
this.state.isLandscape ? filePageStyle.containedPlayerLandscape :
|
||||||
|
(this.state.fullscreenMode ? filePageStyle.fullscreenPlayer : filePageStyle.containedPlayer)];
|
||||||
const playerBgStyle = [filePageStyle.playerBackground, this.state.fullscreenMode ?
|
const playerBgStyle = [filePageStyle.playerBackground, this.state.fullscreenMode ?
|
||||||
filePageStyle.fullscreenPlayerBackground : filePageStyle.containedPlayerBackground];
|
filePageStyle.fullscreenPlayerBackground : filePageStyle.containedPlayerBackground];
|
||||||
// at least 2MB (or the full download) before media can be loaded
|
// at least 2MB (or the full download) before media can be loaded
|
||||||
|
@ -257,7 +286,8 @@ class FilePage extends React.PureComponent {
|
||||||
renderIndicator={() => null} />}
|
renderIndicator={() => null} />}
|
||||||
|
|
||||||
{!this.state.showWebView && (
|
{!this.state.showWebView && (
|
||||||
<View style={filePageStyle.innerPageContainer}>
|
<View style={this.state.fullscreenMode ? filePageStyle.innerPageContainerFsMode : filePageStyle.innerPageContainer}
|
||||||
|
onLayout={this.checkOrientation}>
|
||||||
<View style={filePageStyle.mediaContainer}>
|
<View style={filePageStyle.mediaContainer}>
|
||||||
{(canOpen || (!fileInfo || (isPlayable && !canLoadMedia))) &&
|
{(canOpen || (!fileInfo || (isPlayable && !canLoadMedia))) &&
|
||||||
<FileItemMedia style={filePageStyle.thumbnail} title={title} thumbnail={metadata.thumbnail} />}
|
<FileItemMedia style={filePageStyle.thumbnail} title={title} thumbnail={metadata.thumbnail} />}
|
||||||
|
@ -270,13 +300,25 @@ class FilePage extends React.PureComponent {
|
||||||
onPlay={() => this.setState({ autoPlayMedia: true })} />}
|
onPlay={() => this.setState({ autoPlayMedia: true })} />}
|
||||||
{!fileInfo && <FilePrice uri={uri} style={filePageStyle.filePriceContainer} textStyle={filePageStyle.filePriceText} />}
|
{!fileInfo && <FilePrice uri={uri} style={filePageStyle.filePriceContainer} textStyle={filePageStyle.filePriceText} />}
|
||||||
</View>
|
</View>
|
||||||
{canLoadMedia && <View style={playerBgStyle} />}
|
{canLoadMedia && <View style={playerBgStyle} ref={(ref) => { this.playerBackground = ref; }}
|
||||||
|
onLayout={(evt) => {
|
||||||
|
if (!this.state.playerBgHeight) {
|
||||||
|
this.setState({ playerBgHeight: evt.nativeEvent.layout.height });
|
||||||
|
}
|
||||||
|
}} />}
|
||||||
{canLoadMedia && <MediaPlayer fileInfo={fileInfo}
|
{canLoadMedia && <MediaPlayer fileInfo={fileInfo}
|
||||||
|
ref={(ref) => { this.player = ref; }}
|
||||||
uri={uri}
|
uri={uri}
|
||||||
style={playerStyle}
|
style={playerStyle}
|
||||||
autoPlay={this.state.autoPlayMedia}
|
autoPlay={this.state.autoPlayMedia}
|
||||||
onFullscreenToggled={this.handleFullscreenToggle}
|
onFullscreenToggled={this.handleFullscreenToggle}
|
||||||
onMediaLoaded={() => { this.setState({ mediaLoaded: true }); }}/>}
|
onMediaLoaded={() => { this.setState({ mediaLoaded: true }); }}
|
||||||
|
onLayout={(evt) => {
|
||||||
|
if (!this.state.playerHeight) {
|
||||||
|
this.setState({ playerHeight: evt.nativeEvent.layout.height });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>}
|
||||||
|
|
||||||
{ showActions &&
|
{ showActions &&
|
||||||
<View style={filePageStyle.actions}>
|
<View style={filePageStyle.actions}>
|
||||||
|
@ -299,7 +341,7 @@ class FilePage extends React.PureComponent {
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<UriBar value={uri} navigation={navigation} />
|
{!this.state.fullscreenMode && <UriBar value={uri} navigation={navigation} />}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,10 @@ const filePageStyle = StyleSheet.create({
|
||||||
flex: 1,
|
flex: 1,
|
||||||
marginBottom: 60
|
marginBottom: 60
|
||||||
},
|
},
|
||||||
|
innerPageContainerFsMode: {
|
||||||
|
flex: 1,
|
||||||
|
marginBottom: 0
|
||||||
|
},
|
||||||
mediaContainer: {
|
mediaContainer: {
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
width: screenWidth,
|
width: screenWidth,
|
||||||
|
@ -76,12 +80,17 @@ const filePageStyle = StyleSheet.create({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
zIndex: 101
|
zIndex: 301,
|
||||||
|
elevation: 21
|
||||||
},
|
},
|
||||||
containedPlayer: {
|
containedPlayer: {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: 220,
|
height: 220,
|
||||||
},
|
},
|
||||||
|
containedPlayerLandscape: {
|
||||||
|
width: '100%',
|
||||||
|
height: '100%'
|
||||||
|
},
|
||||||
fullscreenPlayer: {
|
fullscreenPlayer: {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
|
@ -92,7 +101,8 @@ const filePageStyle = StyleSheet.create({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
zIndex: 100,
|
zIndex: 300,
|
||||||
|
elevation: 20,
|
||||||
backgroundColor: Colors.Black
|
backgroundColor: Colors.Black
|
||||||
},
|
},
|
||||||
containedPlayerBackground: {
|
containedPlayerBackground: {
|
||||||
|
|
|
@ -36,4 +36,12 @@ public class ScreenOrientationModule extends ReactContextBaseJavaModule {
|
||||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void lockOrientationPortrait() {
|
||||||
|
Activity activity = getCurrentActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue