Skip to content

Instantly share code, notes, and snippets.

@advienncurtiz
Last active April 8, 2022 00:29
Show Gist options
  • Save advienncurtiz/905067556075e8ee050d54f4ef16660c to your computer and use it in GitHub Desktop.
Save advienncurtiz/905067556075e8ee050d54f4ef16660c to your computer and use it in GitHub Desktop.
Simple Navigaton bar for Sheet
struct SheetNavigationView<Content>: View where Content: View {
var views: Content
var closeButtonTapped: () -> Void
var barHeight: CGFloat = 64
init(@ViewBuilder content: () -> Content, closeButtonTapped: @escaping () -> Void) {
self.views = content()
self.closeButtonTapped = closeButtonTapped
}
var body: some View {
ZStack(alignment: .top) {
VStack {
Spacer(minLength: barHeight)
views
}
VStack {
makeHeader()
.frame(height: barHeight)
Spacer()
}
}
}
@ViewBuilder
private func makeHeader() -> some View {
ZStack {
Color.gray
.frame(minHeight: 0, maxHeight: .infinity, alignment: .center)
HStack {
Spacer()
Button {
closeButtonTapped()
} label: {
Image(systemName: "xmark")
.frame(width: 12, height: 12, alignment: .center)
.padding(8)
.font(Font.subheadline.weight(.semibold))
.foregroundColor(Color.white)
.background(Circle().fill(Color.black))
}
}
.padding(.horizontal)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment