Skip to content

Commit

Permalink
Dismiss presented controller when parent is nil (#217)
Browse files Browse the repository at this point in the history
* dismiss presented controller when parent is nil

* test that the modally navigation controller pops with animation

* Updated tests.

---------

Co-authored-by: Brandon Williams <[email protected]>
  • Loading branch information
dazy1030 and mbrandonw authored Aug 27, 2024
1 parent 9540d98 commit e834b37
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
32 changes: 32 additions & 0 deletions Examples/CaseStudiesTests/PresentationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,38 @@ final class PresentationTests: XCTestCase {
await assertEventuallyEqual(nav.viewControllers.count, 1)
await assertEventuallyNil(nav.presentedViewController)
}

@MainActor func testAnimatedPopFromModallyNavigationController() async throws {
class VC: ViewController {
@UIBinding var presentedChild: Model?
override func viewDidLoad() {
super.viewDidLoad()
present(item: $presentedChild) { model in
let root = BasicViewController(model: model)
return UINavigationController(rootViewController: root)
}
}
}
let vc = VC()
try await setUp(controller: vc)

vc.presentedChild = Model()
await assertEventuallyNotNil(vc.presentedViewController)

vc.presentedChild?.isPushed = true
await assertEventuallyEqual(
(vc.presentedViewController as? UINavigationController)?.viewControllers.count,
2
)

try await Task.sleep(for: .seconds(0.3))
vc.presentedChild?.isPushed = false
await assertEventuallyEqual(
(vc.presentedViewController as? UINavigationController)?.viewControllers.count,
1
)
await assertEventuallyNotNil(vc.presentedChild)
}
}

@Observable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "808eb8e1d07661e8b57a786176eca2c0701a6e550ecfe221b0585e8b058c8ebd",
"originHash" : "d0f789afc5a07ea2d162d8405e7e2c61a4303155472804d542723dbcf4eba9e7",
"pins" : [
{
"identity" : "combine-schedulers",
Expand Down Expand Up @@ -67,7 +67,7 @@
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"location" : "https://github.com/swiftlang/swift-docc-plugin",
"state" : {
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
Expand Down
3 changes: 2 additions & 1 deletion Sources/UIKitNavigation/Navigation/Presentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@
// deinit alongside it on the main thread. If we use this other places we should force it
// to be a UIViewController as well, to ensure this functionality.
MainActor._assumeIsolated {
self.controller?.dismiss(animated: false)
guard let controller, controller.parent == nil else { return }
controller.dismiss(animated: false)
}
}
init(_ controller: UIViewController, id presentationID: AnyHashable? = nil) {
Expand Down

0 comments on commit e834b37

Please sign in to comment.