-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathblock-list-compact.native.js
63 lines (55 loc) · 1.48 KB
/
block-list-compact.native.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* External dependencies
*/
import { View } from 'react-native';
/**
* WordPress dependencies
*/
import { store as blockEditorStore } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import styles from './style.scss';
import BlockListBlock from './block';
/**
* NOTE: This is a component currently used by the List block (V2)
* It only passes the needed props for this block, if other blocks will use it
* make sure you pass other props that might be required coming from:
* components/inner-blocks/index.native.js
*/
function BlockListCompact( props ) {
const {
marginHorizontal = styles.defaultBlock.marginLeft,
marginVertical = styles.defaultBlock.marginTop,
rootClientId,
} = props;
const { blockClientIds } = useSelect(
( select ) => {
const { getBlockOrder } = select( blockEditorStore );
const blockOrder = getBlockOrder( rootClientId );
return {
blockClientIds: blockOrder,
};
},
[ rootClientId ]
);
const containerStyle = {
marginVertical: -marginVertical,
marginHorizontal: -marginHorizontal,
};
return (
<View style={ containerStyle } testID="block-list-wrapper">
{ blockClientIds.map( ( currentClientId ) => (
<BlockListBlock
clientId={ currentClientId }
rootClientId={ rootClientId }
key={ currentClientId }
marginHorizontal={ marginHorizontal }
marginVertical={ marginVertical }
/>
) ) }
</View>
);
}
export default BlockListCompact;