-
Notifications
You must be signed in to change notification settings - Fork 161
Fix onDismiss not called when view controller is explicitly dismissed #255
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 onDismiss not called when view controller is explicitly dismissed #255
Conversation
|
Hi @acosmicflamingo, thanks for looking into this! However, it seems to have broken the test It would also be good to get some test coverage on this change to prove that it behaves the way you say it does. |
|
Oh okay! Sure, I can investigate and the test suggestion is a great one :) |
179c6e5 to
e323d3a
Compare
|
@mbrandonw I added a test that checks whether |
e323d3a to
2ba3b44
Compare
|
@mbrandonw revisiting this, I noticed locally that the test that was crashing also did so even without these changes. Something tells me that when the CI ran months ago and failed in Running this again, I see that the tests are all now passing. Perhaps the perfect solution was the one that was with us the whole time ;) |
|
I GOT IT! Something puzzled me how if there truly was an issue going on, you'd think the presentation tests would catch this. However, I believe the tests are missing a specific use-case of |
|
I'm going to create a separate PR that adds the test to demonstrate the issue, and will then create a PR for that branch to show that it fixes the problem. |
|
NOOOOOOOO! The most basic test I wrote to check will only sometimes fail at the very last line :( @MainActor
func testPresents_Dismissal() async throws {
let vc = BasicViewController()
try await setUp(controller: vc)
await assertEventuallyNil(vc.presentedViewController)
withUITransaction(\.uiKit.disablesAnimations, true) {
vc.model.isPresented = true
}
await assertEventuallyNotNil(vc.presentedViewController)
withUITransaction(\.uiKit.disablesAnimations, true) {
vc.presentedViewController?.dismiss(animated: false)
}
await assertEventuallyNil(vc.presentedViewController)
await assertEventuallyEqual(vc.model.isPresented, false)
await assertEventuallyEqual(vc.isPresenting, false)
} |
|
Going to close this in favor of this PR: #303 |
Looks like present(item:content:) function in UIKit does not successfully call onDismiss as one would expect. I'm not seeing a print statement when I do this:
Going through breakpoints, it appears that controller is always nil: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Navigation/Presentation.swift#L377. I find it strange because I the debugger does at some point set the dict with a value: https://github.com/pointfreeco/swift-navigation/blob/main/Sources/UIKitNavigation/Navigation/Presentation.swift#L365. Dismissal was working properly, and I have a better understanding of how caching works after spending a few minutes reading the code, so it didn't look like the problem resided there.
The next thing that stood out to me was the weakified controller property in
Presented, and that the dictionary's controller properties were being immediately deallocated. Removingweakwill certainly fix this, and I explicitly deallocate it in thedeinitto mimic theweakbehavior.