Skip to content

Commit

Permalink
[removedAfterProceeding] - Adds completion call to destroy - MOB
Browse files Browse the repository at this point in the history
  • Loading branch information
Megan Wiemer committed Jun 7, 2021
1 parent b1c6206 commit 7405cf7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Sources/WorkflowUIKit/UIKitPresenter.swift
Expand Up @@ -66,11 +66,11 @@ open class UIKitPresenter: OrchestrationResponder {

if lastInstance?.value.metadata.persistence == .removedAfterProceeding,
let view = lastInstance?.value.instance?.underlyingInstance as? UIViewController {
destroy(view)
}

destroy(view) { onFinish?(passedArgs) }
} else {
onFinish?(passedArgs)
}
}

func abandon(_ workflow: AnyWorkflow, animated: Bool, onFinish: (() -> Void)?) {
guard let first = firstLoadedInstance else { return }
Expand Down Expand Up @@ -100,12 +100,13 @@ open class UIKitPresenter: OrchestrationResponder {
}
}

private func destroy(_ view: UIViewController) {
private func destroy(_ view: UIViewController, completion: (() -> Void)? = nil) {
if let nav = view.navigationController {
let vcs = nav.viewControllers.filter {
$0 !== view
}
nav.setViewControllers(vcs, animated: false)
completion?()
} else {
let parent = view.presentingViewController
let child = view.presentedViewController
Expand All @@ -116,6 +117,8 @@ open class UIKitPresenter: OrchestrationResponder {
if let p = parent,
let c = child {
p.present(c, animated: false)
} else {
completion?()
}
}
}
Expand Down

0 comments on commit 7405cf7

Please sign in to comment.