Skip to content

Commit

Permalink
Add imageCrop, blockProps to block-list and style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dratwas committed Nov 10, 2020
1 parent 2ec63f1 commit c0f043d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class BlockListBlock extends Component {
parentWidth={ this.props.parentWidth }
contentStyle={ this.props.contentStyle }
onDeleteBlock={ this.props.onDeleteBlock }
{ ...( this.props.blockProps || {} ) }
/>
<View onLayout={ this.getBlockWidth } />
</GlobalStylesContext.Provider>
Expand Down
10 changes: 8 additions & 2 deletions packages/block-editor/src/components/block-list/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,23 @@ export class BlockList extends Component {
onDeleteBlock,
contentStyle,
renderAppender,
blockProps,
} = this.props;
if (
this.extraData.parentWidth !== parentWidth ||
this.extraData.renderFooterAppender !== renderFooterAppender ||
this.extraData.onDeleteBlock !== onDeleteBlock ||
this.extraData.contentStyle !== contentStyle ||
this.extraData.renderAppender !== renderAppender
this.extraData.renderAppender !== renderAppender ||
this.extraData.blockProps !== blockProps
) {
this.extraData = {
parentWidth,
renderFooterAppender,
onDeleteBlock,
contentStyle,
renderAppender,
blockProps,
};
}
return this.extraData;
Expand Down Expand Up @@ -272,9 +275,11 @@ export class BlockList extends Component {
parentWidth,
marginVertical = styles.defaultBlock.marginTop,
marginHorizontal = styles.defaultBlock.marginLeft,
blockProps,
numColumns,
} = this.props;
return (
<View style={ { flex: 1 } }>
<View style={ numColumns && { flex: 1 } }>
<BlockListItem
isStackedHorizontally={ isStackedHorizontally }
rootClientId={ rootClientId }
Expand All @@ -292,6 +297,7 @@ export class BlockList extends Component {
onCaretVerticalPositionChange={
this.onCaretVerticalPositionChange
}
blockProps={ blockProps }
/>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ function UncontrolledInnerBlocks( props ) {
horizontalAlignment,
filterInnerBlocks,
numColumns,
blockProps,
} = props;

const block = useSelect(
( select ) => select( 'core/block-editor' ).getBlock( clientId ),
[ clientId ]
Expand Down Expand Up @@ -123,6 +123,7 @@ function UncontrolledInnerBlocks( props ) {
onDeleteBlock={ onDeleteBlock }
filterInnerBlocks={ filterInnerBlocks }
numColumns={ numColumns }
blockProps={ blockProps }
/>
);

Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ function GalleryEdit( props ) {
mediaPlaceholder={ mediaPlaceholder }
blockProps={ blockProps }
insertBlocksAfter={ insertBlocksAfter }
imageCrop={ imageCrop }
/>
</>
);
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/gallery/gallery.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export const Gallery = ( props ) => {
numColumns: displayedColumns,
marginHorizontal: TILE_SPACING,
marginVertical: TILE_SPACING,
blockProps: {
imageCrop,
isGallery: true,
},
}
);

Expand Down
22 changes: 16 additions & 6 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ export class ImageEdit extends React.Component {
image,
imageSizes,
clientId,
isGallery,
imageCrop,
} = this.props;
const {
align,
Expand Down Expand Up @@ -451,6 +453,13 @@ export class ImageEdit extends React.Component {
wide: 'center',
};

const additionalImageProps = isGallery
? {
height: '100%',
resizeMode: imageCrop ? 'cover' : 'contain',
}
: {};

const getImageComponent = ( openMediaOptions, getMediaOptions ) => (
<>
<TouchableWithoutFeedback
Expand Down Expand Up @@ -485,10 +494,12 @@ export class ImageEdit extends React.Component {
return (
/// TEMPORARY FOR GALLERY!! TODO
<View
style={ {
height: 150,
overflow: 'hidden',
} }
style={
this.props.isGallery && {
height: 150,
overflow: 'hidden',
}
}
>
<Image
align={
Expand All @@ -513,8 +524,7 @@ export class ImageEdit extends React.Component {
url={ url }
shapeStyle={ styles[ className ] }
width={ this.getWidth() }
height={ '100%' }
resizeMode={ 'cover' }
{ ...additionalImageProps }
/>
</View>
);
Expand Down

0 comments on commit c0f043d

Please sign in to comment.