Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to mimic .sheet usage for project. #13

Closed
haIIux opened this issue Jun 14, 2021 · 3 comments · Fixed by #16
Closed

Unable to mimic .sheet usage for project. #13

haIIux opened this issue Jun 14, 2021 · 3 comments · Fixed by #16

Comments

@haIIux
Copy link

haIIux commented Jun 14, 2021

Forgive me please, as this is my first attempt at an issue and I'm new to programming. I am trying to utilize your wonderful SPM project in my own application.

@State var presentedLocation: Location?
           
 .sheet(item: $presentedLocation) { place in
    SelectedBusinessSheet(selectedBusiness: place)
}

Above is how I would call this sheet and display the data. the presentedLocation is an identifiable struct that is used to create an array of data. This method displays the sheet as desired but it looks poorly and would look better in a BottomSheet.

I am unable to mimic this method however, as displayed below, I get the following errors.

.bottomSheet(isPresented: $presentedLocation, height: 700, content: { place in
   SelectedBusinessSheet(selectedBusiness: place)
})

  • Cannot convert value of type 'Binding<Location?>' to expected argument type 'Binding'
  • Contextual closure type '() -> SelectedBusinessSheet' expects 0 arguments, but 1 was used in closure body

I apologize if these are obvious errors that can be easily rectified. Any help is appreciated!

@4brunu
Copy link
Contributor

4brunu commented Mar 20, 2022

I have the same issue.
This would indeed be a great improvement.

@4brunu
Copy link
Contributor

4brunu commented Mar 20, 2022

I tried to create an extension to add this functionality, but it didn't work.

extension View {
    func bottomSheet<Item: Identifiable, Content: View>(
        item: Binding<Item?>,
        height: CGFloat,
        topBarHeight: CGFloat = 30,
        topBarCornerRadius: CGFloat? = nil,
        contentBackgroundColor: Color = Color(.systemBackground),
        topBarBackgroundColor: Color = Color(.systemBackground),
        showTopIndicator: Bool = true,
        @ViewBuilder content: @escaping (Item) -> Content
    ) -> some View {
        let isPresented = Binding {
            item.wrappedValue != nil
        } set: { value in
            if !value {
                item.wrappedValue = nil
            }
        }
        
        return self.bottomSheet(
            isPresented: isPresented,
            height: height,
            topBarHeight: topBarHeight,
            topBarCornerRadius: topBarCornerRadius,
            contentBackgroundColor: contentBackgroundColor,
            topBarBackgroundColor: topBarBackgroundColor,
            showTopIndicator: showTopIndicator
        ) {
            if let unwrapedItem = item.wrappedValue {
                content(unwrapedItem)
            } else {
                EmptyView()
            }
        }
    }
}

I'm not sure if I'm missing something.

@weitieda do you have any idea of what I'm doing wrong?

EDIT: I have updated the code snippet and It works now!

@4brunu
Copy link
Contributor

4brunu commented Mar 20, 2022

I opened #16 that fixes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants