Skip to content
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
72 changes: 49 additions & 23 deletions packages/editor/src/components/post-title/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import { withDispatch } from '@wordpress/data';
import { withFocusOutside } from '@wordpress/components';
import { withInstanceId, compose } from '@wordpress/compose';

import { View } from 'react-native';

import styles from './style.scss';

const minHeight = 30;

class PostTitle extends Component {
titleViewRef: Object;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@pinarol gutenberg doesn't support this syntax, we should remove this line if we want to merge back to master.


constructor() {
super( ...arguments );

Expand All @@ -23,10 +29,23 @@ class PostTitle extends Component {
};
}

componentDidMount() {
if ( this.props.ref ) {
this.props.ref( this );
}
}

handleFocusOutside() {
this.onUnselect();
}

focus() {
if ( this.titleViewRef ) {
this.titleViewRef.focus();
this.setState( { isSelected: true } );
}
}

onSelect() {
this.setState( { isSelected: true } );
this.props.clearSelectedBlock();
Expand All @@ -41,34 +60,41 @@ class PostTitle extends Component {
placeholder,
style,
title,
focusedBorderColor,
borderStyle,
} = this.props;

const decodedPlaceholder = decodeEntities( placeholder );
const borderColor = this.state.isSelected ? focusedBorderColor : 'transparent';

return (
<RichText
tagName={ 'p' }
rootTagsToEliminate={ [ 'strong' ] }
onFocus={ this.onSelect }
onBlur={ this.props.onBlur } // always assign onBlur as a props
multiline={ false }
style={ [ style, {
minHeight: Math.max( minHeight, this.state.aztecHeight ),
} ] }
fontSize={ 24 }
fontWeight={ 'bold' }
onChange={ ( value ) => {
this.props.onUpdate( value );
} }
onContentSizeChange={ ( event ) => {
this.setState( { aztecHeight: event.aztecHeight } );
} }
placeholder={ decodedPlaceholder }
value={ title }
onSplit={ this.props.onEnterPress }
setRef={ this.props.setRef }
>
</RichText>
<View style={ [ styles.titleContainer, borderStyle, { borderColor } ] }>
<RichText
tagName={ 'p' }
rootTagsToEliminate={ [ 'strong' ] }
onFocus={ this.onSelect }
onBlur={ this.props.onBlur } // always assign onBlur as a props
multiline={ false }
style={ [ style, {
minHeight: Math.max( minHeight, this.state.aztecHeight ),
} ] }
fontSize={ 24 }
fontWeight={ 'bold' }
onChange={ ( value ) => {
this.props.onUpdate( value );
} }
onContentSizeChange={ ( event ) => {
this.setState( { aztecHeight: event.aztecHeight } );
} }
placeholder={ decodedPlaceholder }
value={ title }
onSplit={ this.props.onEnterPress }
setRef={ ( ref ) => {
this.titleViewRef = ref;
} }
>
</RichText>
</View>
);
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/editor/src/components/post-title/style.native.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

.titleContainer {
padding-left: 16;
padding-right: 16;
margin-top: 24;
}