0

I'm new to coding. Can someone please explain to me why this code doesn't work? I'm trying to open a sheet when a button is tapped. The button is part of a Floating Action Button like in Gmail with multiple options. This 'SecondaryButton' is the options the user sees when the FAB is active.

Button(action: {
    scanSheet.toggle()
  }, label: {
    //Scan Button
    SecondaryButton(open: $open, icon: "camera.viewfinder", label: "Scan", color: "Blue", offsetY: -90)
      .padding(.trailing, 40)
  })
    .sheet(isPresented: $scanSheet, content: {
      Text("Hello")
    })
1
  • How are you defining scanSheet? And if you always want the sheet to open I would use scanSheet = true. Commented Dec 17, 2021 at 8:23

1 Answer 1

0

I think that your SecondaryButton has something to do with this. I tested it without just a Text as label and it works.

Did you try to load a Button into the Label?

struct ContentView: View {
@State var scanSheet = false
var body: some View {
    Button(action: {
        scanSheet.toggle()
      }, label: {
        //Scan Button
        Text("Button")
          .padding(.trailing, 40)
      })
        .sheet(isPresented: $scanSheet, content: {
          Text("Hello")
        })
}

}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.