Skip to content

Commit

Permalink
Fix last mobile merge into master (#14620)
Browse files Browse the repository at this point in the history
* Add back Heading native changes that were overwritten during last merge of rnmobile/develop into master

* Add back Paragraph native changes that were overwritten during last merge of rnmobile/develop into master

* [Native mobile] Bring release v1.0.1 back to "mobile develop" (#14075)

* Don't allow placeholder to moves once we tap on it (#14066)

* Use platform based SCSS vars for block minHeight (#14070)

# Conflicts:
#	packages/block-library/src/heading/edit.native.js
#	packages/editor/src/components/post-title/style.native.scss

* Remove unecessary imports in scss files
  • Loading branch information
Tug authored Mar 26, 2019
1 parent c36069a commit 2c1fe1a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 49 deletions.
79 changes: 53 additions & 26 deletions packages/block-library/src/heading/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,66 @@ import { Component } from '@wordpress/element';
import { RichText, BlockControls } from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import './editor.scss';
import styles from './editor.scss';

const minHeight = 24;
const name = 'core/heading';

class HeadingEdit extends Component {
constructor( props ) {
super( props );

this.state = {
aztecHeight: 0,
};
this.splitBlock = this.splitBlock.bind( this );
}

/**
* Split handler for RichText value, namely when content is pasted or the
* user presses the Enter key.
*
* @param {?Array} before Optional before value, to be used as content
* in place of what exists currently for the
* block. If undefined, the block is deleted.
* @param {?Array} after Optional after value, to be appended in a new
* paragraph block to the set of blocks passed
* as spread.
* @param {...WPBlock} blocks Optional blocks inserted between the before
* and after value blocks.
*/
splitBlock( before, after, ...blocks ) {
const {
attributes,
insertBlocksAfter,
setAttributes,
onReplace,
} = this.props;

if ( after !== null ) {
// Append "After" content as a new paragraph block to the end of
// any other blocks being inserted after the current paragraph.
const newBlock = createBlock( name, { content: after } );
blocks.push( newBlock );
}

if ( blocks.length && insertBlocksAfter ) {
insertBlocksAfter( blocks );
}

const { content } = attributes;
if ( before === null ) {
onReplace( [] );
} else if ( content !== before ) {
// Only update content if it has in-fact changed. In case that user
// has created a new paragraph at end of an existing one, the value
// of before will be strictly equal to the current content.
setAttributes( { content: before } );
}
}

render() {
const {
attributes,
setAttributes,
mergeBlocks,
insertBlocksAfter,
style,
} = this.props;

const {
Expand All @@ -47,6 +85,7 @@ class HeadingEdit extends Component {
} = attributes;

const tagName = 'h' + level;

return (
<View>
<BlockControls>
Expand All @@ -56,28 +95,16 @@ class HeadingEdit extends Component {
tagName={ tagName }
value={ content }
isSelected={ this.props.isSelected }
style={ {
...style,
minHeight: styles[ 'wp-block-heading' ].minHeight,
} }
onFocus={ this.props.onFocus } // always assign onFocus as a props
onBlur={ this.props.onBlur } // always assign onBlur as a props
onCaretVerticalPositionChange={ this.props.onCaretVerticalPositionChange }
style={ {
minHeight: Math.max( minHeight, this.state.aztecHeight ),
} }
onChange={ ( value ) => setAttributes( { content: value } ) }
onMerge={ mergeBlocks }
onSplit={
insertBlocksAfter ?
( before, after, ...blocks ) => {
setAttributes( { content: before } );
insertBlocksAfter( [
...blocks,
createBlock( 'core/paragraph', { content: after } ),
] );
} :
undefined
}
onContentSizeChange={ ( event ) => {
this.setState( { aztecHeight: event.aztecHeight } );
} }
onSplit={ this.splitBlock }
placeholder={ placeholder || __( 'Write heading…' ) }
/>
</View>
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/heading/style.native.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

.blockText {
min-height: $min-height-heading;
}
11 changes: 3 additions & 8 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,6 @@ class ImageEdit extends React.Component {
imageHeightWithinContainer,
} = sizes;

if ( imageWidthWithinContainer === undefined ) {
return (
<View style={ styles.imageContainer } >
<Dashicon icon={ 'format-image' } size={ 300 } />
</View>
);
}

let finalHeight = imageHeightWithinContainer;
if ( height > 0 && height < imageHeightWithinContainer ) {
finalHeight = height;
Expand All @@ -369,6 +361,9 @@ class ImageEdit extends React.Component {
<View style={ { flex: 1 } } >
{ getInspectorControls() }
{ getMediaOptions() }
{ ! imageWidthWithinContainer && <View style={ styles.imageContainer } >
<Dashicon icon={ 'format-image' } size={ 300 } />
</View> }
<ImageBackground
style={ { width: finalWidth, height: finalHeight, opacity } }
resizeMethod="scale"
Expand Down
15 changes: 1 addition & 14 deletions packages/block-library/src/paragraph/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { RichText } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import styles from './style.scss';

const name = 'core/paragraph';

Expand All @@ -23,10 +22,6 @@ class ParagraphEdit extends Component {
super( props );
this.splitBlock = this.splitBlock.bind( this );
this.onReplace = this.onReplace.bind( this );

this.state = {
aztecHeight: 0,
};
}

/**
Expand Down Expand Up @@ -99,8 +94,6 @@ class ParagraphEdit extends Component {
content,
} = attributes;

const minHeight = styles.blockText.minHeight;

return (
<View>
<RichText
Expand All @@ -110,10 +103,7 @@ class ParagraphEdit extends Component {
onFocus={ this.props.onFocus } // always assign onFocus as a props
onBlur={ this.props.onBlur } // always assign onBlur as a props
onCaretVerticalPositionChange={ this.props.onCaretVerticalPositionChange }
style={ {
...style,
minHeight: Math.max( minHeight, this.state.aztecHeight ),
} }
style={ style }
onChange={ ( nextContent ) => {
setAttributes( {
content: nextContent,
Expand All @@ -122,9 +112,6 @@ class ParagraphEdit extends Component {
onSplit={ this.splitBlock }
onMerge={ mergeBlocks }
onReplace={ this.onReplace }
onContentSizeChange={ ( event ) => {
this.setState( { aztecHeight: event.aztecHeight } );
} }
placeholder={ placeholder || __( 'Start writing…' ) }
/>
</View>
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/paragraph/style.native.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

.blockText {
min-height: 24;
min-height: $min-height-paragraph;
}

0 comments on commit 2c1fe1a

Please sign in to comment.