Skip to content

Commit

Permalink
[Mobile] - BlockList - Add internal onLayout from CellRendererCompone…
Browse files Browse the repository at this point in the history
…nt to BlockListItemCell (#41105)

* Mobile - BlockList - Pass FlatList internal onLayout through CellRendererComponent

* Mobile - Update onLayout naming for BlockListItemCell
  • Loading branch information
geriux committed May 18, 2022
1 parent 8b14921 commit 01f9476
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useEffect, useCallback } from '@wordpress/element';
*/
import { useBlockListContext } from './block-list-context';

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

useEffect( () => {
Expand All @@ -25,18 +25,25 @@ function BlockListItemCell( { children, clientId, rootClientId } ) {
};
}, [] );

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

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

return <View onLayout={ onLayout }>{ children }</View>;
return <View onLayout={ onCellLayout }>{ children }</View>;
}

export default BlockListItemCell;
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 }
onLayout={ onLayout }
rootClientId={ rootClientId }
/>
);
Expand Down

0 comments on commit 01f9476

Please sign in to comment.