Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request weitieda#16 from 4brunu/feature/bottom-sheet-with-…
Browse files Browse the repository at this point in the history
…item

Create bottom sheet with item binding
  • Loading branch information
weitieda authored Mar 20, 2022
2 parents 0eb2333 + 167b2c0 commit b924a83
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Sources/BottomSheet/ViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,40 @@ public extension View {
content: content)
}
}

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 bottomSheet(
isPresented: isPresented,
height: height,
topBarHeight: topBarHeight,
topBarCornerRadius: topBarCornerRadius,
contentBackgroundColor: contentBackgroundColor,
topBarBackgroundColor: topBarBackgroundColor,
showTopIndicator: showTopIndicator
) {
if let unwrapedItem = item.wrappedValue {
content(unwrapedItem)
} else {
EmptyView()
}
}
}
}

0 comments on commit b924a83

Please sign in to comment.