[Xcode 12 beta.1] @State does not project a value correctly that set from an event handling closure.
While I'm trying to use SwiftUI on Xcode12 beta.1.
I found @State does not work correctly under the specific case.
That issue will appear in following:
@State var selectedValue get a new value from onTapGesture of something view.
And then, attempt present sheet.
That sheet presentation needs the view that contains selectedValue
selectedValue must have the set value, because it will run afeter modified selectedValue. but it does not.
struct ContentView: View {
@State var selectedValue: Int?
@State var isPresented = false
var body: some View {
VStack {
Text("Tap this number")
.onTapGesture {
selectedValue = 1
isPresented = true
}
}
.sheet(isPresented: $isPresented) {
Text(selectedValue!.description)
}
}
}
But if we do this, the issue solves.
struct ContentView: View {
@State var selectedValue: Int?
@State var isPresented = false
var body: some View {
VStack {
	 Text(selectedValue.debugDescription)
Text("Tap this number")
.onTapGesture {
selectedValue = 1
isPresented = true
}
}
.sheet(isPresented: $isPresented) {
Text(selectedValue!.description)
}
}
}
I just added a line that reads the value of selectedValue