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] hide replaceable block when adding block #16931

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
48 changes: 31 additions & 17 deletions packages/block-editor/src/components/block-list/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export class BlockList extends Component {
if ( this.props.isPostTitleSelected ) {
// if post title selected, insert at top of post
return 0;
} else if ( this.props.selectedBlockOrder === -1 ) {
} else if ( this.props.selectedBlockIndex === -1 ) {
// if no block selected, insert at end of post
return this.props.blockCount;
}
// insert after selected block
return this.props.selectedBlockOrder + 1;
return this.props.selectedBlockIndex + 1;
}

blockHolderBorderStyle() {
Expand Down Expand Up @@ -125,19 +125,21 @@ export class BlockList extends Component {
return isUnmodifiedDefaultBlock( block );
}

renderItem( { item: clientId } ) {
renderItem( { item: clientId, index } ) {
const { shouldShowBlockAtIndex, shouldShowInsertionPoint } = this.props;
return (
<ReadableContentView>
{ this.props.shouldShowInsertionPoint( clientId ) && this.renderAddBlockSeparator() }
<BlockListBlock
key={ clientId }
showTitle={ false }
clientId={ clientId }
rootClientId={ this.props.rootClientId }
onCaretVerticalPositionChange={ this.onCaretVerticalPositionChange }
borderStyle={ this.blockHolderBorderStyle() }
focusedBorderColor={ styles.blockHolderFocused.borderColor }
/>
{ shouldShowInsertionPoint( clientId ) && this.renderAddBlockSeparator() }
{ shouldShowBlockAtIndex( index ) && (
<BlockListBlock
key={ clientId }
showTitle={ false }
clientId={ clientId }
rootClientId={ this.props.rootClientId }
onCaretVerticalPositionChange={ this.onCaretVerticalPositionChange }
borderStyle={ this.blockHolderBorderStyle() }
focusedBorderColor={ styles.blockHolderFocused.borderColor }
/> ) }
</ReadableContentView>
);
}
Expand Down Expand Up @@ -173,32 +175,44 @@ export default compose( [
getBlockOrder,
getSelectedBlock,
getSelectedBlockClientId,
isBlockSelected,
getBlockInsertionPoint,
isBlockInsertionPointVisible,
} = select( 'core/block-editor' );

const selectedBlockClientId = getSelectedBlockClientId();
const blockClientIds = getBlockOrder( rootClientId );
const insertionPoint = getBlockInsertionPoint();
const blockInsertionPointIsVisible = isBlockInsertionPointVisible();
const shouldShowInsertionPoint = ( clientId ) => {
return (
isBlockInsertionPointVisible() &&
blockInsertionPointIsVisible &&
insertionPoint.rootClientId === rootClientId &&
blockClientIds[ insertionPoint.index ] === clientId
);
};

const selectedBlockIndex = getBlockIndex( selectedBlockClientId );
const shouldShowBlockAtIndex = ( index ) => {
const shouldHideBlockAtIndex = (
blockInsertionPointIsVisible &&
// if `index` === `insertionPoint.index`, then block is replaceable
index === insertionPoint.index &&
// only hide selected block
index === selectedBlockIndex
);
return ! shouldHideBlockAtIndex;
};

return {
blockClientIds,
blockCount: getBlockCount( rootClientId ),
getBlockName,
isBlockSelected,
isBlockInsertionPointVisible: isBlockInsertionPointVisible(),
shouldShowBlockAtIndex,
shouldShowInsertionPoint,
selectedBlock: getSelectedBlock(),
selectedBlockClientId,
selectedBlockOrder: getBlockIndex( selectedBlockClientId ),
selectedBlockIndex,
};
} ),
withDispatch( ( dispatch ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
}

.containerStyleAddHere {
flex: 1;
Copy link
Contributor Author

@mchowning mchowning Aug 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the flex here avoided an issue where the "Add Block Here" text in the add block indicator would not display (or would appear and then disappear) when the related block content was not displayed. This fix seems to work very well, but I'm not 100% clear on what was causing the issue, so there may be better ways to address this issue.

flex-direction: row;
background-color: $white;
}
Expand Down