If a .sheet
modifier is used on a child view while the parent view is also using a .sheet
modifier, then the child viewβs sheet will never appear:
struct ContentView: View {
@State var isPresented1 = false
@State var isPresented2 = false
var body: some View {
VStack {
Button("One") { self.isPresented1 = true }
.sheet(isPresented: self.$isPresented1) {
Text("π This will never show... π")
}
Button("Two") { self.isPresented2 = true }
}
.sheet(isPresented: self.$isPresented2) {
Text("Two presented")
}
}
}
This can be really problematic when you extract child views to their own structs:
struct ContentView: View {
@State var isPresented = false
var body: some View {
VStack {
ChildView()
Button("Two") { self.isPresented2 = true }
}
.sheet(isPresented: self.$isPresented2) {
Text("Two presented")
}
}
}
struct ChildView: View {
@State var isPresented = false
var body: some View {
Button("One") { self.isPresented1 = true }
.sheet(isPresented: self.$isPresented1) {
Text("π This will never show... π")
}
}
}
This is a huge gotcha because the child view must know that none of its parent views use the .sheet
modifier in order to be certain that its .sheet
will work.