Skip to content

Commit 981471e

Browse files
author
Gerardo Pacheco
committed
[Mobile] - BlockList - Add internal onLayout from CellRendererComponent to BlockListItemCell (#41105)
* Mobile - BlockList - Pass FlatList internal onLayout through CellRendererComponent * Mobile - Update onLayout naming for BlockListItemCell
1 parent 7f79f52 commit 981471e

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/block-editor/src/components/block-list/block-list-item-cell.native.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useEffect, useCallback } from '@wordpress/element';
1313
*/
1414
import { useBlockListContext } from './block-list-context';
1515

16-
function BlockListItemCell( { children, clientId, rootClientId } ) {
16+
function BlockListItemCell( { children, clientId, rootClientId, onLayout } ) {
1717
const { blocksLayouts, updateBlocksLayouts } = useBlockListContext();
1818

1919
useEffect( () => {
@@ -25,18 +25,25 @@ function BlockListItemCell( { children, clientId, rootClientId } ) {
2525
};
2626
}, [] );
2727

28-
const onLayout = useCallback(
29-
( { nativeEvent: { layout } } ) => {
28+
const onCellLayout = useCallback(
29+
( event ) => {
30+
const {
31+
nativeEvent: { layout },
32+
} = event;
3033
updateBlocksLayouts( blocksLayouts, {
3134
clientId,
3235
rootClientId,
3336
...layout,
3437
} );
38+
39+
if ( onLayout ) {
40+
onLayout( event );
41+
}
3542
},
36-
[ clientId, rootClientId, updateBlocksLayouts ]
43+
[ clientId, rootClientId, updateBlocksLayouts, onLayout ]
3744
);
3845

39-
return <View onLayout={ onLayout }>{ children }</View>;
46+
return <View onLayout={ onCellLayout }>{ children }</View>;
4047
}
4148

4249
export default BlockListItemCell;

packages/block-editor/src/components/block-list/index.native.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,13 @@ export class BlockList extends Component {
162162
return this.extraData;
163163
}
164164

165-
getCellRendererComponent( { children, item } ) {
165+
getCellRendererComponent( { children, item, onLayout } ) {
166166
const { rootClientId } = this.props;
167167
return (
168168
<BlockListItemCell
169169
children={ children }
170170
clientId={ item }
171+
onLayout={ onLayout }
171172
rootClientId={ rootClientId }
172173
/>
173174
);

0 commit comments

Comments
 (0)