-
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
Contain and retain GB on rotation #9030
Conversation
🥇 thanks @hypest for this 👏 This solution caters for the problem that was raised as concerning in the past: that the system can still kill the Activity for reasons other than rotation, and that would effectively make the undo/redo history lost for blocks, scroll positioning and such. I think detecting For example, turn on the To prevent this and other potential problems we should make sure any re-initialization such as According to this https://developer.android.com/guide/topics/resources/runtime-changes#HandlingTheChange
I think we can remove that piece of code ( There are more of these So, back to our thing: I think we may use a couple of options here (there may be more but these came to mind):
Does that make sense? To summarize:
What do you think? |
GutenbergEditorFragment has been recreated but the GB container hasn't so, no need to re-send content, etc. Essentially, we do let the system kill and recreate the fragments, and only let the parent continue with the "setContent()" logic if the GB container was in fact re-initialized. That handles the cases of the system killing the activities (like when "Don't keep activities" developer setting is enabled, and when rotating the device.
I just pushed 4cf21c8 @mzorz . With it, I took a kinda different approach: I tried to understand how the So, I tried to suppress the signal, instead of detecting rotations and it seems to work. The "trick" is with the flag in the GB container fragment ( This seems to work and is quite contained as a solution. Granted, not the easiest to grok perhaps. Reason is that EditPostActivity and GutenbergEditorFragment are allowed to be recreated, but the container fragment only gets recreated in some cases. Let me know what you think... thanks! |
A new issue I've seen so far is that the post is marked as "modified" even by just entering and exiting the editor. Will work on it. |
Turns out that the change detection trigger is due to a regression elsewhere (and it's in gutenberg-mobile develop), not related to this PR. |
Updated from develop @mzorz , ready for another pass, thanks! |
GutenbergContainerFragment.newInstance(isNewPost); | ||
gutenbergContainerFragment.setRetainInstance(true); | ||
fragmentTransaction.add(gutenbergContainerFragment, GutenbergContainerFragment.TAG); | ||
fragmentTransaction.commitNow(); |
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.
TIL about commitNow()
. Thanks
This looks generally good code-wise, I've been testing and found an issue with content loss on this branch, that I also confirmed happens in If Made issue here #9148 Will continue testing and update here if anything 👍 |
Nice catch @mzorz ! Confirmed the issue happening on this PR too. Even though the issue is not introduced by this PR, I think we should fix it here. Reason is that, if we merge this PR, I expect some potential problems arising anyway (i.e. potential problems with media work that is currently in progress in parallel) so, I'd like to avoid disrupting the other, parallel efforts. #9148 is about lifecycle behavior so, it's not too far from the topic of this very PR anyway. So, let's handle it here, cool? |
Agreed @hypest ! nice if we can handle it here 👍 |
Fixed the |
Updated from develop and fixed known issues. This should be ready for another pass. @daniloercoli , can you pick up reviewing this now that Mario is AFK? Let me know if you need anything to help with passing the baton. Thanks! |
Whoaa, nice solution implemented here! We had already discussed this over slack, voice and comments, and this seems the only viable solution that fixes many problems (redo/undo/caret position), even though it could seem a bit of hacky. For me is a 👍 to this PR. Not sure how much of the new media work was added back here, but during tests I found out that cannot add a media to a post with don't keep activities ON.
|
Thanks for the review pass Danilo! I'll merge whatever is latest from all Also, I have an additional fix for retaining the exact caret position (without any RN involvement for saving state and such) and I'll push it as well. |
634b546
to
c6dee6a
Compare
Added c6dee6a which points to a gutenberg-mobile + Aztec side fix for maintaining the exact caret position (inside Aztec) on rotation. Known issue: scroll position is not maintained though. I think we could address that in a separate PR. Also, updated from develop.
I'm afraid that's also true for current develop too @daniloercoli , because we rely on a callback passed from RN to Java to set the media data after selecting it from the picker. But, the picker itself is a separate Activity and causes the EditPostActivity (along with the GB fragments) to get recreated. In that whole process, the callback reference is gone. We will need to revise our implementation to not rely on a callback. I think that's beyond the scope of this PR and we better handle it in a separate one. WDYT? cc @marecar3 since all RN-callback-based features (including media upload and such) can be affected or broken when "Don't Keep Activities" is ON. |
👍 Will do another round of testing with the fix for retaining the exact caret position. |
Run another round of tests on devices running Android 9 and Android 6 and this PR works as expected. Although I noticed that the caret is not preserved on the |
Agreed! So, let's review/merge the gutenberg-mobile side PR first (wordpress-mobile/gutenberg-mobile#483), update this one and I can merge. Cool? |
For the record, I tried the wordpress-mobile/gutenberg-mobile#513 against this and the focus is properly maintained in the title too. So, I think that issue will fix itself. |
Fixes state loss issues on Gutenberg-mobile (example)
Implementation details
The Gutenberg-mobile editor is of course living inside a React Native view (ReactRootView). The solution here manages the View via a retained (headless) Fragment (GutenbergContainerFragment.java).
Especially when rotating,
setContent()
is bypassed so the content is not written again. It's not needed and it will also cause problems in the GB state.To test:
Note: at the time of writing, the Travis build fails, apparently due to some trouble with Jitpack checking out the branch (
Git error. Checkout conflict with file: Cannot delete file: react-native-aztec/example/ios
). Opened ticket on JitPack here.Update release notes:
RELEASE-NOTES.txt
.