Skip to content

Commit e4b0d4d

Browse files
acosmicflamingombrandonwstephencelis
authored
Dismiss should be called on child being passed in dismiss closure (#310)
* Dismiss should be called on child being passed in onDismiss closure * Dismiss 'self' when presentedByID's controller did not trigger dismissal * Dismiss presentedViewController instead of 'self' when not nil * Always pass 'controller' to dismiss closure * Dismiss presentedViewController if non-nil or self in dismiss closure * wip * Try to fix iOS 26 crash * wip --------- Co-authored-by: Brandon Williams <[email protected]> Co-authored-by: Stephen Celis <[email protected]>
1 parent 3091def commit e4b0d4d

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

Sources/UIKitNavigation/Navigation/Presentation.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,17 @@
122122
} present: { [weak self] child, transaction in
123123
guard let self else { return }
124124
if presentedViewController != nil {
125-
self.dismiss(animated: !transaction.uiKit.disablesAnimations) {
125+
self.dismiss(
126+
animated: !transaction.uiKit.disablesAnimations
127+
) {
126128
onDismiss?()
127129
self.present(child, animated: !transaction.uiKit.disablesAnimations)
128130
}
129131
} else {
130132
self.present(child, animated: !transaction.uiKit.disablesAnimations)
131133
}
132-
} dismiss: { [weak self] _, transaction in
133-
self?.dismiss(animated: !transaction.uiKit.disablesAnimations) {
134+
} dismiss: { child, transaction in
135+
child.dismiss(animated: !transaction.uiKit.disablesAnimations) {
134136
onDismiss?()
135137
}
136138
}
@@ -356,14 +358,11 @@
356358
}
357359
}
358360
let childController = content(unwrappedItem)
359-
let onDismiss = {
360-
[
361-
weak self,
362-
presentationID = id(unwrappedItem.wrappedValue)
363-
] in
364-
if let wrappedValue = item.wrappedValue,
365-
presentationID == id(wrappedValue)
366-
{
361+
let onDismiss = { [
362+
weak self,
363+
presentationID = id(unwrappedItem.wrappedValue)
364+
] in
365+
if let wrappedValue = item.wrappedValue, presentationID == id(wrappedValue) {
367366
inFlightController = self?.presentedByID[key]?.controller
368367
item.wrappedValue = nil
369368
}
@@ -387,10 +386,20 @@
387386
}
388387
} else if let presented = presentedByID[key] {
389388
if let controller = presented.controller {
390-
dismiss(controller, transaction)
389+
var controllerToDismiss: UIViewController? = nil
390+
if inFlightController != nil {
391+
controllerToDismiss = inFlightController
392+
inFlightController = nil
393+
} else if controller.presentedViewController != nil {
394+
controllerToDismiss = self
395+
} else {
396+
controllerToDismiss = controller
397+
}
398+
if let controllerToDismiss {
399+
dismiss(controllerToDismiss, transaction)
400+
}
391401
}
392402
self.presentedByID[key] = nil
393-
inFlightController = nil
394403
}
395404
}
396405
}

0 commit comments

Comments
 (0)