Skip to content
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] performance improvements #27446

Merged
merged 25 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0c95011
Speed up typing
dratwas Nov 30, 2020
c9eec5c
Add another imrpovements
dratwas Dec 1, 2020
651c539
remove console logs for production builds
dratwas Dec 1, 2020
e91ff4a
add missing import
dratwas Dec 2, 2020
eba991b
fix button select
dratwas Dec 2, 2020
24ebd3d
Add useMemo to BlockVariations
dratwas Dec 2, 2020
35cfc26
add check in the layout component
dratwas Dec 2, 2020
9e3336e
remove cascadeu update in rich-text
dratwas Dec 2, 2020
1502042
add small fix in VirtualizedList.js
dratwas Dec 2, 2020
50bc104
revert patch and back selectionStart and End
dratwas Dec 10, 2020
b0fb005
revert changes in provider
dratwas Dec 10, 2020
c7ab5bb
update columns only if needed
dratwas Dec 10, 2020
d80f6f9
Do not update link attributes if not needed
dratwas Dec 11, 2020
426d638
add fix for sidebar opened prop
dratwas Dec 15, 2020
c227e2a
Merge branch 'master' into rnmobile/performance-improvements
dratwas Dec 16, 2020
5960f66
merge with master
dratwas Jan 25, 2021
e6e4a93
revert gallery changes since the gallery is fixed already
dratwas Jan 26, 2021
fba62ab
Merge branch 'master' of github.com:WordPress/gutenberg into rnmobile…
dratwas Jan 27, 2021
2688bbb
update package-lock.json
dratwas Jan 27, 2021
7b90020
merge with master
dratwas Jan 28, 2021
eca0424
fix columns settings issue
dratwas Jan 29, 2021
67e3590
merge with master and resolve conflicts
dratwas Feb 1, 2021
06926c0
fix lint errors
dratwas Feb 1, 2021
a1b6395
remove babel require context
dratwas Feb 2, 2021
dbe3db0
merge with master
dratwas Feb 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"babel-plugin-inline-json-import": "0.3.2",
"babel-plugin-react-native-classname-to-style": "1.2.2",
"babel-plugin-react-native-platform-specific-extensions": "1.1.1",
"babel-plugin-transform-remove-console": "6.9.4",
"benchmark": "2.1.4",
"browserslist": "4.15.0",
"chalk": "4.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,14 @@ export default compose( [
const { maxWidth } = getSettings();
const isReadOnly = getSettings().readOnly;

const blockCount = getBlockCount( rootBlockId );

const rootBlockId = getBlockHierarchyRootClientId(
selectedBlockClientId
);
const blockCount = getBlockCount( rootBlockId );
const hasRootInnerBlocks = !! blockCount;

const isFloatingToolbarVisible =
!! selectedBlockClientId && hasRootInnerBlocks;

