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

Introduces RichText component for mobile and ports Para block for mobile #8231

Merged

Conversation

daniloercoli
Copy link
Contributor

@daniloercoli daniloercoli commented Jul 26, 2018

Description

This PR introduces the RichText component for mobile, and implements the Paragraph Block by using it.

How has this been tested?

No tests implemented.

Types of changes

This PR adds a native version of the Paragraph Block, and a native version of the RichText component.

This new mobile RichText component doesn't use TinyMCE, but it's built over our React Native wrapper of Aztec editor(s). Being developed here https://github.com/wordpress-mobile/react-native-aztec, that's our port to the React world of our native editors, and referenced in this PR.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

cc @SergioEstevao

@daniloercoli daniloercoli added Mobile Web Viewport sizes for mobile and tablet devices Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) labels Jul 26, 2018
@daniloercoli daniloercoli added this to the 3.4 milestone Jul 26, 2018
@daniloercoli daniloercoli requested review from gziolo and hypest July 26, 2018 14:30
@daniloercoli daniloercoli removed the Mobile Web Viewport sizes for mobile and tablet devices label Jul 26, 2018
export default class RichText extends Component {
constructor() {
super( ...arguments );
//console.log('RichText');
Copy link
Contributor

Choose a reason for hiding this comment

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

We'd remove the commented lines


this.currentTimer = setTimeout( function() {
// Create a React Tree from the new HTML
const newParaBlock = parse( '<!-- wp:paragraph --><p>' + this.lastContent + '</p><!-- /wp:paragraph -->' )[ 0 ];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should change this asap, since will only work when RichText is used in a para block.

@pento pento modified the milestones: 3.4, 3.5 Jul 30, 2018
SergioEstevao and others added 3 commits July 30, 2018 14:13
…ter-july

# Conflicts:
#	core-blocks/paragraph/index.js
…rmation from HTML to React is made in the mobile paragraph block.
@hypest
Copy link
Contributor

hypest commented Aug 1, 2018

👋 @SergioEstevao , can you add some documentation on the <p> replacement with <br>? I think a in-code comment will work well and I would suggest updating this PR's description to include it as a highlight. 🙇‍♂️

}
}

const ParagraphEdit = function ParagraphEdit( { attributes, setAttributes } ) {
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this one, you can export ParagraphBlock directly.

Aside: const ParagraphEdit = is obsolete in such code, it assigns the name to the function, but the function has already name specified.

}
}
placeholder={ placeholder || __( 'Add text or type / to add content' ) }
aria-label={ __( 'test' ) }
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this test to have included?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's not needed at the moment.

<View>
<RichText
content={ { contentTree: attributes.content, eventCount: attributes.eventCount } }
style={ style, [
Copy link
Member

Choose a reason for hiding this comment

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

This style definition is broken. Prop can take only one value so it probably doesn't take minHeight into account.


import { RichText } from '@wordpress/editor';

const _minHeight = 50;
Copy link
Member

Choose a reason for hiding this comment

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

We don't use underscores to prepend private variables.

}
}

const ParagraphEdit = compose( [
Copy link
Member

Choose a reason for hiding this comment

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

I noticed some differences withh the master branch. There were some changes applied to this code. I will fix them myself.

content = <RawHTML>{ value }</RawHTML>;
break;

case 'element':
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to port this deprecated code. It is going to be removed in the next version.

@@ -8,7 +8,7 @@ const phrasingContentSchema = {
em: {},
del: {},
ins: {},
a: { attributes: [ 'href' ] },
a: { attributes: [ 'href', 'target', 'rel' ] },
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that this already get out of sync so I moved it to its own file.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

I added a few commits so I would appreciate another round of testing. Speaking myself this code looks good to merge on the web side.

* External dependencies
*/
import RCTAztecView from 'react-native-aztec';
import { children } from '@wordpress/blocks';
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this import should be put under WordPress dependencies section.

this.onChange = this.onChange.bind( this );
this.onContentSizeChange = this.onContentSizeChange.bind( this );

this.lastContentSizeHeight = -1;
Copy link
Member

Choose a reason for hiding this comment

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

For the next PR. I don't think it is reliable to use private variables inside component to keep state. You should be using this.setState method instead which React provides by default: https://reactjs.org/docs/faq-state.html.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I used those private variables, instead keeping them in state, since even if the component gets recreated, and those variables reset to their initial value, the code works ok anyway. Those variables control if render should be executed or not.

return true;
}

setForceUpdate( flag ) {
Copy link
Member

Choose a reason for hiding this comment

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

This is never used in this code, can you explain why you need it?


onContentSizeChange( event ) {
this.lastContentSizeHeight = event.nativeEvent.contentSize.height;
this.forceUpdate = true; // Set this to true and check it in shouldComponentUpdate to force re-render the component
Copy link
Member

Choose a reason for hiding this comment

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

React provides built-in method which does the same forceUpdate: https://reactjs.org/docs/react-component.html#forceupdate.

}

shouldComponentUpdate( nextProps ) {
if ( !! this.forceUpdate ) {
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to convert values to boolean in JS. this.forceUpdate is all you need here and also it works the same in other cases below. JavaScript engine does type coercion itself.

@daniloercoli
Copy link
Contributor Author

Thanks @gziolo for the detailed review, and suggestions! 🙇

@daniloercoli daniloercoli merged commit 1c966a9 into master Aug 1, 2018
@daniloercoli daniloercoli deleted the rnmobile/port-para-block-use-latest-gb-master-july branch August 1, 2018 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants