-
Notifications
You must be signed in to change notification settings - Fork 58
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
Changes to integrate Gutenberg-Mobile into the WPiOS App #195
Conversation
Adding some test HTML code
I'm thinking, the changes in this PR show how we can send data from RN to the parent/hosting app, when the action is triggered via the RN layer (the save/close buttons introduced in this PR). I would assume that we probably want to reuse the app bars already in place in the main WP apps and those already have their set of buttons like close/update. Tapping those means that the action will be triggered by the hosting layer and we will need to extract the html data off the RN layer. Have you found a good way to do that? AFAICT, we can't extract data synchronously but the current WP app implementations assume it to be synchronous, right? My investigation so far (on Android) tells me we probably need to revise the main app implementation to support async extraction or just block the thread while waiting for the answer from the JS core. WDYT? (EDIT: there's probably already a pattern in place to wait for an async result in the case of the older, hybrid editor, pre-Aztec. We might just try that.) |
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.
A few thoughts:
- Yay! for having this first connection/integration in place! The very first important step to establish a communication channel between the layers!
- The "Shared" folder inside the
ios/
dir is a good idea but we probably need to put it even more "up" and have a dedicated native module project just for that, one that will include the Android counterpart as well. I'm thinking, let's create a library with https://facebook.github.io/react-native/docs/native-modules-setup. We can name itreact-native-gutenberg-bridge
and place it at the root of the mobile repo (no submodule or anything, just add it there). - We can introduce a JS module that that the
import NativeModules from 'reac-native
and export a friendlier name for the bridge module (https://github.com/frostney/react-native-create-library does that automatically actually). - I think the JS based save/close buttons are not the solution we'd like to go down with. We better rely on the respective buttons already in the parent app. It's probably OK to leave them in as an example for now but, let's try to remove them.
Points 2 and 3 above can actually be performed in another PR, no blockers for this one. I think I will open a PR myself for those. Point 4 though is kinda a blocker for me. For ease of development, let's keep them in but make them use the methods from the bridge to simulate the button clicks from the parent app. Does that make sense?
Update:
To test:
Note:
cc @pinarol |
There is a new |
It seems that we have no more use of the In that sense, and since |
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.
Just 1 comment for now.
Also a question: is there an integration PR I can use to test this in WPiOS?
|
||
import UIKit | ||
|
||
class GutenbergViewController: UIViewController { |
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.
Going the route of providing a VC in Gutenberg is a double edged sword, and one that I'd really try to avoid, if possible.
I realize I may not see the full picture so my initial question is: was this choice because of advantages? requirements?
To explain a bit more why I think this is a bigger deal that can be apparent at first... this is all coming from my experience working in Aztec:
- This couples the UI surrounding the editor, to
gutenberg-mobile
. If the UI needs to be customized we'll need to add extra code to support any such customization (that'd be otherwise for free). Think of the app needing to show different colors... change the whole layout... move buttons around. Or even worse, us wanting to use this library in two different Apps. - This potentially couples other things too, such as service calls, business logic (that may already exist WPiOS). We may also need to add native dependencies to
gutenberg-mobile
(things likeWordPressShared
... the media provider... services... UI components that exist in WPiOS... etc). - It would reduce our ability to reuse Gutenberg elsewhere. I don't have a clear picture of where Gutenberg may end up showing up, but the advantage in working the editor as a view component is that you can place it anywhere.
Overall, while it may seem simpler, it may end up adding a ton of extra work to access things that we'd get for free if we just provided a view 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.
Thanks for your comments @diegoreymendez !
I believe there's a misunderstanding. Probably I haven't explained this implementation properly.
This GutenbergViewController
only exists in the Example app and is meant to be a testing platform for the native modules (the communication between RN and Native).
The plan (as I see it so far) would be to provide just the Gutenberg.h
interface to the gutenberg-mobile
users (i.e: WPiOS). Gutenberg.h
currently lives inside react-native-gutenberg-bridge
but ideally we would provide it as the public header in a Pod framework. It provide access to the Gutenberg RootView (plain UIView
), and it doesn't have any React / ReactNative public dependencies (all the React dependencies are managed internally). It also has methods to send messages to the RN side and a delegate to receive messages from RN.
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.
Maybe we could rename it GutenbergExampleController
, or plane ExampleController
to be more explicit about it.
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 think my confusion stems from the fact there's no mention of Example
in the file path or name... it's not a big deal to be honest. If this is an Example App VC we should be good.
Hey @diegoreymendez , There is a branch that I'm using to test the integration of this branch on WPiOS: I recommend you to clone it on a clean folder. The steps to make it run are (so far):
Following the comment instructions should fix the error and should run the app. The whole dependency management is quite messy for now, but that is the part I just "have been making it work". If you have ideas, everything is welcome! This little import Hack is the next thing I'm planing to fix, as soon as we finish with the Aztec stuff. 😅 In the WPiOS project there's a new Same than Aztec, Gutenberg is just a I'm waiting forward for your observations and thoughts on this approach. |
@etoledom - In the WPiOS integration branch, when doing
|
Does it happens on this branch? (Without being a submodule of WPiOS).
|
@@ -1,18 +1,18 @@ | |||
|
|||
Pod::Spec.new do |s| | |||
s.name = "RNReactNativeGutenbergBridge" |
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.
Sorry, I'm picky with names 😁, but why not just Gutenberg
?
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 is just the Bridge
module to communicate between parent and the RN app.
Probably we want to name Gutenberg
to the whole Gutenberg module (our RN App) 😄
We will see it more clearly when we work on the integration with the WPiOS app in detail.
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 sure if relevant but, I'd avoid using the "Gutenberg" generic term just yet. We need to be able to say "bridge" and understand which component we're talking about and ideally how to search for it. Just my 2c.
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.
Got it, I think I need to catch up a bit on how the details of integrating work 😁
In that case, GutenbergBridge
seems reasonable. RN
and ReactNative
is saying the same thing twice, and IMO both are redundant since we only have a “bridge” because Gutenberg is RN. This isn’t super important, but the odd naming caught my attention
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.
thank you for your effort! I just entered some small comments, nothing critical. some of them are just questions.
@hypest -
That's even better! I rolled back the @pinarol - Thanks for your observations. For now we are obligated to only use one instance of Gutenberg in the parent app at a given time. But as we talked with @hypest some time ago, this is fine for now and we can improve it when the need arrives. This is also deallocating |
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.
Looks good! 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.
Works as described.
This PR has all the minimum changes required for the simplest integration with the WPiOS app. This PR is intended to gather feedback rather than to merge it directly.
This is still early, but I decided to start a PR at this point before it becomes more complex and difficult to review. There's enough things implemented to get a general idea.
RN side changes:
There are a few changes in the "Gutenberg view" (aka
block-manager
):Added a
Save
button and aCancel
button:I was wondering if those buttons should go in the RN side or in the Native side. I decided to add them in RN as it increase the shared code between platforms, and the communication code is slightly simpler. We might decide later that the second option is better, but to start I'm giving this option a shot.
Calls to parent app:
Added method calls to the host app (
savePost
andclose
), these are resolved in iOS by the changes made to the example app, but they will error on Android when the new buttons are pressed until the communication are implemented there.Native (iOS) side changes:
I added a new folder called
Shared
. It holds the files that are being shared with the WPiOS project. For now I added them to WPiOS via direct reference, but the ideal is to make aGutenberg Bridge
package, or maybe to bundle them together withRNAztec
. We decided with @hypest that it's still too early to do this, so I'm sticking with referencing them for now.The communication manager (PostManager for now) is global, since the bridge is initiated with the app launch, and they sirve as mediators more than managers (candidate for renaming). They shouldn't own business logic, instead it just pass messages to its delegate.
PostManager
could easily become a generic mediator between RN and Native, taking care of all the communication we need.GutenbergBridge
is encapsulating all the RNBridge logic together with the dependency onReact
, and it holds a reference of the communication managers for easy access by theGutenbergController
(spoiler for the WPiOS integration).The Hack:
This is more relevant when reviewing the integration on WPiOS, but there are some
// import React
and//#import "WordPress-Swift.h"
. That is because I'm referencing the files directly into the WPiOS app, and the dependency management is different. So the WPiOS app won't compile unless we uncomment those import statements (not necessary to review this PR).I'll be checking how to solve this issue next week and I appreciate any help I can get with it :]
I'm happy to accept ideas, name changes, concept changes, UI changes, etc...
Thank you!
BTW: Not sure why travis is failing, it errors trying to:
"eval git submodule update --init --recursive "
To test: