I have a list that displays 1, 2, and 3. When the text is tapped the app opens a sheet with the number tapped. However, if I tap the text in the second or third row, the number displayed in the sheet is still 1. What am I doing wrong?
import SwiftUI
struct ContentView: View {
var numbers = [1, 2, 3]
@State private var shouldPresentSheet = false
var body: some View {
List(self.numbers, id: \.self) { number in
Text("number: \(number)").sheet(isPresented: self.$shouldPresentSheet) {
Text("This is sheet number \(number)")
}.onTapGesture {
self.shouldPresentSheet.toggle()
}
}
}
}