Skip to content

Commit

Permalink
[RNMobile] Only fetch image data if image url is not local file (#20202)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchowning authored Feb 14, 2020
1 parent 7ca8ea1 commit 56ff721
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const getUrlForSlug = ( image, { sizeSlug } ) => {
return get( image, [ 'media_details', 'sizes', sizeSlug, 'source_url' ] );
};

const isFileUrl = ( url ) => url && url.startsWith( 'file:' );

export class ImageEdit extends React.Component {
constructor( props ) {
super( props );
Expand Down Expand Up @@ -123,7 +125,7 @@ export class ImageEdit extends React.Component {
if (
! attributes.id &&
attributes.url &&
attributes.url.indexOf( 'file:' ) === 0
isFileUrl( attributes.url )
) {
requestMediaImport( attributes.url, ( id, url ) => {
if ( url ) {
Expand Down Expand Up @@ -658,13 +660,14 @@ export default compose( [
const { getMedia } = select( 'core' );
const { getSettings } = select( 'core/block-editor' );
const {
attributes: { id },
attributes: { id, url },
isSelected,
} = props;
const { imageSizes } = getSettings();

const shouldGetMedia = id && isSelected && ! isFileUrl( url );
return {
image: id && isSelected ? getMedia( id ) : null,
image: shouldGetMedia ? getMedia( id ) : null,
imageSizes,
};
} ),
Expand Down

0 comments on commit 56ff721

Please sign in to comment.