Skip to content

Commit

Permalink
Mobile - BlockList - Pass FlatList internal onLayout through CellRend…
Browse files Browse the repository at this point in the history
…ererComponent
  • Loading branch information
Gerardo committed May 17, 2022
1 parent 27ec8f6 commit 140b3f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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 }
rootClientId={ rootClientId }
/>
);
Expand Down

0 comments on commit 140b3f1

Please sign in to comment.