Skip to content

fix(iOS): viewhierarchy stability with modals #6370

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

Conversation

NathanWalker
Copy link
Contributor

PR Checklist

What is the current behavior?

Apps can get a "white screen of death" due to invalid and improper viewController handling on iOS related to modals.

What is the new behavior?

Ensures that a viewController is properly closed in the case one needs to be before opening to avoid app error.

The issue here relates to {N} + Angular however it's tied to this problem in core modules ultimately.
closes NativeScript/nativescript-angular#1546

@ghost ghost added the ♥ community PR label Oct 8, 2018
@NathanWalker
Copy link
Contributor Author

This PR is not cleanest solution however intended to provide suggestion on fix which core team may can address in best way possible. This modification has been tested pretty rigorously and has been found to be the type of fix needed to solve the issue mentioned.

@ns-bot ns-bot added the cla: yes label Oct 8, 2018
@NathanWalker NathanWalker force-pushed the feat-ios-viewhierarchy-improvements branch 2 times, most recently from c1309c6 to c238bc5 Compare October 8, 2018 21:32
@NathanWalker
Copy link
Contributor Author

NathanWalker commented Oct 8, 2018

Ideally we could use https://developer.apple.com/documentation/uikit/uiviewcontroller/1621505-dismissviewcontrolleranimated with the completion handler to ensure it's fully closed in that particular condition. Not sure if worth the trouble since usually this particular condition just needs to fully close (with no animation) before opening again (and the timeout here ensures that as well as appears to fully correct the situation) but perhaps the completion handler's could be used to tighten all this up and avoid race conditions in the most sure fire way.

@MartoYankov
Copy link
Contributor

@NathanWalker Indeed this fix doesn't look clean. It's not clear how the problem of a viewController not having a view is fixed by closing a modal view on the same viewController. Perhaps this fixes a certain scenario, but it's not immediately clear what it is.

My guess is that you are trying to open a modal view on a target that already opened a modal view. The iOS framework doesn't allow this by default and we are currently not supporting this. If indeed this is the case, we can discuss further if this is indeed a desirable behavior.

@NathanWalker
Copy link
Contributor Author

Agreed @MartoYankov - I assume that your team also believed a modal needed to be closed in that condition though hence the message you all had in there:

Parent page is not part of the window hierarchy. Close the current modal page before showing another one!

So instead of just logging a message I did just that: closed the current modal. Again it appears to fix it - why it fixes it not sure but it's a definite race condition that I've had trouble reproducing really over the past year to year and half as I've run into from time to time in all sorts of {N} projects.

Bottom line I believe is that the message that was there (is there currently alludes to the situation), let's just handle and not let apps fail on that condition.

Reproducing it or providing a test for it - I wish I knew - race conditions are tough.

@NathanWalker NathanWalker force-pushed the feat-ios-viewhierarchy-improvements branch from c238bc5 to edb9566 Compare October 9, 2018 21:38
@vakrilov
Copy link
Contributor

Hey @NathanWalker

I have done some tests and managed to reproduce the "Close the current modal page before showing another one!" error consistently in 2 scenarios:

1. Open a modal page in the closeCallback of another modal page

The issue here is that we fire the closeCallback before the closing animation is completed. As you suggested - I tried using the dismissViewControllerAnimatedCompletion and fire the callback in the completion handler. This seems to resolve the issue. 🎉
Also related to #5744

2. Open a modal page while another one is opened

The issue here is the same as before - there is already modally presented view controller, so we cannot present another one. The solution might be to have a parameter forceCloseOpenedModal in the showModal() method. The implementation should trigger a close on the current modal and use the completion callback (as in the previous case) to show the new modal. The value of this "force" param can also be true by default, which will make it behave much like what you are aiming with this PR.

Here is the branch that I have been experimenting with:

Next Steps

This PR triggered a good discussion. One thing is sure - setTimeout(openNow(), 300); is not the right approach here - that's why I'm closing this PR.
What's next:

  1. Work on a PR based on dismissViewControllerAnimatedCompletion to resolve iOS: issue when trying to chain modal pages within promise #5744 (problem 1)
  2. Work on on the forceClose option (problem 2). We can set it to true by default or make angular always pass true when showing modals.
  3. Once the above are done. Let's see if there are more "view-hierarchy stability" issues that developers can easily hit.

Your help is much appreciated if you want to contribute on this plan.

@vakrilov vakrilov closed this Nov 28, 2018
@ghost ghost removed the ♥ community PR label Nov 28, 2018
@NathanWalker
Copy link
Contributor Author

@vakrilov hooray! this is great news thank you so much for digging into this one 🤗
Love your proposal 1 & 2 in next steps - I'll definitely try to help on those when I can.

@lock
Copy link

lock bot commented Nov 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Nov 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(modals): easier ViewContainerRef handling
4 participants