Skip to content

[iOS] Using presentingViewController to dismiss Modal#24959

Closed
zhongwuzw wants to merge 1 commit into
facebook:masterfrom
zhongwuzw:fix_modal_do_not_dismiss
Closed

[iOS] Using presentingViewController to dismiss Modal#24959
zhongwuzw wants to merge 1 commit into
facebook:masterfrom
zhongwuzw:fix_modal_do_not_dismiss

Conversation

@zhongwuzw
Copy link
Copy Markdown
Contributor

Summary

Fixes #23463.
Using presentingViewController to dismiss Modal VC directly, don't let Modal VC to find presentingViewController, then dismiss.

Changelog

[iOS] [Fixed] - Using presentingViewController to dismiss Modal

Test Plan

Sample code please see #23463, it should works.

@zhongwuzw zhongwuzw requested a review from shergin as a code owner May 20, 2019 03:23
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 20, 2019
Copy link
Copy Markdown
Contributor

@janicduplessis janicduplessis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use [modalHostView reactViewController] instead? It would be more constant with the rest of the code.

@zhongwuzw
Copy link
Copy Markdown
Contributor Author

Can we use [modalHostView reactViewController] instead? It would be more constant with the rest of the code.

🤔 Originally, I want to change all [modalHostView reactViewController] to viewController.presentingViewController for consolidation, but I didn't because they may not related about this fix.

And seems we can't use [modalHostView reactViewController] here, because [modalHostView reactViewController] is not always equal to viewController.presentingViewController. reactViewController is only next VC in responder chain( In the demo, when dismiss, reactViewController is nil), presentingViewController is the VC which present presented VC. So I think we may need to use viewController.presentingViewController. :)

@shergin
Copy link
Copy Markdown
Contributor

shergin commented May 20, 2019

@janicduplessis @zhongwuzw I fell that my idiomatic iOS skills are now rusty. :( I don't remember exactly how it should work but I have to admit fixed version looks more correct to me.

reactViewController returns the closest VC that powers RCTRootView. I don't think it should be related to this issue at all because when we remove Modal we should ask the particular VC that DID present already presented VC that we are dismissing. reactViewController can be even nil in cases where we don't use VC for RCTRootView.

_dismissalBlock([modalHostView reactViewController], viewController, animated, completionBlock);
} else {
[viewController dismissViewControllerAnimated:animated completion:completionBlock];
[viewController.presentingViewController dismissViewControllerAnimated:animated completion:completionBlock];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation is clear and confirms my recollections:

dismissViewControllerAnimated:completion:

Dismisses the view controller that was presented modally by the view controller.
SDKs

So, the fix looks perfectly legit to me, the only Q that prevents me from landing it:
I don't understand how/why it worked previously. Did it? (Until we find answer to this question we cannot be sure that our conclusions are correct.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shergin Could be why it works, but maybe it dismisses the wrong vc sometimes.

 If you call this method on the presented view controller itself, UIKit asks the presenting view controller to handle the dismissal.

Thanks for clarifiying what reactViewController is. LGTM

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we just have one Modal, it works whatever we passed presented VC or presenting VC, but if we have multiple Modals, bug may happen, for example, VC present Modal A, ModalA present Modal B, if we call [ModalA dismissVC], what this should perform? because ModalA is the presenting VC to present ModalB,but it also the presented VC which presenting VC is the closest VC when present ModalA, I think this is why bug happened. :)

Copy link
Copy Markdown
Contributor

@cpojer cpojer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @zhongwuzw in 284c5f0.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label May 31, 2019
facebook-github-bot pushed a commit that referenced this pull request Jun 4, 2019
Summary:
Fixes #16037.
We need to keep the order of Modals, if we dismiss Modal randomly(before we use hash table), some Modals may not dismiss successfully.

This PR should based on #24959.

## Changelog

[iOS] [Fixed] - Keep the order of Modals that we can dismiss in sequence
Pull Request resolved: #24961

Differential Revision: D15621858

Pulled By: cpojer

fbshipit-source-id: 964729f8f4584995f4e1dd527af4b61534d369ba
M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this pull request Mar 10, 2020
Summary:
Fixes facebook#23463.
Using `presentingViewController` to dismiss Modal VC directly, don't let Modal VC to find `presentingViewController`, then dismiss.

## Changelog

[iOS] [Fixed] - Using presentingViewController to dismiss Modal
Pull Request resolved: facebook#24959

Differential Revision: D15575571

Pulled By: cpojer

fbshipit-source-id: e275e7c7fef644c06cc8e64dba5b5a5af4129192
M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this pull request Mar 10, 2020
)

Summary:
Fixes facebook#16037.
We need to keep the order of Modals, if we dismiss Modal randomly(before we use hash table), some Modals may not dismiss successfully.

This PR should based on facebook#24959.

## Changelog

[iOS] [Fixed] - Keep the order of Modals that we can dismiss in sequence
Pull Request resolved: facebook#24961

Differential Revision: D15621858

Pulled By: cpojer

fbshipit-source-id: 964729f8f4584995f4e1dd527af4b61534d369ba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Component: Modal Merged This PR has been merged. Platform: iOS iOS applications.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error closing multiples opened modals

6 participants