-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile][tech-debt] block-list optimisation (#22144)
* optimisation of renders * fix for wrapper props * rename file and add one small fix * back to identity from loadsh * refactor memo * fix withSelect in blockListItem * more tweaks - fix deleting and inner blocks * fix scroll to the caret position iOS * fix header component * refactor and fix issue with header * Fix visual editor * revert insertBlockAfter
- Loading branch information
Showing
6 changed files
with
323 additions
and
188 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
packages/block-editor/src/components/block-list/block-list-item.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,102 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { View } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
import { withSelect } from '@wordpress/data'; | ||
import { compose } from '@wordpress/compose'; | ||
import { ReadableContentView } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import BlockListBlock from './block'; | ||
import BlockInsertionPoint from './insertion-point'; | ||
|
||
const stretchStyle = { | ||
flex: 1, | ||
}; | ||
|
||
export class BlockListItem extends Component { | ||
render() { | ||
const { | ||
clientId, | ||
isReadOnly, | ||
shouldShowInsertionPointBefore, | ||
shouldShowInsertionPointAfter, | ||
contentResizeMode, | ||
shouldShowInnerBlockAppender, | ||
...restProps | ||
} = this.props; | ||
const readableContentViewStyle = | ||
contentResizeMode === 'stretch' && stretchStyle; | ||
return ( | ||
<ReadableContentView style={ readableContentViewStyle }> | ||
<View | ||
style={ readableContentViewStyle } | ||
pointerEvents={ isReadOnly ? 'box-only' : 'auto' } | ||
> | ||
{ shouldShowInsertionPointBefore && ( | ||
<BlockInsertionPoint /> | ||
) } | ||
<BlockListBlock | ||
key={ clientId } | ||
showTitle={ false } | ||
clientId={ clientId } | ||
{ ...restProps } | ||
/> | ||
{ ! shouldShowInnerBlockAppender() && | ||
shouldShowInsertionPointAfter && ( | ||
<BlockInsertionPoint /> | ||
) } | ||
</View> | ||
</ReadableContentView> | ||
); | ||
} | ||
} | ||
|
||
export default compose( [ | ||
withSelect( | ||
( select, { rootClientId, isStackedHorizontally, clientId } ) => { | ||
const { | ||
getBlockOrder, | ||
getBlockInsertionPoint, | ||
isBlockInsertionPointVisible, | ||
getSettings, | ||
} = select( 'core/block-editor' ); | ||
|
||
const blockClientIds = getBlockOrder( rootClientId ); | ||
const insertionPoint = getBlockInsertionPoint(); | ||
const blockInsertionPointIsVisible = isBlockInsertionPointVisible(); | ||
const shouldShowInsertionPointBefore = | ||
! isStackedHorizontally && | ||
blockInsertionPointIsVisible && | ||
insertionPoint.rootClientId === rootClientId && | ||
// if list is empty, show the insertion point (via the default appender) | ||
( blockClientIds.length === 0 || | ||
// or if the insertion point is right before the denoted block | ||
blockClientIds[ insertionPoint.index ] === clientId ); | ||
|
||
const shouldShowInsertionPointAfter = | ||
! isStackedHorizontally && | ||
blockInsertionPointIsVisible && | ||
insertionPoint.rootClientId === rootClientId && | ||
// if the insertion point is at the end of the list | ||
blockClientIds.length === insertionPoint.index && | ||
// and the denoted block is the last one on the list, show the indicator at the end of the block | ||
blockClientIds[ insertionPoint.index - 1 ] === clientId; | ||
|
||
const isReadOnly = getSettings().readOnly; | ||
|
||
return { | ||
shouldShowInsertionPointBefore, | ||
shouldShowInsertionPointAfter, | ||
isReadOnly, | ||
}; | ||
} | ||
), | ||
] )( BlockListItem ); |
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
Oops, something went wrong.