Skip to content

Commit

Permalink
[RNMobile] Fix footer appender in buttons block (#22711)
Browse files Browse the repository at this point in the history
* add renderFooterAppender to the extraData to re-render list

* small refactor
  • Loading branch information
dratwas committed May 29, 2020
1 parent 984f3b3 commit f2eea8e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
23 changes: 20 additions & 3 deletions packages/block-editor/src/components/block-list/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ const getStyles = (
export class BlockList extends Component {
constructor() {
super( ...arguments );

this.extraData = {
parentWidth: this.props.parentWidth,
renderFooterAppender: this.props.renderFooterAppender,
};
this.renderItem = this.renderItem.bind( this );
this.renderBlockListFooter = this.renderBlockListFooter.bind( this );
this.onCaretVerticalPositionChange = this.onCaretVerticalPositionChange.bind(
Expand All @@ -65,6 +68,7 @@ export class BlockList extends Component {
this
);
this.renderEmptyList = this.renderEmptyList.bind( this );
this.getExtraData = this.getExtraData.bind( this );
}

addBlockToEndOfPost( newBlock ) {
Expand Down Expand Up @@ -102,6 +106,20 @@ export class BlockList extends Component {
);
}

getExtraData() {
const { parentWidth, renderFooterAppender } = this.props;
if (
this.extraData.parentWidth !== parentWidth ||
this.extraData.renderFooterAppender !== renderFooterAppender
) {
this.extraData = {
parentWidth,
renderFooterAppender,
};
}
return this.extraData;
}

render() {
const { isRootList } = this.props;
// Use of Context to propagate the main scroll ref to its children e.g InnerBlocks
Expand Down Expand Up @@ -134,7 +152,6 @@ export class BlockList extends Component {
isFloatingToolbarVisible,
isStackedHorizontally,
horizontalAlignment,
parentWidth,
} = this.props;
const { parentScrollRef } = extraProps;

Expand Down Expand Up @@ -180,7 +197,7 @@ export class BlockList extends Component {
! isRootList && styles.overflowVisible,
] }
horizontal={ horizontal }
extraData={ parentWidth }
extraData={ this.getExtraData() }
scrollEnabled={ isRootList }
contentContainerStyle={
horizontal && styles.horizontalContentContainer
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/button/editor.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@
font-size: 16px;
display: none;
}

.linkSettingsPanel {
padding-left: 0;
padding-right: 0;
}
22 changes: 10 additions & 12 deletions packages/block-library/src/buttons/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { withSelect, withDispatch } from '@wordpress/data';
import { compose, useResizeObserver } from '@wordpress/compose';
import { createBlock } from '@wordpress/blocks';
import { useState, useEffect } from '@wordpress/element';
import { useState, useEffect, useRef } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -45,16 +45,14 @@ function ButtonsEdit( {
}
}, [ sizes ] );

function renderFooterAppender() {
return (
<View style={ styles.appenderContainer }>
<InnerBlocks.ButtonBlockAppender
isFloating={ true }
onAddBlock={ onAddNextButton }
/>
</View>
);
}
const renderFooterAppender = useRef( () => (
<View style={ styles.appenderContainer }>
<InnerBlocks.ButtonBlockAppender
isFloating={ true }
onAddBlock={ onAddNextButton }
/>
</View>
) );

// Inside buttons block alignment options are not supported.
const alignmentHooksSetting = {
Expand All @@ -68,7 +66,7 @@ function ButtonsEdit( {
allowedBlocks={ ALLOWED_BLOCKS }
template={ BUTTONS_TEMPLATE }
renderFooterAppender={
shouldRenderFooterAppender && renderFooterAppender
shouldRenderFooterAppender && renderFooterAppender.current
}
__experimentalMoverDirection="horizontal"
horizontalAlignment={ align }
Expand Down

0 comments on commit f2eea8e

Please sign in to comment.