Skip to content

UIKit: Prevent redundant dismissal of already-dismissing view controller #295

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

juliensagot
Copy link
Contributor

This fixes an issue where presenting a view controller just after dismissing one results in dismissing the presenting view controller.

When a view controller was already in the process of being dismissed (isBeingDismissed = true) or moving from its parent (isMovingFromParent = true), the presentation logic would still attempt to call dismiss() on it again, causing unintended dismissals in the presentation hierarchy.


Without the fix:

Pressing the save button dismisses the currently presented view controller and immediately presents the timer view controller. However, due to a bug, the presenting view controller is also dismissed.

Bug.mov

With the fix:

Pressing the save button correctly dismisses the currently presented view controller and then presents the timer view controller without affecting the presenting view controller.

No_bug.mov

@stephencelis
Copy link
Member

@juliensagot Thanks for this! We're definitely down to merge but in the interest of preventing regressions in the future do you think it's possible to get a test written that would fail with the existing behavior?

We have a suite here that will hopefully be easy to extend:

https://github.com/pointfreeco/swift-navigation/blob/main/Examples/CaseStudiesTests/PresentationTests.swift

Let us know if you have any questions!

@juliensagot
Copy link
Contributor Author

While writing the test, I realized the fix isn’t needed after all—it works as expected. In my project, the issue is 100% reproducible, but only the first time I present the initial view controller. There’s definitely something odd going on, and I need to spend more time investigating.

@juliensagot juliensagot marked this pull request as draft July 29, 2025 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants