Curious sheet behaviour

Hi,

I have a strange case involving sheets, which I think it's a bug, but then again I might be missing something.

Using the following code:
Code Block
import SwiftUI
enum WhichSheet: String {
case one, two, three, none
}
struct ContentView: View {
@State private var _showSheet = false
@State private var _whichSheet: WhichSheet = .none
var body: some View {
VStack(spacing: 8) {
Button("One Sheet", action: { self._whichSheet = .one; self._showSheet = true})
Button("Two Sheet", action: { self._whichSheet = .two; self._showSheet = true})
Button("Three Sheet", action: { self._whichSheet = .three; self._showSheet = true})
}
.sheet(isPresented: $_showSheet, content: {
Text("whichSheet = \(_whichSheet.rawValue)")
})
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}


I would assume that, depending on which button is pressed, I would say a sheet with the text "whichSheet = one" or "whichSheet = two" etc.
But no matter which button is pressed first the text on the sheet is always "whichSheet = none". Only if you choose a different button the second (or third, or ...) time the correct text is being displayed.

Bug or am I missing something really obvious?

(Test using an iOS 14 / 14.2 project with Xcode 12 / 12.2 beta)

Cheers, Michael
Now logged as FB8714689.
Have the exact same issue using same code layout. Submitted a feedback report but have not heard anything about the issue. What I discovered debuggin this issues is for some reason on the frist button press the @State variables are not set by the button press. Somehow the system reads that true for presenting the sheet but at no time is that variable ever registering as true during debugging. The second variable being set and passed to the new View is also never registering as set.

If you continue to select the same button, the same behavior happens until you choose a second different button. When this happens then all the State variables are properly set and the Sheet appears correctly.

Strange Bug that needs to be fixed if Apple wants iOS 14 compatibility.

Dave

Still not working in Xcode 12 Beta 2 :-(

Still happening inXcode 13.3. Maybe in XCode 100.5 will be fixed!

Curious sheet behaviour
 
 
Q