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

[Mobile] - BlockList - Add internal onLayout from CellRendererComponent to BlockListItemCell #41105

Merged
merged 2 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { useEffect, useCallback } from '@wordpress/element';
*/
import { useBlockListContext } from './block-list-context';

function BlockListItemCell( { children, clientId, rootClientId } ) {
function BlockListItemCell( {
children,
clientId,
rootClientId,
listOnLayout,
} ) {
const { blocksLayouts, updateBlocksLayouts } = useBlockListContext();

useEffect( () => {
Expand All @@ -26,14 +31,21 @@ function BlockListItemCell( { children, clientId, rootClientId } ) {
}, [] );

const onLayout = useCallback(
( { nativeEvent: { layout } } ) => {
( event ) => {
const {
nativeEvent: { layout },
} = event;
updateBlocksLayouts( blocksLayouts, {
clientId,
rootClientId,
...layout,
} );

if ( listOnLayout ) {
listOnLayout( event );
}
},
[ clientId, rootClientId, updateBlocksLayouts ]
[ clientId, rootClientId, updateBlocksLayouts, listOnLayout ]
);

return <View onLayout={ onLayout }>{ children }</View>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,13 @@ export class BlockList extends Component {
return this.extraData;
}

getCellRendererComponent( { children, item } ) {
getCellRendererComponent( { children, item, onLayout } ) {
const { rootClientId } = this.props;
return (
<BlockListItemCell
children={ children }
clientId={ item }
listOnLayout={ onLayout }
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if this name could be different than the current one, maybe something like internalListOnLayout?

Copy link
Contributor

@fluiddot fluiddot May 17, 2022

Choose a reason for hiding this comment

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

I'm thinking that we could simply name it onLayout as we do for other components, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, I'll update it 👍 Thanks!

rootClientId={ rootClientId }
/>
);
Expand Down