Introduces RichText component for mobile and ports Para block for mobile#8231
Conversation
… by using the newly introduced RichText component.
| export default class RichText extends Component { | ||
| constructor() { | ||
| super( ...arguments ); | ||
| //console.log('RichText'); |
There was a problem hiding this comment.
We'd remove the commented lines
…tive.js and relevant import statement.
…js`) in raw-handling
|
|
||
| this.currentTimer = setTimeout( function() { | ||
| // Create a React Tree from the new HTML | ||
| const newParaBlock = parse( '<!-- wp:paragraph --><p>' + this.lastContent + '</p><!-- /wp:paragraph -->' )[ 0 ]; |
There was a problem hiding this comment.
We should change this asap, since will only work when RichText is used in a para block.
…ter-july # Conflicts: # core-blocks/paragraph/index.js
…rmation from HTML to React is made in the mobile paragraph block.
…block-use-latest-gb-master-july
|
👋 @SergioEstevao , can you add some documentation on the |
core-blocks/paragraph/edit.native.js
Outdated
| } | ||
| } | ||
|
|
||
| const ParagraphEdit = function ParagraphEdit( { attributes, setAttributes } ) { |
There was a problem hiding this comment.
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.
core-blocks/paragraph/edit.native.js
Outdated
| } | ||
| } | ||
| placeholder={ placeholder || __( 'Add text or type / to add content' ) } | ||
| aria-label={ __( 'test' ) } |
There was a problem hiding this comment.
Do we need this test to have included?
There was a problem hiding this comment.
No, it's not needed at the moment.
core-blocks/paragraph/edit.native.js
Outdated
| <View> | ||
| <RichText | ||
| content={ { contentTree: attributes.content, eventCount: attributes.eventCount } } | ||
| style={ style, [ |
There was a problem hiding this comment.
This style definition is broken. Prop can take only one value so it probably doesn't take minHeight into account.
core-blocks/paragraph/edit.native.js
Outdated
|
|
||
| import { RichText } from '@wordpress/editor'; | ||
|
|
||
| const _minHeight = 50; |
There was a problem hiding this comment.
We don't use underscores to prepend private variables.
| } | ||
| } | ||
|
|
||
| const ParagraphEdit = compose( [ |
There was a problem hiding this comment.
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': |
There was a problem hiding this comment.
You don't need to port this deprecated code. It is going to be removed in the next version.
…obile paragraph block.
…github.com:WordPress/gutenberg into rnmobile/port-para-block-use-latest-gb-master-july
| del: {}, | ||
| ins: {}, | ||
| a: { attributes: [ 'href' ] }, | ||
| a: { attributes: [ 'href', 'target', 'rel' ] }, |
There was a problem hiding this comment.
I noticed that this already get out of sync so I moved it to its own file.
gziolo
left a comment
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
React provides built-in method which does the same forceUpdate: https://reactjs.org/docs/react-component.html#forceupdate.
| } | ||
|
|
||
| shouldComponentUpdate( nextProps ) { | ||
| if ( !! this.forceUpdate ) { |
There was a problem hiding this comment.
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.
…ersion of value to boolean in if. JS does it itself.
…olean variable used to skip the rendering.
|
Thanks @gziolo for the detailed review, and suggestions! 🙇 |
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:
cc @SergioEstevao