Skip to content

Commit

Permalink
RNMobile - Hide video component while video is loading (#21508)
Browse files Browse the repository at this point in the history
  • Loading branch information
dratwas committed Apr 15, 2020
1 parent b1edf9b commit f73151e
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from '@wordpress/block-editor';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { useEffect, useState } from '@wordpress/element';
import { cover as icon, replace } from '@wordpress/icons';

/**
Expand Down Expand Up @@ -119,6 +119,21 @@ const Cover = ( {
setAttributes( { dimRatio: value } );
};

const [ isVideoLoading, setIsVideoLoading ] = useState( true );

const onVideoLoadStart = () => {
setIsVideoLoading( true );
};

const onVideoLoad = () => {
setIsVideoLoading( false );
};

const backgroundColor = getStylesFromColorScheme(
styles.backgroundSolid,
styles.backgroundSolidDark
);

const overlayStyles = [
styles.overlay,
url && { opacity: dimRatio / 100 },
Expand All @@ -129,12 +144,7 @@ const Cover = ( {
styles.overlay.color,
},
// While we don't support theme colors we add a default bg color
! overlayColor.color && ! url
? getStylesFromColorScheme(
styles.backgroundSolid,
styles.backgroundSolidDark
)
: {},
! overlayColor.color && ! url ? backgroundColor : {},
];

const placeholderIconStyle = getStylesFromColorScheme(
Expand Down Expand Up @@ -194,7 +204,7 @@ const Cover = ( {
onLongPress={ openMediaOptions }
disabled={ ! isParentSelected }
>
<View style={ styles.background }>
<View style={ [ styles.background, backgroundColor ] }>
{ getMediaOptions() }
{ isParentSelected && toolbarControls( openMediaOptions ) }
<MediaUploadProgress
Expand Down Expand Up @@ -224,7 +234,13 @@ const Cover = ( {
repeat
resizeMode={ 'cover' }
source={ { uri: url } }
style={ styles.background }
onLoad={ onVideoLoad }
onLoadStart={ onVideoLoadStart }
style={ [
styles.background,
// Hide Video component since it has black background while loading the source
{ opacity: isVideoLoading ? 0 : 1 },
] }
/>
) }
</>
Expand Down

0 comments on commit f73151e

Please sign in to comment.