-
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
Conversation
* CSS related imports are suppressed * classnames are left in only to minimize diff among the files but do not play a role, nor style the elements
So far, that's the only way I found to have the android-specific jest tests succeed.
May also tie into #2751 (registration of said high-level definition on the server). |
In general, we are looking into having a way to define all blocks on the server (minus JS specific bits like |
Will define a `wp` global via RN and reuse the `createElement()` from `@gutenberg/component`.
Update:
|
After some discussion with @gziolo I've :
|
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 left some minor comments. In general, I'm okey with the proposed solution, because everything happens in RN specific files. I think it would be a good idea to move all edit
components to their own files anyway. We can help with that if others agree that it is a way to move forward.
@mtias, @aduth, @youknowriad any thoughts?
core-blocks/code/edit.native.js
Outdated
*/ | ||
import { PlainText } from '../../blocks'; | ||
|
||
export function edit( { attributes, setAttributes, style } ) { |
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.
It can be exported as export default function ...
.
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.
Makes sense, done with 0edfb18.
core-blocks/code/index.js
Outdated
} from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './editor.scss'; | ||
import { edit } from './edit'; // import the specialized `edit` function. Is is different between the web and native mobile. |
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.
This comment can be removed as we should probably do the same for all edit
implementations :)
edit
can be exported as default to have:
import edit from './edit';
// and later
{
...
edit,
...
}
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.
The comment can be considered trivial if one reads the PR and has an understanding of the .native.js
pattern. I had added it to help people pick up the pattern but, i'm perfectly fine with removing it 👍 . Done with 9b68ba3.
core-blocks/code/edit.native.js
Outdated
|
||
export function edit( { attributes, setAttributes, style } ) { | ||
return ( | ||
<View> |
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.
Shouldn't be style
applied to View
rather than PlainText
to mirror web implementation?
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.
Yes and no. Unfortunately, styling in RN is not cascading by default and we will need more work on establishing a pattern on how to pass and style the blocks/components/containers.
In this particular case for example, the style includes the fontFamily
property which is supported by the PlaintText
component (because it's a TextInput
under the hood) but not by the View
component.
All in all, styling should be considered alpha
at this stage as well and i'd suggest we work on it in a different PR, if that's OK with you too @gziolo . I'll update the PR description to include some relative info.
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 would be awesome to have it documented in the code next to RN version of the edit
component.
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.
Done with 0377c73.
@@ -0,0 +1,9 @@ | |||
.blocks-plain-text { |
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!
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 tested web version and it still works properly. I would defer the final decision to @aduth and @youknowriad, but speaking myself it's good to go.
Let's get it and iterate with further PRs. |
Good to see this happening :) |
Description
This PR introduces the minimal set of changes to make the core/code block ready to be consumed by a ReactNative app, in the road to implement a "native" mobile GB editing experience as per the Make post.
Among the goals is to eventually be able to introduce patterns for how to share code between GB the webapp and GB the native mobile app. Please, feel free to open PRs against this one with proposals towards that goal.
TODO before lifting the "In progress" label:
Have a proposal ready for how to change thecore/code
block definition so its high level definition is shared among the 3 platforms (web, Android, iOS)For the time being, the
.native.js
variants of key files (index.js
among which is the most important ones) will serve as the method we provide compatibility with an RN app. The goal is still to come up with a "common language" down the road but we need to port more code before patterns on what the common language is emerge.Types of changes
Introduces
.native.js
variants of various key files. Those are picked up instead of the corresponding.js
files when the code is imported in an RN build. The regular Gutenberg build just ignores the.native.js
files.The specialized
index.native.js
files play a key role: They are importing only the submodules needed by the RN implementation. These submodules will gradually be ported and only where appropriate.Ports the
core/code
block into a RN compatible component.None.
Checklist: