tapping on the player controls container while it is visible should hide the container

This commit is contained in:
Akinwale Ariwodola 2018-09-04 09:36:48 +01:00
parent 6d6c749338
commit 648a11c978

View file

@ -115,6 +115,11 @@ class MediaPlayer extends React.PureComponent {
this.hidePlayerControls();
}
manualHidePlayerControls = () => {
this.clearControlsTimeout();
this.setState({ areControlsVisible: false });
}
hidePlayerControls() {
const player = this;
let timeout = setTimeout(() => {
@ -123,6 +128,14 @@ class MediaPlayer extends React.PureComponent {
player.setState({ controlsTimeout: timeout });
}
togglePlayerControls = () => {
if (this.state.areControlsVisible) {
this.manualHidePlayerControls();
} else {
this.showPlayerControls();
}
}
togglePlay = () => {
this.showPlayerControls();
this.setState({ paused: !this.state.paused });
@ -342,7 +355,7 @@ class MediaPlayer extends React.PureComponent {
onEnd={this.onEnd}
/>
<TouchableOpacity style={mediaPlayerStyle.playerControls} onPress={this.showPlayerControls}>
<TouchableOpacity style={mediaPlayerStyle.playerControls} onPress={this.togglePlayerControls}>
{this.renderPlayerControls()}
</TouchableOpacity>