-
Notifications
You must be signed in to change notification settings - Fork 56
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
Fix crash and side effects on double rotation with modal #2011
Fix crash and side effects on double rotation with modal #2011
Conversation
@hypest I wanted to attempt to address your question from #1288 (comment), since I was able to dig into this issue this week and resolve some side effects (pending review) that we were seeing from @mkevins fix for wordpress-mobile/WordPress-Android#10227.
So Those same Line 461 in 7500e0e
In short, |
👍 @cameronvoell , thanks for having a deep look. |
Thanks Cameron for summarizing the lifecycle methods behavior, and for finding a solution to the side effects exposed by the draft fix. Very nice work on part 2 👍 .
This makes sense to me, and works well. I've tested via the steps in the description, and everything is now working as expected.
I agree on this point too. Since our app architecture requires us to "color outside the lines" a bit, I'm unsure how readily our proposed changes would be accepted upstream. |
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.
Tested via steps in description, on Android 10 - Pixel 3a, and everything is working as expected. LGTM!
c21c9c7
to
b00c4e4
Compare
0c7071c
to
66c9403
Compare
Fixes wordpress-mobile/WordPress-Android#10227
Context
This PR borrows ideas from this older PR from @mkevins: #1288
Related PRs
Gutenberg: WordPress/gutenberg#20860
WordPress-Android: wordpress-mobile/WordPress-Android#10383
Description
The changes is this PR can be broken into
Part 1: Identical to #1288 (see the Description section there). Basically since we are creating a new Activity on orientation change we need to make a call to
ReactInstanceManager.onHostDestroy()
which will perform any required cleanup by ourReactContext's
ActivityEventListeners
. This includes removing references from our Modal to the old Activity, which fixes wordpress-mobile/WordPress-Android#10227.Part 2: of this PR is to fix some issues where modals would no longer respond after we performed the required cleanup mentioned above (see discussion here: wordpress-mobile/WordPress-Android#10383 (comment)). The simplest way I found to do this was to emit a message to our React Native Bridge that we are closing any open modals. Our React Native
BottomSheet
component that contains thereact-native-modal
will listen for these events on Android and perform a call to itsonClose
method which notifies the ReactNative state that the modal is ready to be opened again (see Gutenberg PR: WordPress/gutenberg#20860).Alternatively, we could test an update to the ReactModalHostView class in the facebook
react-native
repo that adds a call to the mOnRequestCloseListener before Dialog cleanup occurs in itsonHostDestroy
method. I have not tested this yet, but I think proposing the change to Open Source library would be complicated because the way we utilize our React Native instance inside a "headless" fragment is non standard, so this use case may not apply to most people.To test:
Tested in WordPress Android app, as well as in the Android/iOS example apps. See steps and screenshot below.
Testing steps (same apply for opening the inserter Modal, or clicking insert Image/Video to Open a modal)
Screenshot:
PR submission checklist:
RELEASE-NOTES.txt
if necessary.