Skip to content

Commit

Permalink
[RNMobile] Cover block - Support adding video background from media l…
Browse files Browse the repository at this point in the history
…ibrary (#20463)

* support video background that is set on the web
  • Loading branch information
dratwas committed Mar 12, 2020
1 parent e8c7e97 commit 6797931
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { View, TouchableWithoutFeedback } from 'react-native';
import { default as Video } from 'react-native-video';

/**
* WordPress dependencies
Expand All @@ -21,6 +22,7 @@ import {
InnerBlocks,
InspectorControls,
MEDIA_TYPE_IMAGE,
MEDIA_TYPE_VIDEO,
MediaPlaceholder,
MediaUpload,
withColors,
Expand All @@ -46,7 +48,7 @@ import { EditMediaIcon } from './edit-media-icon';
/**
* Constants
*/
const ALLOWED_MEDIA_TYPES = [ MEDIA_TYPE_IMAGE ];
const ALLOWED_MEDIA_TYPES = [ MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO ];
const INNER_BLOCKS_TEMPLATE = [
[
'core/paragraph',
Expand Down Expand Up @@ -116,11 +118,7 @@ const Cover = ( {
overlayColor && overlayColor.color
? overlayColor.color
: styles.overlay.color,
// Set opacity to 1 while video / theme color support is not available
opacity:
url && VIDEO_BACKGROUND_TYPE !== backgroundType
? dimRatio / 100
: 1,
opacity: dimRatio / 100,
},
// While we don't support theme colors we add a default bg color
! overlayColor.color && ! url
Expand Down Expand Up @@ -207,6 +205,16 @@ const Cover = ( {
url={ url }
/>
) ) }
{ VIDEO_BACKGROUND_TYPE === backgroundType && (
<Video
muted
disableFocus
repeat
resizeMode={ 'cover' }
source={ { uri: url } }
style={ styles.background }
/>
) }
</View>
</TouchableWithoutFeedback>
);
Expand Down Expand Up @@ -249,7 +257,7 @@ const Cover = ( {

<MediaUpload
__experimentalOnlyMediaLibrary
allowedTypes={ [ MEDIA_TYPE_IMAGE ] }
allowedTypes={ ALLOWED_MEDIA_TYPES }
onSelect={ onSelectMedia }
render={ ( { open, getMediaOptions } ) => {
return background( open, getMediaOptions );
Expand Down

0 comments on commit 6797931

Please sign in to comment.