-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Port the core/code block to be used by the ReactNative mobile GB app #5816
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
850497c
Android specific files for the Code block
hypest 43590b2
Breaking change: Don't override the default JSX translation
hypest bf82dce
Add the platform specific files for iOS as well
hypest 16b7eb5
Set TextInput to multiline for Code block
hypest 20fd557
Hide the default TextInput underline on Android
hypest f922044
Expose registerBlockType, getBlockType to the RN app
hypest 8ee1a4e
Use .native.js for common native code
hypest 3e81e6b
Merge branch 'master' into rnmobile/port-code-block
hypest 9a2c431
Correct configuration for the babel plugins settings
hypest 0f3b9ea
transform-react-jsx for the production env as well
hypest 0aaba3d
No need for pragma override
hypest a3d5ab4
Ignore mobile native files when linting
hypest a29e5bc
Revert "Ignore mobile native files when linting"
hypest e37c8bc
Comment out ununsed imports
hypest a6f8089
Fix codestyle
hypest c190e24
Import is compatible anyway, uncomment it
hypest c96b10b
Remove the React import. The RN project auto-imports it.
hypest 685d178
Limit native code to the edit function alone
hypest f3e8a47
Merge branch 'master' into rnmobile/port-code-block
hypest ad934ad
Expose getBlockContent to RN
hypest 9b5a3f8
RN app tests need createElement exported
hypest a2a1a04
Export serialize from serializer
hypest 95b17a2
Load native version of plain-text's CSS module
hypest 737a498
Make it clear that RN uses styles, not classnames
hypest 1ab7542
Merge branch 'rnmobile/react-native-mobile-integration-first-steps' i…
maxme 49ceaa8
Use the i18n package from @wordpress
maxme 836c51e
Remove some commented out code
hypest ce3c5c4
Utils are not currently used on native
hypest 33f9764
'Border' property not supported in shorthand form
hypest 2bbcbc8
Use hypens in css class names as traditionally
hypest 837f029
remove unused code
hypest 2a98232
No need for platform-specific factory.js
hypest d530570
Merge branch 'master' into rnmobile/port-code-block
hypest eed0531
Move native files after update from master
hypest 779c342
Codestyle fix
hypest 2a97aed
GB isn't using Prettier so, no need for the pragma
hypest 489ae72
Comment on the need to import the `edit` function
hypest 0edfb18
Export the edit function as default
hypest 9b68ba3
Remove reduntant line comment
hypest 5c93331
Import block using the new pattern
hypest 0377c73
Add a comment about styling
hypest dfb1a12
Use object property shorthand for `edit`
gziolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export { | ||
createBlock, | ||
} from './factory'; | ||
export { | ||
default as serialize, | ||
getBlockContent, | ||
} from './serializer'; | ||
export { | ||
registerBlockType, | ||
getBlockType, | ||
} from './registration'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// A "block" is the abstract term used to describe units of markup that, | ||
// when composed together, form the content or layout of a page. | ||
// The API for blocks is exposed via `wp.blocks`. | ||
// | ||
// Supported blocks are registered by calling `registerBlockType`. Once registered, | ||
// the block is made available as an option to the editor interface. | ||
// | ||
// Blocks are inferred from the HTML source of a post through a parsing mechanism | ||
// and then stored as objects in state, from which it is then rendered for editing. | ||
export * from './api'; | ||
|
||
export { default as PlainText } from './plain-text'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { TextInput } from 'react-native'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './style.scss'; | ||
|
||
function PlainText( { onChange, className, ...props } ) { | ||
return ( | ||
<TextInput | ||
className={ [ styles[ 'blocks-plain-text' ], className ] } | ||
onChangeText={ ( text ) => onChange( text ) } | ||
{ ...props } | ||
/> | ||
); | ||
} | ||
|
||
export default PlainText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.blocks-plain-text { | ||
box-shadow: none; | ||
|
||
border-width: 0; | ||
|
||
padding: 0; | ||
margin: 0; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './editor.scss'; | ||
import { PlainText } from '@wordpress/blocks'; | ||
|
||
export default function edit( { attributes, setAttributes, className } ) { | ||
return ( | ||
<div className={ className }> | ||
<PlainText | ||
value={ attributes.content } | ||
onChange={ ( content ) => setAttributes( { content } ) } | ||
placeholder={ __( 'Write code…' ) } | ||
aria-label={ __( 'Code' ) } | ||
/> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { View } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PlainText } from '@wordpress/blocks'; | ||
|
||
// Note: styling is applied directly to the (nested) PlainText component. Web-side components | ||
// apply it to the container 'div' but we don't have a proper proposal for cascading styling yet. | ||
export default function edit( { attributes, setAttributes, style } ) { | ||
return ( | ||
<View> | ||
<PlainText | ||
value={ attributes.content } | ||
style={ style } | ||
multiline={ true } | ||
underlineColorAndroid="transparent" | ||
onChange={ ( content ) => setAttributes( { content } ) } | ||
placeholder={ __( 'Write code…' ) } | ||
aria-label={ __( 'Code' ) } | ||
/> | ||
</View> | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
registerBlockType, | ||
} from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import * as code from './code'; | ||
|
||
export const registerCoreBlocks = () => { | ||
[ | ||
code, | ||
].forEach( ( { name, settings } ) => { | ||
registerBlockType( name, settings ); | ||
} ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
createElement, | ||
Component, | ||
} from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import serialize from './serialize'; | ||
|
||
/** | ||
* Returns a new element of given type. Type can be either a string tag name or | ||
* another function which itself returns an element. | ||
* | ||
* @param {?(string|Function)} type Tag name or element creator | ||
* @param {Object} props Element properties, either attribute | ||
* set to apply to DOM node or values to | ||
* pass through to element creator | ||
* @param {...WPElement} children Descendant elements | ||
* | ||
* @return {WPElement} Element. | ||
*/ | ||
export { createElement }; | ||
|
||
/** | ||
* A base class to create WordPress Components (Refs, state and lifecycle hooks) | ||
*/ | ||
export { Component }; | ||
|
||
/** | ||
* Renders a given element into a string. | ||
* | ||
* @param {WPElement} element Element to render | ||
* | ||
* @return {string} HTML. | ||
*/ | ||
export { serialize as renderToString }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you check if it isn't included in web build by accident?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not extensively, I didn't. What I only tested was modifying values in the style file and see if GB-web picks those up, visually. Tried out adding a
background-color
for example. Any practical way to test it out more thoroughly perhaps?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can test it myself before merging, but I think if you put
background-color: pink
in the RN version, it shouldn't get applied in the web version. That's all we need to ensure :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's grand, that was the test I did and it succeeded (color wasn't picked up) so, feel free to test is your side as well, thanks!