Skip to content

Commit

Permalink
[RNMobile] Insure tapping at end of post inserts at end
Browse files Browse the repository at this point in the history
Previously, tapping at the end of the post would insert a block
immediately after the currently selected block. In addition, this commit
is cleaning out a few unusued props in the block-list file.
  • Loading branch information
mchowning authored and gziolo committed Aug 29, 2019
1 parent 7512fc4 commit 34e9963
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions packages/block-editor/src/components/block-list/index.native.js
Expand Up @@ -33,31 +33,12 @@ export class BlockList extends Component {
this.renderDefaultBlockAppender = this.renderDefaultBlockAppender.bind( this );
this.onCaretVerticalPositionChange = this.onCaretVerticalPositionChange.bind( this );
this.scrollViewInnerRef = this.scrollViewInnerRef.bind( this );
this.getNewBlockInsertionIndex = this.getNewBlockInsertionIndex.bind( this );
this.addBlockToEndOfPost = this.addBlockToEndOfPost.bind( this );
this.shouldFlatListPreventAutomaticScroll = this.shouldFlatListPreventAutomaticScroll.bind( this );
}

finishBlockAppendingOrReplacing( newBlock ) {
// now determine whether we need to replace the currently selected block (if it's empty)
// or just add a new block as usual
if ( this.isReplaceable( this.props.selectedBlock ) ) {
// do replace here
this.props.replaceBlock( this.props.selectedBlockClientId, newBlock );
} else {
this.props.insertBlock( newBlock, this.getNewBlockInsertionIndex() );
}
}

getNewBlockInsertionIndex() {
if ( this.props.isPostTitleSelected ) {
// if post title selected, insert at top of post
return 0;
} 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.selectedBlockIndex + 1;
addBlockToEndOfPost( newBlock ) {
this.props.insertBlock( newBlock, this.props.blockCount );
}

blockHolderBorderStyle() {
Expand Down Expand Up @@ -158,7 +139,7 @@ export class BlockList extends Component {
const paragraphBlock = createBlock( 'core/paragraph' );
return (
<TouchableWithoutFeedback onPress={ () => {
this.finishBlockAppendingOrReplacing( paragraphBlock );
this.addBlockToEndOfPost( paragraphBlock );
} } >
<View style={ styles.blockListFooter } />
</TouchableWithoutFeedback>
Expand All @@ -170,10 +151,8 @@ export default compose( [
withSelect( ( select, { rootClientId } ) => {
const {
getBlockCount,
getBlockName,
getBlockIndex,
getBlockOrder,
getSelectedBlock,
getSelectedBlockClientId,
getBlockInsertionPoint,
isBlockInsertionPointVisible,
Expand Down Expand Up @@ -206,13 +185,10 @@ export default compose( [
return {
blockClientIds,
blockCount: getBlockCount( rootClientId ),
getBlockName,
isBlockInsertionPointVisible: isBlockInsertionPointVisible(),
shouldShowBlockAtIndex,
shouldShowInsertionPoint,
selectedBlock: getSelectedBlock(),
selectedBlockClientId,
selectedBlockIndex,
};
} ),
withDispatch( ( dispatch ) => {
Expand Down

0 comments on commit 34e9963

Please sign in to comment.