-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Introduce GutenbergEditPostActivity #8874
Conversation
Generated by 🚫 Danger |
…ter decide which editor to offer depending on a) settings and b) Post content.
…s editing, as it's only used in one place where we already know we have Gutenberg content, so let's just launch Gutenberg there.
…ed GutenbergEditPostActivity
…ted code that we'll soon need back
… we'd do for Posts
…mplementations from GutenbergEditorFragment
fragment.startActivityForResult(intent, RequestCodes.EDIT_POST); | ||
} | ||
|
||
public static void editPageForResultOnGutenberg(@NonNull Fragment fragment, @NonNull PageModel page) { |
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.
Hmm, having a Gutenberg-dedicated method (editPageForResultOnGutenberg
) is generally fine but, only a few lines above (line 605) we're seeing a different pattern, where the method is just one and it it decides internally which editor to launch. Can we get away with using just one of the two patterns 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 think it's fine for this case as otherwise we need to inject and use FluxC in ActivityLauncher just to be able to inflate the PageModel, read the content of the Post body and then only decide which Activity to launch. This, in the only case where this method is called, is already known at the time the call happens by the caller.
PostUtils.showGutenbergCompatibilityWarningDialog( | ||
getActivity(), fragmentManager, post, viewModel.site | ||
) | ||
if (PostUtils.shouldShowGutenbergEditor(false, post)) { |
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.
Feels to me that the check for Gutenberg editor is bleeding into this class (PagesFragment
) but it'd better not. Can we leave it out, perhaps by having it inside ActivityLauncher.editPageForResult()
?
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.
see comment above
Extensive work @mzorz , nice! I haven't actually finished my review pass over the full changes yet, though I did leave a couple of comments already. Thing is, I started having a feeling of unease when I realized that we'll find ourselves with effectively 2 "copies" of the EditPostActivity and most of its internals. We might not want to enter that situation. I guess I'd like others to have a pass at the PR too and we can then discuss a plan what to do next after this PR or to take another path forward. @daniloercoli and @marecar3 , can you have a look at this PR and we can share thoughts afterwards? Thanks! |
Thanks for bringing valid concerns up @hypest as usual!
Also, related to that (taken from the PR description):
We discussed this elsewhere already but bringing it here so others have the same info: this is an assumption I made: I assumed the timeframe for the editors coexisting would be rather short (just a few months) but it was brought up in our conversation that it may as well not be the case (i.e. stay with us for years). I agree we might give it a second thought if we're going to need to stick and maintain both classes for long, I just didn't see why we'd need to go through the work of refactoring only to kill it shortly after (I assumed Gutenberg to be the only editor in a few months from now). In this PR I assume what's described in "goals" point 2 (that we won't dedicate much time to maintaining the other editors as much as Gutenberg) so it made sense to let the Hope that gives a bit more context 👍 Now, that said and looking forward to taking the conversation to the next step: I still think for Gutenberg (well, RN in particular) we need to have an Activity that doesn't handle orientation changes (i.e. preventing the system from killing it in that specific case of rotation as a common use case), given it's handled in RN already. If we wanted to reuse the existing |
I had already took a look at potential solutions to the history lost issue, just before Mario implemented the fix by adding a new activity for GB only. In my short investigation there were 3 solutions on the table:
Having 2 activities is not ideal at all, but at the moment don't have better solutions to the problem. We also need to consider that |
I'd add a 4th option @daniloercoli:
|
I had a look again today and I'm wondering what y'all think about this idea (a 5th option?): Introduce a new Activity that completely inherits from the original The assumption this requires is that the code in EditPostActivity that runs when Gutenberg, should be compat with the fact that the activity will not get recreated. Ideally and hopefully, this might be easier to scope and handle in steps. All in all, nothing would change for the Aztec codepath, but the GB codepath will have the orientation "hack". Thoughts? |
I like this idea better than writing all from scratch. |
I cannot shake the feeling that retaining the Activity (new or not) on rotate will be problematic. I mean, it might even limit our options regarding layouts on landscape or on tablets. From https://developer.android.com/guide/topics/resources/runtime-changes#HandlingTheChange:
In our case, I think we'll want to have the option to update resources on rotate. So instead, I went after a different route: retain the RN view only. I opened a PR with that option so we can assess it better. |
By the way, and on a different matter, the work with the RN detach/attach in has enabled a nice trick: we can preload the RN view if we want and make the editor appear instantly. Check out the branch https://github.com/wordpress-mobile/WordPress-Android/compare/gb/experiment-preload-gb?expand=1. In the branch, I have hardcoded the bootstrap of GB during the main app activity just to test it out. Try going into the editor and back to the post list, and into the editor again to see the speed. |
Not exactly sure which limitations you would see there ☝️ , but we're definitely going down the other path for now as suggested here, after issues observed are addressed. Closing this one. |
What I had in mind there was the ability of defining different resources for different screen configurations and rotations. Think: have bigger content margins when in landscape for example. Bypassing the framework managed rotation would make it harder to have such features. |
That for sure needs to be taken care of, but I honestly don't see a hassle in it given we're talking about the Gutenberg-holding Activity only and we handle all that in RN. |
This PR introduces a dedicated Activity for hosting the Gutenberg editor, as opposed to having all editors co-live within
EditPostActivity
, which already has lots of code to make a difference and tell which editor to launch in the first place, depending on user settings, Post contents, and more intricate conditions.Context and goals
It is important to note where this particular effort comes from. This is not a real refactor of
EditPostActivity
which we've been discussing for long and postponing for when time is available to tackle such a non-trivial, and also not minor, effort.This PR on the contrary, represents what I've found to be the less disruptive way to achieve these goals:
For this, we're introducing a new Activity to host the Gutenberg editor only, but will keep the current
EditPostActivity
.I've elevated the shared constants and only the most obvious common code into an abstract class, but I've no intention to maximize code reuse for this particular effort. This is a temporal situation that makes Aztec/Visual editors live without much of a problem while we introduce the new Gutenberg editor.
A real, thorough refactor would evidently demand that we not only remove code that is not used, but we'd also need to refactor and reuse code as much as possible. Such an effort would demand more valuable time and thought for a thing that we know we're going to remove soon as part of our known plans. Thus, containing new things in an isolated way and building up from there seems to come in very handy.
ToDo (general)
Intent
we need depending on the Editor we need to launch. (13d3d75 and 2ccd179)abstract EditPostBaseActivity
class, and makeEditPostActivity
a derived class. (74765be)EditPostBaseActivity
, and add the configchanges attributes inAndroidManifest.xml
(79eef32)possibly make that logic centralizedended up having it all inActivityLauncher
where Activity intents where created. (2ccd179 and 2f8ef0e)GutenbergEditPostActivity
(left only commented code 5e1c762)EditPostActivity
(see ToDo lists below).ToDo on
GutenbergEditPostActivity
mShowGutenbergEditor
flag and usages as it's unneeded in this context (d008ed1)mShowAztec
flag and usages as it won't belong here (5e1c762)mShowNewEditor
flag and usages as it won't belong here (85263bb)make "discardLocalChanges" functionality work the same on Gutenberg as it was on AztecI'll tackle this on a separate PR once this one landsMedia - related ToDo (on separate PRs)
(5e1c762 commented out code that we'll need to reuse for Media soon)
Moved to issue wordpress-mobile/gutenberg-mobile#459
ToDo on
EditPostActivity
(cleanup)EditPostActivity
(fd181f2)To test:
CASE A: use gutenberg
CASE B: use Aztec in compatibility mode
CASE C: use Gutenberg and rotate
CASE D: use Gutenberg and rotate, observe undo/redo
NOTE: other entry points, such as uploading an image to the Media section of your site and then tapping on "WRITE POST" on the success snackbar/notification to include the just-uploaded picture in your post is not yet supported. We'll support that once Media is all wired up together.
Update release notes:
RELEASE-NOTES.txt
.