0

I'm trying to make it so when a button is tapped, the selectedSheet variable will update and then present the proper sheet. The issue I'm having is that it never actually updates the value until a few different clicks on each option. I assume this is the wrong way to be setting the new state value or it's missing it's initial value.

struct ContentView: View {
    enum Sheets {
        case Settings,
             Information
    }
    @State private var selectedSheet: Sheets = .Settings
    @State private var showSheet = false
    
    var body: some View {
        VStack {
            Button("Open Information") {
                selectedSheet = .Information
                showSheet.toggle()
            }
            
            Button("Open Settings") {
                selectedSheet = .Settings
                showSheet.toggle()
            }
        }
        .sheet(isPresented: $showSheet) {
            switch selectedSheet {
            case .Settings :
                Text("Settings View")
            case .Information :
                Text("Information View")
            }
        }
    }
}
Joe Scotto
  • 10,936
  • 14
  • 66
  • 136

0 Answers0