I am trying to present a sheet from an item in a VStack. The following code works on iOS 13.7 but not on iOS 14:
import SwiftUI
struct ListRow: View {
@State var showingSheet: Bool = false
var body: some View {
Button(action: {
self.showingSheet = true
}) {
Text("Tap me")
}.sheet(isPresented: self.$showingSheet, content: {
NavigationView {
Text("Hello")
}
})
}
}
struct ListRow_Previews: PreviewProvider {
static var previews: some View {
ListRow()
}
}
struct ContentView: View {
@State private var showingModal: Bool = false
var body: some View {
NavigationView{
VStack {
ForEach (0..<10) {_ in
ListRow().padding()
}
}.navigationBarItems(leading: Button(action: {
self.showingModal = true
}, label: {
Text("TAP")
})).sheet(isPresented: self.$showingModal, content: {
Text("Testing main modal")
})
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
However, when I replace the VStack with a List, it seems to work.
Is this intended behaviour or a bug in SwiftUI on iOS 14? What am I doing wrong?
Thanks
Tobias Timpe