UIKit present()
function dismisses multiple view controllers when using a custom transitioning delegate
#268
Replies: 3 comments
-
Hi @juliensagot, thanks for the report. As far as I can tell, this issue doesn't have to do with a custom transition delegate. I observe the same behavior even without a transition delegate. Can you confirm that is the case on your end too? |
Beta Was this translation helpful? Give feedback.
-
@mbrandonw Interesting! While double-checking the code, I moved the declaration of the presented view controller inside the present closure instead of outside, and it works! New: present(isPresented: $viewModel.isSheetDisplayed) { [viewControllerTransitioningDelegate] in
let presentedVC = ViewControllerB()
presentedVC.modalPresentationStyle = .custom
presentedVC.transitioningDelegate = viewControllerTransitioningDelegate
return presentedVC
} old: let presentedVC = ViewControllerB()
presentedVC.modalPresentationStyle = .custom
presentedVC.transitioningDelegate = viewControllerTransitioningDelegate
present(isPresented: $viewModel.isSheetDisplayed) {
presentedVC
} I am indeed experiencing the same issue, regardless of whether a custom transitioning delegate is used in this context. |
Beta Was this translation helpful? Give feedback.
-
I am not sure why declaring the But FWIW we recommend this style anyway: present(isPresented: $viewModel.isSheetDisplayed) { [weak self] in
guard let self else { return UIViewController() }
let presentedVC = ViewControllerB()
presentedVC.modalPresentationStyle = .custom
presentedVC.transitioningDelegate = viewControllerTransitioningDelegate
return presentedVC
} We don't think the presented controllers should be escaped out of the trailing closure. You should just build it up right in the closure and return it, like like how you do for SwiftUI. I am going to convert this to a discussion for now since it everything seems to work when presenting like the above. If you investigate why the dismissal was happening and can PR a fix we would be happy to take it. |
Beta Was this translation helpful? Give feedback.
-
Description
Hi folks 👋
When using the
present()
method in conjunction with a custom transitioning delegate, the app dismisses multiple view controllers instead of just dismissing the intended view controller. This issue only occurs when a custom transitioning delegate is set.Here’s a minimal reproduction app:
SwiftNavigationDismissIssue.zip
Checklist
main
branch of this package.Beta Was this translation helpful? Give feedback.
All reactions