diff --git a/Sources/BottomSheet/ViewExtension.swift b/Sources/BottomSheet/ViewExtension.swift index 106c356..d4ee9ff 100644 --- a/Sources/BottomSheet/ViewExtension.swift +++ b/Sources/BottomSheet/ViewExtension.swift @@ -31,5 +31,40 @@ public extension View { content: content) } } + + func bottomSheet( + item: Binding, + 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 bottomSheet( + isPresented: isPresented, + height: height, + topBarHeight: topBarHeight, + topBarCornerRadius: topBarCornerRadius, + contentBackgroundColor: contentBackgroundColor, + topBarBackgroundColor: topBarBackgroundColor, + showTopIndicator: showTopIndicator + ) { + if let unwrapedItem = item.wrappedValue { + content(unwrapedItem) + } else { + EmptyView() + } + } + } }