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.
But if we do this, the issue solves.
I just added a line that reads the value of selectedValue
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.
Code Block swift 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.
Code Block swift 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