danielsaidi / BottomSheet

BottomSheet lets you add custom bottom sheets to your SwiftUI apps.
MIT License
189 stars 12 forks source link

Using BottomSheet with isPresented? #6

Closed jakeround closed 2 years ago

jakeround commented 2 years ago

Hello πŸ‘‹πŸ»

I'm attempting to use BottomSheet to build my Movie app Sonix (I'm fairly new to Swift/SwiftUI) basically i'm trying to replicate the design which is attached so each movie opens BottomSheet at full width. At the moment the only way I have it working is wrapping inside .sheet using isPresented.

Any help would be much appreciated

Screenshot 2021-11-29 at 00 18 25

Screenshot 2021-11-29 at 00 22 43
jakeround commented 2 years ago

Using the Demo app provided, I basically want to show the sheet only when the sheet has been toggled. Whatever I've tried seems to throw an error.

@State var showSheet = false

    var body: some View {
        VStack {
            if showSheet == true {
                Image(systemName: "film")
                    .resizable()
                    .frame(width: 100, height: 100, alignment: .center)
                    .foregroundColor(Color.green)
                    .padding(.bottom, 20)
            }
        }.padding(.vertical, 25)

        Button(action: {
            withAnimation{
                self.showSheet.toggle()
            }

        }, label: {
            Text("Show Sheet").font(.system(size: 20, weight: .medium, design: .default))
                .frame(minWidth: 0, maxWidth: .infinity, maxHeight: 50)
                .foregroundColor(Color.green)
                .cornerRadius(10)

        })

            .bottomSheet(sheet)
    }
danielsaidi commented 2 years ago

Hi @jakeround

The standard style for iPad is to use the full width, so that should be no problem. Have a look at the demo app.

Regarding only showing the sheet when a movie is selected, you could do it with a custom view extension:

image

In fact, I think this is a great addition to the library, so I'll add it in 0.2, which I'll release in a few minutes.

danielsaidi commented 2 years ago

I've released 0.2 now πŸŽ‰

jakeround commented 2 years ago

Thanks a lot @danielsaidi i'll take a peak later today!

Much appreciated for taking a look at my issue so quickly πŸ˜„

danielsaidi commented 2 years ago

I haven’t revisited this library since creating it, so it was great that you reminded me πŸ˜€