Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RNMobile - Cover Block: First iteration #19722

Merged
merged 26 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
51f8935
RNMobile - Cover Block - First iteration
Jan 17, 2020
c4bdb88
Remove allowed blocks
Jan 22, 2020
ac30632
Fix content height
Jan 22, 2020
e507dcd
Merge with master
Jan 23, 2020
970c666
RNMobile - Update Heading and Paragraph blocks to use __experimentalU…
Jan 24, 2020
419abf9
RNMobile - Cover block: import correct icon
Jan 24, 2020
cd3baae
RNMobile - Cover block - Default color text for InnerBlocks
Jan 24, 2020
7cee335
Mock use select
Jan 26, 2020
dcc1875
Merge branch 'master' of github.com:WordPress/gutenberg into rnmobile…
Jan 29, 2020
eb6fc3b
RNMobile - Cover block - Use memo from element, don't set min height …
Jan 29, 2020
96ca747
Merge branch 'master' of github.com:WordPress/gutenberg into rnmobile…
Feb 3, 2020
e06c903
RNMobile - Cover Block - Prettier and get opacity logic improvement
Feb 3, 2020
a4dfbdd
Cover block: Move onCoverSelectMedia to a utils file to be shared wit…
Feb 3, 2020
5305373
RNMobile - Cover block: don't set fontSize by default since it is not…
Feb 3, 2020
e71ee48
RNMobile - ImageWithFocalPoint - Move container logic to component an…
Feb 3, 2020
21eb57c
Merge branch 'master' of github.com:WordPress/gutenberg into rnmobile…
Feb 11, 2020
a61cbb6
RNMobile - Cover block: move attributesFromMedia to shared file, rena…
Feb 11, 2020
d7875e6
RNMobile - Enable Cover block for testing
Feb 11, 2020
63767ef
Merge branch 'master' of github.com:WordPress/gutenberg into rnmobile…
Feb 14, 2020
4f7d25a
RNMobile - Cover block - Allow changing the image and fix blocks with…
Feb 14, 2020
225e2bb
RNMobile - Cover - Fallback for theme colors
Feb 17, 2020
7a9341c
RNMobile - Cover - Fix paddings for cover blocks with and without inn…
Feb 18, 2020
ad28977
RNMobile - Cover - Overlay styles as a const instead of a function
Feb 24, 2020
b4b9a68
Merge branch 'master' of github.com:WordPress/gutenberg into rnmobile…
Feb 24, 2020
b343b2c
RNMobile - Cover block - Remove duplicated export
Feb 24, 2020
8bebf5e
RNMobile - Paragraph - Test mock import
Feb 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function MediaPlaceholder( props ) {
labels = {},
icon,
onSelect,
__experimentalOnlyMediaLibrary,
isAppender,
disableMediaButtons,
getStylesFromColorScheme,
Expand Down Expand Up @@ -141,6 +142,9 @@ function MediaPlaceholder( props ) {
<MediaUpload
allowedTypes={ allowedTypes }
onSelect={ setMedia }
__experimentalOnlyMediaLibrary={
__experimentalOnlyMediaLibrary
}
multiple={ multiple }
render={ ( { open, getMediaOptions } ) => {
return (
Expand Down
17 changes: 11 additions & 6 deletions packages/block-editor/src/components/media-upload/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const siteLibrarySource = {
label: __( 'WordPress Media Library' ),
types: [ MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO ],
icon: wordpress,
mediaLibrary: true,
};

const internalSources = [
Expand Down Expand Up @@ -94,15 +95,18 @@ export class MediaUpload extends React.Component {
}

getMediaOptionsItems() {
const { allowedTypes = [] } = this.props;
const {
allowedTypes = [],
__experimentalOnlyMediaLibrary,
} = this.props;

return this.getAllSources()
.filter( ( source ) => {
return (
allowedTypes.filter( ( allowedType ) =>
source.types.includes( allowedType )
).length > 0
);
return __experimentalOnlyMediaLibrary
? source.mediaLibrary
: allowedTypes.filter( ( allowedType ) =>
source.types.includes( allowedType )
).length > 0;
} )
.map( ( source ) => {
return {
Expand Down Expand Up @@ -140,6 +144,7 @@ export class MediaUpload extends React.Component {
const types = allowedTypes.filter( ( type ) =>
mediaSource.types.includes( type )
);

requestMediaPicker( mediaSource.id, types, multiple, ( media ) => {
if ( ( multiple && media ) || ( media && media.id ) ) {
onSelect( media );
Expand Down
13 changes: 13 additions & 0 deletions packages/block-library/src/cover/edit-media-icon.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* WordPress dependencies
*/
import { Path, Rect, SVG } from '@wordpress/components';

export const EditMediaIcon = (
<SVG width={ 20 } height={ 20 } viewBox="0 0 20 20">
<Rect x={ 11 } y={ 3 } width={ 7 } height={ 5 } rx={ 1 } />
<Rect x={ 2 } y={ 12 } width={ 7 } height={ 5 } rx={ 1 } />
<Path d="M13,12h1a3,3,0,0,1-3,3v2a5,5,0,0,0,5-5h1L15,9Z" />
<Path d="M4,8H3l2,3L7,8H6A3,3,0,0,1,9,5V3A5,5,0,0,0,4,8Z" />
</SVG>
);
41 changes: 2 additions & 39 deletions packages/block-library/src/cover/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { cover as icon } from '@wordpress/icons';
* Internal dependencies
*/
import {
attributesFromMedia,
IMAGE_BACKGROUND_TYPE,
VIDEO_BACKGROUND_TYPE,
COVER_MIN_HEIGHT,
Expand Down Expand Up @@ -159,44 +160,6 @@ function ResizableCover( {
);
}

function onCoverSelectMedia( setAttributes ) {
return ( media ) => {
if ( ! media || ! media.url ) {
setAttributes( { url: undefined, id: undefined } );
return;
}
let mediaType;
// for media selections originated from a file upload.
if ( media.media_type ) {
if ( media.media_type === IMAGE_BACKGROUND_TYPE ) {
mediaType = IMAGE_BACKGROUND_TYPE;
} else {
// only images and videos are accepted so if the media_type is not an image we can assume it is a video.
// Videos contain the media type of 'file' in the object returned from the rest api.
mediaType = VIDEO_BACKGROUND_TYPE;
}
} else {
// for media selections originated from existing files in the media library.
if (
media.type !== IMAGE_BACKGROUND_TYPE &&
media.type !== VIDEO_BACKGROUND_TYPE
) {
return;
}
mediaType = media.type;
}

setAttributes( {
url: media.url,
id: media.id,
backgroundType: mediaType,
...( mediaType === VIDEO_BACKGROUND_TYPE
? { focalPoint: undefined, hasParallax: undefined }
: {} ),
} );
};
}

/**
* useCoverIsDark is a hook that returns a boolean variable specifying if the cover
* background is dark or not.
Expand Down Expand Up @@ -271,7 +234,7 @@ function CoverEdit( {
gradientValue,
setGradient,
} = __experimentalUseGradient();
const onSelectMedia = onCoverSelectMedia( setAttributes );
const onSelectMedia = attributesFromMedia( setAttributes );

const toggleParallax = () => {
setAttributes( {
Expand Down
Loading