In MacCatalyst on MacOS Sonoma 14.6 when my app has 3 levels of active sheets the 3rd sheet disappears immediately after presenting, if the 1st level sheet is a modifier on a view in the NavigationStack, rather than a modifier of the NavigationStack. I don’t have this problem in MacCatalyst on MacOS 13.6, on iOS 16.4 or on iOS 17.6. In my real app each one of these NavigationStacks has many sheets, hence the use of the overlays. What’s the right way to make this work on iOS > 16 and macCatalyst on MacOs > 14.6? Thank you
import SwiftUI
@main
struct TestSheetsApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State var popup1Item = false
var body: some View {
NavigationStack {
Button("Show Popup 1") {
popup1Item = true
}
// this code results in the 3rd level of sheet disappearing after presenting
.overlay(
EmptyView()
.sheet(isPresented: $popup1Item) {
Popup1()
}
)
}
// this code results in the 3rd level of sheet staying after presenting
/*
.overlay(
EmptyView()
.sheet(isPresented: $popup1Item) {
Popup1()
}
)
*/
}
}
struct Popup2: View {
@State var showPopup3 = false
var body: some View {
NavigationStack {
Button("Show Popup 3") {
showPopup3 = true
}
}
.overlay(
EmptyView()
.sheet(isPresented: $showPopup3) {
Text("Popup 3")
}
)
}
}
struct Popup1: View {
@State var popup2Item = false
var body: some View {
NavigationStack {
Button("Show Popup 2") {
popup2Item = true
}
.overlay(
EmptyView()
.sheet(isPresented: $popup2Item) {
Popup2()
}
)
}
}
}