return {
blockClientIds,
blockCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,41 @@ function BlockVariationPicker( { isVisible, onClose, clientId, variations } ) {
onClose();
};

return (
<BottomSheet
isVisible={ isVisible }
onClose={ onClose }
title={ __( 'Select a layout' ) }
contentStyle={ styles.contentStyle }
leftButton={ leftButton }
>
<ScrollView
horizontal
showsHorizontalScrollIndicator={ false }
contentContainerStyle={ styles.contentContainerStyle }
style={ styles.containerStyle }
return useMemo(
() => (
<BottomSheet
isVisible={ isVisible }
onClose={ onClose }
title={ __( 'Select a layout' ) }
contentStyle={ styles.contentStyle }
leftButton={ leftButton }
>
{ variations.map( ( v ) => {
return (
<InserterButton
item={ v }
key={ v.name }
onSelect={ () => onVariationSelect( v ) }
/>
);
} ) }
</ScrollView>
<PanelBody>
<FooterMessageControl
label={ __(
'Note: Column layout may vary between themes and screen sizes'
) }
/>
</PanelBody>
</BottomSheet>
<ScrollView
horizontal
showsHorizontalScrollIndicator={ false }
contentContainerStyle={ styles.contentContainerStyle }
style={ styles.containerStyle }
>
{ variations.map( ( v ) => {
return (
<InserterButton
item={ v }
key={ v.name }
onSelect={ () => onVariationSelect( v ) }
/>
);
} ) }
</ScrollView>
<PanelBody>
<FooterMessageControl
label={ __(
'Note: Column layout may vary between themes and screen sizes'
) }
/>
</PanelBody>
</BottomSheet>
),
[ variations, isVisible, onClose ]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export default compose( [
insertionIndexAfter,
insertionIndexStart,
insertionIndexEnd,
isAnyBlockSelected,
isAnyBlockSelected: !! isAnyBlockSelected,
isSelectedBlockReplaceable: isSelectedUnmodifiedDefaultBlock,
};
} ),
Expand Down
33 changes: 12 additions & 21 deletions packages/block-library/src/button/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ class ButtonEdit extends Component {
}

componentDidUpdate( prevProps, prevState ) {
const { selectedId, editorSidebarOpened, parentWidth } = this.props;
const { isSelected, editorSidebarOpened, parentWidth } = this.props;
const { isLinkSheetVisible, isButtonFocused } = this.state;

if ( prevProps.selectedId !== selectedId ) {
if ( isSelected && ! prevProps.isSelected ) {
this.onToggleButtonFocus( true );
}

Expand All @@ -123,17 +123,11 @@ class ButtonEdit extends Component {
}

if ( this.richTextRef ) {
const selectedRichText = this.richTextRef.props.id === selectedId;

if ( ! selectedRichText && isButtonFocused ) {
if ( ! isSelected && isButtonFocused ) {
this.onToggleButtonFocus( false );
}

if (
selectedRichText &&
selectedId !== prevProps.selectedId &&
! isButtonFocused
) {
if ( isSelected && ! isButtonFocused ) {
AccessibilityInfo.isScreenReaderEnabled().then( ( enabled ) => {
if ( enabled ) {
this.onToggleButtonFocus( true );
Expand Down Expand Up @@ -194,7 +188,9 @@ class ButtonEdit extends Component {
}

onToggleButtonFocus( value ) {
this.setState( { isButtonFocused: value } );
if ( value !== this.state.isButtonFocused ) {
this.setState( { isButtonFocused: value } );
}
}

onClearSettings() {
Expand Down Expand Up @@ -444,23 +440,18 @@ export default compose( [
withInstanceId,
withGradient,
withColors( 'backgroundColor', { textColor: 'color' } ),
withSelect( ( select, { clientId } ) => {
withSelect( ( select, { clientId, isSelected } ) => {
const { isEditorSidebarOpened } = select( 'core/edit-post' );
const {
getSelectedBlockClientId,
getBlockCount,
getBlockRootClientId,
getSettings,
} = select( 'core/block-editor' );
const { getBlockCount, getBlockRootClientId, getSettings } = select(
'core/block-editor'
);
const { maxWidth } = getSettings();

const parentId = getBlockRootClientId( clientId );
const selectedId = getSelectedBlockClientId();
const numOfButtons = getBlockCount( parentId );

return {
selectedId,
editorSidebarOpened: isEditorSidebarOpened(),
editorSidebarOpened: isSelected && isEditorSidebarOpened(),
numOfButtons,
maxWidth,
};
Expand Down
39 changes: 22 additions & 17 deletions packages/block-library/src/buttons/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { BlockControls, InnerBlocks } from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';
import { useResizeObserver } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { useState, useEffect, useRef } from '@wordpress/element';
import { useState, useEffect, useRef, useCallback } from '@wordpress/element';
import {
ToolbarGroup,
ToolbarItem,
Expand All @@ -28,6 +28,8 @@ import ContentJustificationDropdown from './content-justification-dropdown';
const ALLOWED_BLOCKS = [ buttonBlockName ];
const BUTTONS_TEMPLATE = [ [ 'core/button' ] ];

const layoutProp = { type: 'default', alignments: [] };

export default function ButtonsEdit( {
attributes: { contentJustification, align },
clientId,
Expand Down Expand Up @@ -83,20 +85,25 @@ export default function ButtonsEdit( {
}
}, [ sizes, align ] );

const onAddNextButton = debounce( ( selectedId ) => {
const order = getBlockOrder( clientId );
const selectedButtonIndex = order.findIndex(
( i ) => i === selectedId
);
const onAddNextButton = useCallback(
debounce( ( selectedId ) => {
const order = getBlockOrder( clientId );
const selectedButtonIndex = order.findIndex(
( i ) => i === selectedId
);

const index =
selectedButtonIndex === -1 ? order.length + 1 : selectedButtonIndex;
const index =
selectedButtonIndex === -1
? order.length + 1
: selectedButtonIndex;

const insertedBlock = createBlock( 'core/button' );
const insertedBlock = createBlock( 'core/button' );

insertBlock( insertedBlock, index, clientId );
selectBlock( insertedBlock.clientId );
}, 200 );
insertBlock( insertedBlock, index, clientId );
selectBlock( insertedBlock.clientId );
}, 200 ),
[]
);

function onChangeContentJustification( updatedValue ) {
setAttributes( {
Expand All @@ -113,8 +120,8 @@ export default function ButtonsEdit( {
</View>
) );

const remove = useCallback( () => removeBlock( clientId ), [ clientId ] );
const shouldRenderFooterAppender = isSelected || isInnerButtonSelected;

return (
<>
{ isSelected && (
Expand All @@ -141,14 +148,12 @@ export default function ButtonsEdit( {
}
orientation="horizontal"
horizontalAlignment={ contentJustification }
onDeleteBlock={
shouldDelete ? () => removeBlock( clientId ) : undefined
}
onDeleteBlock={ shouldDelete ? remove : undefined }
onAddBlock={ onAddNextButton }
parentWidth={ maxWidth }
marginHorizontal={ spacing }
marginVertical={ spacing }
__experimentalLayout={ { type: 'default', alignments: [] } }
__experimentalLayout={ layoutProp }
templateInsertUpdatesSelection
blockWidth={ blockWidth }
/>
Expand Down
10 changes: 7 additions & 3 deletions packages/block-library/src/columns/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ function ColumnsEditContainer( {
useEffect( () => {
if ( columnCount === 0 ) {
const newColumnCount = columnCount || DEFAULT_COLUMNS_NUM;

updateColumns( columnCount, newColumnCount );
}
}, [] );
Expand Down Expand Up @@ -453,6 +452,7 @@ const ColumnsEdit = ( props ) => {
getBlockAttributes,
} = select( 'core/block-editor' );
const { isEditorSidebarOpened } = select( 'core/edit-post' );

const block = getBlock( clientId );
const innerBlocks = block?.innerBlocks;
const isContentEmpty = map(
Expand All @@ -467,7 +467,7 @@ const ColumnsEdit = ( props ) => {
innerColumns: innerBlocks,
hasParents: !! parents.length,
parentBlockAlignment: getBlockAttributes( parents[ 0 ] )?.align,
editorSidebarOpened: isEditorSidebarOpened(),
editorSidebarOpened: isSelected && isEditorSidebarOpened(),
};
},
[ clientId ]
Expand All @@ -481,6 +481,10 @@ const ColumnsEdit = ( props ) => {
}
}, [] );

const onClose = useCallback( () => {
setIsVisible( false );
}, [] );

return (
<>
<ColumnsEditContainerWrapper
Expand All @@ -493,7 +497,7 @@ const ColumnsEdit = ( props ) => {
/>
<BlockVariationPicker
variations={ variations }
onClose={ () => setIsVisible( false ) }
onClose={ onClose }
clientId={ clientId }
isVisible={ isVisible }
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/file/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,13 @@ export class FileEdit extends Component {

export default compose( [
withSelect( ( select, props ) => {
const { attributes } = props;
const { attributes, isSelected } = props;
const { id, href } = attributes;
const { isEditorSidebarOpened } = select( 'core/edit-post' );
const isNotFileHref = id && getProtocol( href ) !== 'file:';
return {
media: isNotFileHref ? select( 'core' ).getMedia( id ) : undefined,
isSidebarOpened: isEditorSidebarOpened(),
isSidebarOpened: isSelected && isEditorSidebarOpened(),
};
} ),
withDispatch( ( dispatch ) => {
Expand Down
5 changes: 0 additions & 5 deletions packages/block-library/src/media-text/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,23 +396,18 @@ export default compose(
withSelect( ( select, { clientId } ) => {
const {
getSelectedBlockClientId,
getBlockRootClientId,
getBlockParents,
getSettings,
} = select( 'core/block-editor' );

const parents = getBlockParents( clientId, true );

const selectedBlockClientId = getSelectedBlockClientId();
const isParentSelected =
selectedBlockClientId &&
selectedBlockClientId === getBlockRootClientId( clientId );
const isAncestorSelected =
selectedBlockClientId && parents.includes( selectedBlockClientId );

return {
isSelected: selectedBlockClientId === clientId,
isParentSelected,
isAncestorSelected,
isRTL: getSettings().isRTL,
};
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/paragraph/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
BlockControls,
RichText,
} from '@wordpress/block-editor';
import { useCallback } from '@wordpress/element';
import { useSelect } from '@wordpress/data';

const name = 'core/paragraph';
Expand All @@ -31,15 +32,16 @@ function ParagraphBlock( {
...style,
};

const onAlignmentChange = useCallback( ( nextAlign ) => {
setAttributes( { align: nextAlign } );
}, [] );
return (
<>
<BlockControls>
<AlignmentToolbar
value={ align }
isRTL={ isRTL }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
onChange={ onAlignmentChange }
/>
</BlockControls>
<RichText
Expand Down
Loading