Hello,
I am experiencing an issue in an iPad app when displaying nested sheets.
When the second sheet is dismissed, the buttons of the first one are not aligned with their clickable area. It only happens when we use the keyboard in the second sheet.
It looks like the sheet frame changes when it is behind another one.
One solution would be to put buttons inside my Form but it is not exactly what I want.
It is easily reproducible with this code :
struct ContentView: View {
@State private var openSheet = false
var body: some View {
NavigationView {
VStack {
Button {
openSheet.toggle()
} label: {
Text("click")
}
.buttonStyle(.bordered)
.padding()
.sheet(isPresented: $openSheet) {
print("first dismiss")
} content: {
NavigationView {
FirstSheet()
.interactiveDismissDisabled()
}.navigationViewStyle(.stack)
}
}
}.navigationViewStyle(.stack)
}
}
struct FirstSheet: View {
@Environment(\.dismiss) private var dismiss
var data = Array(0...10)
@State private var openSheet = false
var body: some View {
VStack {
Form {
Text("abcv")
.sheet(isPresented: $openSheet) {
print("second dismiss")
} content: {
NavigationView {
SecondSheet()
.interactiveDismissDisabled()
}.navigationViewStyle(.stack)
}
ForEach(data, id: \.self) {
Text($0.description)
}
Section {
Button {
dismiss()
} label: {
Text("dismiss")
}
.buttonStyle(.bordered)
.padding()
Button {
openSheet.toggle()
} label: {
Text("click")
}
.buttonStyle(.bordered)
.padding()
}
}
Button {
dismiss()
} label: {
Text("dismiss2")
}
.buttonStyle(.bordered)
.padding()
Button {
openSheet.toggle()
} label: {
Text("click2")
}
.buttonStyle(.bordered)
.padding()
}
}
}
struct SecondSheet: View {
@Environment(\.dismiss) private var dismiss
@State private var txt = ""
var body: some View {
VStack {
Button {
dismiss()
} label: {
Text("dismiss")
}
.buttonStyle(.bordered)
.padding()
TextField("Title", text: $txt)
}
}
}