Skip to content

Commit

Permalink
Add prop to force fullscreen preview for videos. (#20436)
Browse files Browse the repository at this point in the history
* Add prop to force fullscreen preview for videos.

By default the force fullscreen is active on Android to allow users
to watch videos using outside players.
On iOS is disable to allow display inline or fullscreen depending of
the user actions.

* Improve full screen state and play state.

* Allow to select the video block by tapping the play button.
  • Loading branch information
SergioEstevao committed Apr 21, 2020
1 parent 39423a5 commit e19b804
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions packages/block-editor/src/components/video-player/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Video extends Component {
super( ...arguments );
this.isIOS = Platform.OS === 'ios';
this.state = {
isFullScreen: false,
videoContainerHeight: 0,
};
this.onPressPlay = this.onPressPlay.bind( this );
Expand Down Expand Up @@ -84,8 +83,12 @@ class Video extends Component {
}

render() {
const { isSelected, style } = this.props;
const { isFullScreen, videoContainerHeight } = this.state;
const {
isSelected,
style,
forceFullscreen = ! this.isIOS,
} = this.props;
const { videoContainerHeight } = this.state;
const showPlayButton = videoContainerHeight > 0;

return (
Expand All @@ -95,21 +98,12 @@ class Video extends Component {
ref={ ( ref ) => {
this.player = ref;
} }
// Using built-in player controls is messing up the layout on iOS.
// So we are setting controls=false and adding a play button that
// will trigger presentFullscreenPlayer()
controls={ false }
pointerEvents={ isSelected ? undefined : 'none' }
controls={ ! forceFullscreen }
ignoreSilentSwitch={ 'ignore' }
paused={ ! isFullScreen }
onLayout={ this.onVideoLayout }
onFullscreenPlayerWillPresent={ () => {
this.setState( { isFullScreen: true } );
} }
onFullscreenPlayerDidDismiss={ () => {
this.setState( { isFullScreen: false } );
} }
/>
{ showPlayButton && (
{ showPlayButton && forceFullscreen && (
// If we add the play icon as a subview to VideoPlayer then react-native-video decides to show control buttons
// even if we set controls={ false }, so we are adding our play button as a sibling overlay view.
<TouchableOpacity
Expand Down

0 comments on commit e19b804

Please sign in to comment.