diff --git a/packages/block-editor/src/components/index.native.js b/packages/block-editor/src/components/index.native.js index df605eb54da3f..5b3249e1f1a8a 100644 --- a/packages/block-editor/src/components/index.native.js +++ b/packages/block-editor/src/components/index.native.js @@ -20,6 +20,7 @@ export { default as BlockInvalidWarning } from './block-list/block-invalid-warni // Content Related Components export { default as DefaultBlockAppender } from './default-block-appender'; +export { default as Inserter } from './inserter'; // State Related Components export { default as BlockEditorProvider } from './provider'; diff --git a/packages/block-editor/src/components/inserter/index.native.js b/packages/block-editor/src/components/inserter/index.native.js new file mode 100644 index 0000000000000..2985d61c7811c --- /dev/null +++ b/packages/block-editor/src/components/inserter/index.native.js @@ -0,0 +1,96 @@ +/** + * External dependencies + */ +import { FlatList, Text, TouchableHighlight, View } from 'react-native'; + +/** + * WordPress dependencies + */ +import { BottomSheet, Icon } from '@wordpress/components'; +import { Component } from '@wordpress/element'; +import { withSelect } from '@wordpress/data'; +import { compose } from '@wordpress/compose'; +import { getUnregisteredTypeHandlerName } from '@wordpress/blocks'; + +/** + * Internal dependencies + */ +import styles from './style.scss'; + +class Inserter extends Component { + calculateNumberOfColumns() { + const bottomSheetWidth = BottomSheet.getWidth(); + const { paddingLeft: itemPaddingLeft, paddingRight: itemPaddingRight } = styles.modalItem; + const { paddingLeft: containerPaddingLeft, paddingRight: containerPaddingRight } = styles.content; + const { width: itemWidth } = styles.modalIconWrapper; + const itemTotalWidth = itemWidth + itemPaddingLeft + itemPaddingRight; + const containerTotalWidth = bottomSheetWidth - ( containerPaddingLeft + containerPaddingRight ); + return Math.floor( containerTotalWidth / itemTotalWidth ); + } + + render() { + const numberOfColumns = this.calculateNumberOfColumns(); + const bottomPadding = this.props.addExtraBottomPadding && styles.contentBottomPadding; + + return ( + + + + } + keyExtractor={ ( item ) => item.name } + renderItem={ ( { item } ) => + this.props.onValueSelected( item.name ) }> + + + + + + + { item.title } + + + } + /> + + ); + } +} + +export default compose( [ + withSelect( ( select, { clientId, isAppender, rootClientId } ) => { + const { + getInserterItems, + getBlockRootClientId, + getBlockSelectionEnd, + } = select( 'core/block-editor' ); + + let destinationRootClientId = rootClientId; + if ( ! destinationRootClientId && ! clientId && ! isAppender ) { + const end = getBlockSelectionEnd(); + if ( end ) { + destinationRootClientId = getBlockRootClientId( end ) || undefined; + } + } + const inserterItems = getInserterItems( destinationRootClientId ); + + return { + items: inserterItems.filter( ( { name } ) => name !== getUnregisteredTypeHandlerName() ), + }; + } ), +] )( Inserter ); diff --git a/packages/block-editor/src/components/inserter/style.native.scss b/packages/block-editor/src/components/inserter/style.native.scss new file mode 100644 index 0000000000000..82d5fa5822650 --- /dev/null +++ b/packages/block-editor/src/components/inserter/style.native.scss @@ -0,0 +1,57 @@ +/** @format */ + +.touchableArea { + border-radius: 8px 8px 8px 8px; +} + +.content { + padding: 0 0 0 0; + align-items: center; + justify-content: space-evenly; +} + +.contentBottomPadding { + padding-bottom: 20px; +} + +.rowSeparator { + height: 12px; +} + +.modalItem { + flex-direction: column; + justify-content: center; + align-items: center; + padding-left: 8; + padding-right: 8; + padding-top: 0; + padding-bottom: 0; +} + +.modalIconWrapper { + width: 104px; + height: 64px; + background-color: $gray-light; //#f3f6f8 + border-radius: 8px 8px 8px 8px; + justify-content: center; + align-items: center; +} + +.modalIcon { + width: 32px; + height: 32px; + justify-content: center; + align-items: center; + fill: $gray-dark; +} + +.modalItemLabel { + background-color: transparent; + padding-left: 2; + padding-right: 2; + padding-top: 4; + padding-bottom: 0; + justify-content: center; + font-size: 12; + color: $gray-dark; +} diff --git a/packages/blocks/src/api/index.native.js b/packages/blocks/src/api/index.native.js index 123be1e132a99..b99fccc531c21 100644 --- a/packages/blocks/src/api/index.native.js +++ b/packages/blocks/src/api/index.native.js @@ -21,8 +21,12 @@ export { getUnregisteredTypeHandlerName, getBlockType, getBlockTypes, + getBlockSupport, hasBlockSupport, isReusableBlock, + getChildBlockNames, + hasChildBlocks, + hasChildBlocksWithInserterSupport, setDefaultBlockName, getDefaultBlockName, } from './registration';