Skip to content

UIKit's present(item:content) function does not execute onDismiss #257

Open
@acosmicflamingo

Description

@acosmicflamingo

Description

When using present(item:content:), the onDismiss function is not executed:

// Using item parameter
present(item: $model.destination.alert, id: \.self, onDismiss: {
  print("Yay!!!")
}) { message in
  let alert = UIAlertController(
    title: "This is an alert",
    message: message,
    preferredStyle: .alert
  )
  alert.addAction(UIAlertAction(title: "OK", style: .default))
  return alert
}

// Using isPresented parameter
present(isPresented: UIBinding($model.destination.alert), onDismiss: {
  print("Yay!!!")
}) { //message in
  let alert = UIAlertController(
    title: "This is an alert",
    message: "LOL",
    preferredStyle: .alert
  )
  alert.addAction(UIAlertAction(title: "OK", style: .default))
  return alert
}

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

I expect that onDismiss is always executed when a presented UIAlertController is dismissed.

Actual behavior

I never see a print statement or have the debugger stop at the breakpoint in the onDismiss closure.

Steps to reproduce

If you run the CaseStudies app in this repository and go to ConciseEnumNavigation, you'll see that if you try and open an alert and then select "Ok", you cannot open it again.

SwiftUI Navigation version information

No response

Destination operating system

iOS 18.1

Xcode version information

Xcode 16.2

Swift Compiler version information

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions