Skip to content
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
Next Next commit
Mobile - BlockList - Pass FlatList internal onLayout through CellRend…
…ererComponent
  • Loading branch information
Gerardo committed May 17, 2022
commit 140b3f162ac0904cdf21d7bd9c1a398fad0ddc27
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