Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Milloy committed Mar 14, 2018
1 parent cdb2e78 commit 08d0fcb
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions VideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,26 @@ export default class VideoPlayer extends Component {
*/
this.events = {
onError: this.props.onError || this._onError.bind( this ),
onBack: this.props.onBack || this._onBack.bind( this ),
onEnd: this.props.onEnd || this._onEnd.bind( this ),
onScreenTouch: this._onScreenTouch.bind( this ),
onEnterFullscreen: this.props.onEnterFullscreen,
onExitFullscreen: this.props.onExitFullscreen,
onLoadStart: this._onLoadStart.bind( this ),
onProgress: this._onProgress.bind( this ),
onLoad: this._onLoad.bind( this ),
onPause: this.props.onPause,
onPlay: this.props.onPlay,
};

/**
* Functions used throughout the application
*/
this.methods = {
// 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 @@ -429,10 +426,10 @@ export default class VideoPlayer extends Component {
state.resizeMode = state.isFullscreen === true ? 'cover' : 'contain';

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

this.setState( state );
Expand All @@ -443,7 +440,15 @@ export default class VideoPlayer extends Component {
*/
_togglePlayPause() {
let state = this.state;
state.paused = ! state.paused;
state.paused = !state.paused;

if (state.paused) {
typeof this.events.onPause === 'function' && this.events.onPause();
}
else {
typeof this.events.onPlay === 'function' && this.events.onPlay();
}

this.setState( state );
}

Expand Down Expand Up @@ -880,7 +885,7 @@ export default class VideoPlayer extends Component {
source={ require( './assets/img/back.png' ) }
style={ styles.controls.back }
/>,
this.methods.onBack,
this.events.onBack,
styles.controls.back
);
}
Expand Down

0 comments on commit 08d0fcb

Please sign in to comment.