@DTS Engineer below is the new code based on your suggestion, and I run into a new weird problem where the Button("Closure: Click to dismiss") is not responding to a click. If I remove dismiss() call, it becomes clickable.
The issue is within the context of NavigationStack, not NavigationSplitView.
struct Debug_ID2_Dismiss: View {
@Environment(\.dismiss) private var dismiss
@State private var myNavigate = false
var body: some View {
Button("Click to navigate") {
myNavigate = true
}
.navigationDestination(isPresented: $myNavigate) {
#if DISMISS_SUCCESSFULLY
DismissButton()
#else
Button("Closure: Click to dismiss") {
print("Dismissing ...")
dismiss()
print("Done dismissing")
}
#endif
}
} // body
struct DismissButton: View {
let SRC = "DismissButton"
@Environment(\.dismiss) private var dismiss
var body: some View {
Button("\(SRC): Click to dismiss") {
print("\(SRC): Dismissing")
dismiss()
print("\(SRC): Done dismissing")
}
}
} // DismissButton
} // Debug_ID2_Dismiss