-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RNMobile] Add Reusable blocks to the inserter menu #28495
Merged
Merged
Changes from 98 commits
Commits
Show all changes
101 commits
Select commit
Hold shift + click to select a range
178648e
Add custom header to BottomSheet
fluiddot bf5f8aa
SegmentedControl mobile component exported
fluiddot 463c257
Add Reusable blocks to inserter menu with tabs
fluiddot 0e164f5
Add native version of inserter-list-item
fluiddot c081f76
Add mobile version of block-types-list component
fluiddot 8efbfbb
Add getWidth to mobile version of inserter-list-item component
fluiddot 1010667
Add blocks-tab mobile version to inserter component
fluiddot 2507e95
Add reusable-blocks-tab mobile version to inserter component
fluiddot 9cc6776
Inserter menu mobile version refactor to use new tabs
fluiddot 4ca23d7
Lint fixes in inserter menu components
fluiddot b9d9cb9
README of block-types-list component updated with mobile changes
fluiddot d29b5c5
modal prefix removed from inserter-list-item style names
fluiddot 11c59bb
blocks-tab renamed to block-types-tab in inserter menu
fluiddot 420dbb6
add block-types-tab UI test
fluiddot 37ea46a
Add reusable-blocks-tab UI test
fluiddot 83bac66
Remove unused import from block types list
fluiddot 3a5e7e5
Change key calculation for block types list component
fluiddot 68ccca7
Fix style format issue in inserter list item
fluiddot cc6efdc
Add header prop to BottomSheet
fluiddot 17ae9a4
Add header height to max height calculation
fluiddot 32e66c2
Move inserter search form to bottom sheet header
fluiddot 71eeab7
Merge branch 'trunk' into rnmobile/add/2575-reusable-blocks-inserter
fluiddot 57a0b71
Merge branch 'rnmobile/add/custom-header-bottom-sheet' into rnmobile/…
fluiddot ad76855
Update BlockTypesList to functional component
fluiddot 005dba9
Add use clipboard block hook
fluiddot 899141f
Use block types list in search results
fluiddot 4d3013f
Remove inserter list item native files
fluiddot a412058
Cleanup inserter native styles
fluiddot a3c3ca8
Update platform specific styles
jhnstn a5a6beb
Fix styles import
jhnstn 6aa2a11
Update android input
jhnstn b28f276
Replace search icone with Gridicon
jhnstn ed09983
Remove touchable highlight component
jhnstn f63dd63
Refactor input form
jhnstn 851079f
Clean up style generation
jhnstn e18274a
Rename input container class
jhnstn 7456ddf
Fix input container active styling
jhnstn 844184e
Update input button styles
jhnstn cccf2b4
Fix input button on Android
jhnstn 1aea172
Fix iOS active search styles
jhnstn c883fd8
Tighten up iOS input buttons
jhnstn 14ad9d6
Align items in icon button
jhnstn 360f5d4
Use elevation for input shadow
jhnstn 1145225
Updates for dark mode
jhnstn fb37e84
Merge branch 'trunk' into rnmobile/add/2575-reusable-blocks-inserter
fluiddot 7f64173
Fix icon fill color
jhnstn 8e817e1
Clean up styles
jhnstn eacd5bc
Fix key calculation in BlockTypesList
fluiddot 8b7b5c3
Add block-editor store definition in ReusableBlocksTab
fluiddot fd97494
Limit the number of lines of block title
fluiddot e7b2676
Add inserter tabs component
fluiddot f2e0c79
Add inserter tabs in inserter menu
fluiddot cadfaa6
Add search focus to inserter menu
fluiddot 8d0f3ae
Unify keyboard listeners in bottom sheet component
fluiddot dcd4fa9
Merge branch 'trunk' into rnmobile/add/2575-reusable-blocks-inserter
fluiddot 4ccd706
Update useClipboardBlock hook
fluiddot 44c0537
Add visual improvements to inserter menu
fluiddot 575c58f
Set maximum items per page of reusable blocks
fluiddot 1ad3268
Add new color scheme hook
jhnstn 873e389
Refactor style generation
jhnstn d1d3f12
Fix style selectors
jhnstn c16c5bc
Fix fill color on icons
jhnstn 4df39cd
Merge branch 'update/inserter-block-search' into rnmobile/add/2575-re…
fluiddot 60e461b
Refactor native inserter tabs
fluiddot 2e02624
Add layout animations in inserter menu
fluiddot 00527a5
Add layout animation fixes in bottom sheet
fluiddot 110a513
Increase max listeners on iOS to prevent warning
fluiddot fa4c0ec
Add root client id to search results
fluiddot 853d45f
Hide tabs when is not main inserter
fluiddot 5d23d10
Force layout calculation on block types list mount
fluiddot 663cc8c
Improve inserter menu layout animations for Android
fluiddot c93082a
Add layout animations to bottom sheet component
fluiddot 2a70a38
Update keyboard layout animation
fluiddot 736fab5
Add keyboard show/hide callbacks to bottom sheet
fluiddot e35bff5
Remove search form height
fluiddot 1d6e507
Merge branch 'rnmobile/add/custom-header-bottom-sheet' into rnmobile/…
fluiddot 9c4dbfe
Prevent multiple layout animations on Android
fluiddot 7eaa61c
Use keyboard events instead focus for display tabs
fluiddot 49ea69c
Enable layout animation of empty search for Android
fluiddot 8a4179c
Update block-types-list README
fluiddot 0b1ad2f
Add last scroll events to inserter tabs
fluiddot 4455515
Fix block types tab unit test
fluiddot e12c54e
Add landscape mode support in inserter tabs
fluiddot f060f9c
Revert "Merge branch 'update/inserter-block-search' into rnmobile/add…
fluiddot 622313d
Revert "Add search focus to inserter menu"
fluiddot 8b4c462
Revert "Increase max listeners on iOS to prevent warning"
fluiddot fcf1ccf
Limit layout animation to header changes in bottom sheet
fluiddot 76be478
Enable reusable tab when inserting in inner blocks
fluiddot 24fc1f4
Merge branch 'trunk' into rnmobile/add/2575-reusable-blocks-inserter
fluiddot e25217d
Remove hasReusableBlocks from inserter menu
fluiddot 958dd9d
Apply BEM naming to block types list styles
fluiddot 08f4549
Rename block types tab to match web version
fluiddot 6153e92
Move tabs container style to a constant
fluiddot 8ebca15
Rename block types tab function to match web version
fluiddot 60e020b
Rename import of block types list in inserter unit tests
fluiddot 89a2e43
Move bottom-sheet keyboard handlers to constants
fluiddot 444386a
Update inserter tabs to use wrapper width for animations
fluiddot c95db83
Merge branch 'trunk' into rnmobile/add/2575-reusable-blocks-inserter
fluiddot 00289fc
Include safe area inset on the block types list
fluiddot 0ca8b43
Merge branch 'trunk' into rnmobile/add/2575-reusable-blocks-inserter
fluiddot d9f3257
Update react-native-editor changelog
fluiddot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
packages/block-editor/src/components/block-types-list/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
FlatList, | ||
View, | ||
TouchableWithoutFeedback, | ||
Dimensions, | ||
} from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState, useEffect } from '@wordpress/element'; | ||
import { BottomSheet, InserterButton } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './style.scss'; | ||
|
||
const MIN_COL_NUM = 3; | ||
|
||
export default function BlockTypesList( { name, items, onSelect, listProps } ) { | ||
const [ numberOfColumns, setNumberOfColumns ] = useState( MIN_COL_NUM ); | ||
const [ itemWidth, setItemWidth ] = useState(); | ||
const [ maxWidth, setMaxWidth ] = useState(); | ||
|
||
useEffect( () => { | ||
Dimensions.addEventListener( 'change', onLayout ); | ||
onLayout(); | ||
return () => { | ||
Dimensions.removeEventListener( 'change', onLayout ); | ||
}; | ||
}, [] ); | ||
|
||
function calculateItemWidth() { | ||
const { | ||
paddingLeft: itemPaddingLeft, | ||
paddingRight: itemPaddingRight, | ||
} = InserterButton.Styles.modalItem; | ||
const { width } = InserterButton.Styles.modalIconWrapper; | ||
return width + itemPaddingLeft + itemPaddingRight; | ||
} | ||
|
||
function onLayout() { | ||
const columnStyle = styles[ 'block-types-list__column' ]; | ||
const sumLeftRightPadding = | ||
columnStyle.paddingLeft + columnStyle.paddingRight; | ||
|
||
const bottomSheetWidth = BottomSheet.getWidth(); | ||
const containerTotalWidth = bottomSheetWidth - sumLeftRightPadding; | ||
const itemTotalWidth = calculateItemWidth(); | ||
|
||
const columnsFitToWidth = Math.floor( | ||
containerTotalWidth / itemTotalWidth | ||
); | ||
|
||
const numColumns = Math.max( MIN_COL_NUM, columnsFitToWidth ); | ||
|
||
setNumberOfColumns( numColumns ); | ||
setMaxWidth( containerTotalWidth / numColumns ); | ||
|
||
if ( columnsFitToWidth < MIN_COL_NUM ) { | ||
const updatedItemWidth = | ||
( bottomSheetWidth - 2 * sumLeftRightPadding ) / MIN_COL_NUM; | ||
setItemWidth( updatedItemWidth ); | ||
} | ||
} | ||
|
||
return ( | ||
<FlatList | ||
onLayout={ onLayout } | ||
key={ `InserterUI-${ name }-${ numberOfColumns }` } //re-render when numberOfColumns changes | ||
keyboardShouldPersistTaps="always" | ||
numColumns={ numberOfColumns } | ||
data={ items } | ||
initialNumToRender={ 3 } | ||
ItemSeparatorComponent={ () => ( | ||
<TouchableWithoutFeedback accessible={ false }> | ||
<View | ||
style={ styles[ 'block-types-list__row-separator' ] } | ||
/> | ||
</TouchableWithoutFeedback> | ||
) } | ||
keyExtractor={ ( item ) => item.id } | ||
renderItem={ ( { item } ) => ( | ||
<InserterButton | ||
{ ...{ | ||
item, | ||
itemWidth, | ||
maxWidth, | ||
onSelect, | ||
} } | ||
/> | ||
) } | ||
{ ...listProps } | ||
/> | ||
); | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/block-editor/src/components/block-types-list/style.native.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.block-types-list__row-separator { | ||
height: 12px; | ||
} | ||
|
||
.block-types-list__column { | ||
padding: $grid-unit-20; | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/block-editor/src/components/inserter/block-types-tab.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockTypesList from '../block-types-list'; | ||
import useClipboardBlock from './hooks/use-clipboard-block'; | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
const NON_BLOCK_CATEGORIES = [ 'reusable' ]; | ||
|
||
function BlockTypesTab( { onSelect, rootClientId, listProps } ) { | ||
const clipboardBlock = useClipboardBlock( rootClientId ); | ||
|
||
const { items } = useSelect( | ||
( select ) => { | ||
const { getInserterItems } = select( blockEditorStore ); | ||
|
||
const allItems = getInserterItems( rootClientId ); | ||
const blockItems = allItems.filter( | ||
( { category } ) => ! NON_BLOCK_CATEGORIES.includes( category ) | ||
); | ||
|
||
return { | ||
items: clipboardBlock | ||
? [ clipboardBlock, ...blockItems ] | ||
: blockItems, | ||
}; | ||
}, | ||
[ rootClientId ] | ||
); | ||
|
||
return ( | ||
<BlockTypesList | ||
name="Blocks" | ||
items={ items } | ||
onSelect={ onSelect } | ||
listProps={ listProps } | ||
/> | ||
); | ||
} | ||
|
||
export default BlockTypesTab; |
39 changes: 39 additions & 0 deletions
39
packages/block-editor/src/components/inserter/hooks/use-clipboard-block.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { rawHandler, store as blocksStore } from '@wordpress/blocks'; | ||
import { getClipboard } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../../store'; | ||
|
||
export default function useClipboardBlock( destinationRootClientId ) { | ||
geriux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { canInsertBlockType } = useSelect( blockEditorStore ); | ||
const { getBlockType } = useSelect( blocksStore ); | ||
|
||
const clipboard = getClipboard(); | ||
const clipboardBlock = rawHandler( { HTML: clipboard } )[ 0 ]; | ||
|
||
const canAddClipboardBlock = canInsertBlockType( | ||
clipboardBlock?.name, | ||
destinationRootClientId | ||
); | ||
|
||
if ( ! canAddClipboardBlock ) { | ||
return undefined; | ||
} | ||
|
||
const { icon, name } = getBlockType( clipboardBlock.name ); | ||
const { attributes: initialAttributes, innerBlocks } = clipboardBlock; | ||
|
||
return { | ||
id: 'clipboard', | ||
name, | ||
icon, | ||
initialAttributes, | ||
innerBlocks, | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for this component has been extracted from
InserterSearchResults
component. This component is now used for rendering the block types in the different tabs of the inserter menu as well as in the search results.