Skip to content

Commit

Permalink
add hooks for entering/exiting fullscreen and playing/pausing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Milloy committed Mar 14, 2018
1 parent 8d93d8a commit cdb2e78
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions VideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,18 @@ export default class VideoPlayer extends Component {
* Functions used throughout the application
*/
this.methods = {
onBack: this.props.onBack || this._onBack.bind( this ),
// Private
toggleFullscreen: this._toggleFullscreen.bind( this ),
togglePlayPause: this._togglePlayPause.bind( this ),
toggleControls: this._toggleControls.bind( this ),
toggleTimer: this._toggleTimer.bind( this ),

// Public
onBack: this.props.onBack || this._onBack.bind( this ),
onEnterFullscreen: this.props.onEnterFullscreen,
onExitFullscreen: this.props.onExitFullscreen,
onPause: this.props.onPause,
onPlay: this.props.onPlay,
};

/**
Expand Down Expand Up @@ -417,9 +424,17 @@ export default class VideoPlayer extends Component {
*/
_toggleFullscreen() {
let state = this.state;

state.isFullscreen = ! state.isFullscreen;
state.resizeMode = state.isFullscreen === true ? 'cover' : 'contain';

if (state.isFullscreen) {
typeof this.props.onEnterFullscreen === 'function' && callback();
}
else {
typeof this.props.onExitFullscreen === 'function' && callback();
}

this.setState( state );
}

Expand Down Expand Up @@ -827,9 +842,9 @@ export default class VideoPlayer extends Component {
*/
renderTopControls() {

const backControl = !this.props.disableBack ? this.renderBack() : this.renderNullControl();
const volumeControl = !this.props.disableVolume ? this.renderVolume() : this.renderNullControl();
const fullscreenControl = !this.props.disableFullscreen ? this.renderFullscreen() : this.renderNullControl();
const backControl = this.props.disableBack ? this.renderNullControl() : this.renderBack();
const volumeControl = this.props.disableVolume ? this.renderNullControl() : this.renderVolume();
const fullscreenControl = this.props.disableFullscreen ? this.renderNullControl() : this.renderFullscreen();

return(
<Animated.View style={[
Expand Down Expand Up @@ -916,9 +931,9 @@ export default class VideoPlayer extends Component {
*/
renderBottomControls() {

const playPauseControl = !this.props.disablePlayPause ? this.renderPlayPause() : this.renderNullControl();
const timerControl = !this.props.disableTimer ? this.renderTimer() : this.renderNullControl();
const seekbarControl = !this.props.disableSeekbar ? this.renderSeekbar() : this.renderNullControl();
const timerControl = this.props.disableTimer ? this.renderNullControl() : this.renderTimer();
const seekbarControl = this.props.disableSeekbar ? this.renderNullControl() : this.renderSeekbar();
const playPauseControl = this.props.disablePlayPause ? this.renderNullControl() : this.renderPlayPause();

return(
<Animated.View style={[
Expand Down

0 comments on commit cdb2e78

Please sign in to comment.