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

Tiled Gallery: Add noResize to block save #29496

Merged
merged 1 commit into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
69 changes: 41 additions & 28 deletions client/gutenberg/extensions/tiled-gallery/gallery-grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,36 @@ class TiledGalleryGrid extends Component {

pendingRaf = null;

handleResize = entries => {
if ( this.pendingRaf ) {
cancelAnimationFrame( this.pendingRaf );
}
this.pendingRaf = requestAnimationFrame( () => {
this.pendingRaf = null;
for ( const entry of entries ) {
const { width } = entry.contentRect;
if ( width && width !== this.state.width ) {
this.setWidth( width );
handleResize = this.props.noResize
? () => {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take that this ternary is just an optimization because we already have if ( ! this.props.noResize ) in componentDidMount ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, it's redundant as you note. I expect we may start to call resize on mount to get initial sizes set up. This is also complete, noResize really will not resize.

: entries => {
if ( this.pendingRaf ) {
cancelAnimationFrame( this.pendingRaf );
}
}
} );
};
this.pendingRaf = requestAnimationFrame( () => {
this.pendingRaf = null;
for ( const entry of entries ) {
const { width } = entry.contentRect;
if ( width && width !== this.state.width ) {
this.setWidth( width );
}
}
} );
};

setWidth( width ) {
this.setState( { width } );
}

componentDidMount() {
this.deferredMount = defer( () => {
// ResizeObserver has checks for `window` & `document`:
// it does nothing if those are not available.
this.observer = new ResizeObserver( this.handleResize );
this.observer.observe( this.wrapper.current.parentNode );
} );
if ( ! this.props.noResize ) {
this.deferredMount = defer( () => {
// ResizeObserver has checks for `window` & `document`:
// it does nothing if those are not available.
this.observer = new ResizeObserver( this.handleResize );
this.observer.observe( this.wrapper.current.parentNode );
} );
}
}

componentWillUnmount() {
Expand All @@ -68,6 +72,7 @@ class TiledGalleryGrid extends Component {
imageCrop,
images,
layout,
noResize,
renderGalleryImage,
} = this.props;
const { width } = this.state;
Expand All @@ -88,28 +93,36 @@ class TiledGalleryGrid extends Component {
} ) }
data-columns={ columns }
ref={ this.wrapper }
style={ { width } }
style={ noResize ? undefined : { width } }
>
<Fragment>
{ rows.map( ( row, rowIndex ) => {
return (
<div
key={ `tiled-gallery-row-${ rowIndex }` }
className="tiled-gallery__row"
style={ {
width: row.width,
height: row.height,
} }
style={
noResize
? undefined
: {
width: row.width,
height: row.height,
}
}
>
{ row.tiles.map( tile => {
const galleryItem = (
<div
className="tiled-gallery__item"
key={ images[ imageIndex ].id || images[ imageIndex ].url }
style={ {
width: tile.width,
height: tile.height,
} }
style={
noResize
? undefined
: {
width: tile.width,
height: tile.height,
}
}
>
{ renderGalleryImage( imageIndex ) }
</div>
Expand Down
1 change: 1 addition & 0 deletions client/gutenberg/extensions/tiled-gallery/save.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default ( { attributes } ) => {
images={ images }
layout={ layout }
renderGalleryImage={ renderGalleryImage }
noResize
/>
);
};