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

[Mobile]Update PostTitle to apply borders when it is focused #13970

Merged
merged 8 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
70 changes: 48 additions & 22 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
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.onRef ) {
this.props.onRef( 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,33 +60,40 @@ 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' }
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' }
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
7 changes: 7 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,7 @@

.titleContainer {
padding-left: 16;
padding-right: 16;
padding-top: 32;
Copy link
Contributor

Choose a reason for hiding this comment

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

This top padding looks a bit too much on the WordPress apps. I'm not sure if this was a requirement from before or it's an adjustment made for the example apps?
@iamthomasbishop might now :)

screenshot_20190221-091118

But not really important on this PR.

Choose a reason for hiding this comment

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

We did add 16pt spacing above the title in a related pr, is that what's at play here? Should we use margin instead of padding? I imagine when the block gets focused (with top/bottom borders) it'll looks odd.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see! Yes, adding the extra 16pts as margin will make the difference. Currently we don't see the top border when the title is selected.

Copy link
Contributor Author

@pinarol pinarol Feb 21, 2019

Choose a reason for hiding this comment

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

I just moved the style from one place to another, didn't change or add any styles(on the parent PR you can see that the titleContainer style was here before: https://github.com/wordpress-mobile/gutenberg-mobile/pull/622/files). This PR isn't changing anything about the paddings on the title.

I've put some gifs here to demonstrate how it looks wordpress-mobile/gutenberg-mobile#622 (comment)

padding-bottom: 16;
}