Skip to content

Commit

Permalink
[RNMobile] Implement getMedia on Image block. (#17979)
Browse files Browse the repository at this point in the history
* Implement getMedia on Image block to get media object

* Revert making public default headers. Not needed anymore
  • Loading branch information
etoledom authored Nov 20, 2019
1 parent c21dbfe commit c7d00c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
10 changes: 0 additions & 10 deletions packages/api-fetch/src/index.native.js

This file was deleted.

27 changes: 24 additions & 3 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
requestImageUploadCancelDialog,
requestImageFullscreenPreview,
} from 'react-native-gutenberg-bridge';
import { isEmpty, map } from 'lodash';
import { isEmpty, map, get } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -39,7 +39,8 @@ import {
import { __, sprintf } from '@wordpress/i18n';
import { isURL } from '@wordpress/url';
import { doAction, hasAction } from '@wordpress/hooks';
import { withPreferredColorScheme } from '@wordpress/compose';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -209,7 +210,17 @@ export class ImageEdit extends React.Component {
}

onSetSizeSlug( sizeSlug ) {
const { image } = this.props;

const url = get( image, [ 'media_details', 'sizes', sizeSlug, 'source_url' ] );
if ( ! url ) {
return null;
}

this.props.setAttributes( {
url,
width: undefined,
height: undefined,
sizeSlug,
} );
}
Expand Down Expand Up @@ -430,4 +441,14 @@ export class ImageEdit extends React.Component {
}
}

export default withPreferredColorScheme( ImageEdit );
export default compose( [
withSelect( ( select, props ) => {
const { getMedia } = select( 'core' );
const { attributes: { id }, isSelected } = props;

return {
image: id && isSelected ? getMedia( id ) : null,
};
} ),
withPreferredColorScheme,
] )( ImageEdit );

0 comments on commit c7d00c6

Please sign in to comment.