Skip to content

Commit

Permalink
Add default VStack to shelf
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdifran committed Jun 4, 2024
1 parent 499283e commit 0646e3d
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Sources/AppUI/Extensions/View/View+Shelf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,37 @@
import SwiftUI

struct ViewShelf<ShelfContent: View>: ViewModifier {
let spacing: CGFloat?
let shelfContent: ShelfContent

init(@ViewBuilder shelfContent: () -> ShelfContent) {
init(spacing: CGFloat? = nil, @ViewBuilder shelfContent: () -> ShelfContent) {
self.spacing = spacing
self.shelfContent = shelfContent()
}

func body(content: Content) -> some View {
content
.safeAreaInset(edge: .bottom) {
shelfContent
.padding()
.background {
Rectangle()
.fill(.bar)
.edgesIgnoringSafeArea(.bottom)
}
VStack(spacing: spacing) {
shelfContent
}
.padding()
.background {
Rectangle()
.fill(.bar)
.edgesIgnoringSafeArea(.bottom)
}
}
}
}

public extension View {

func shelf<ShelfContent: View>(@ViewBuilder _ shelfContent: @escaping () -> ShelfContent) -> some View {
modifier(ViewShelf(shelfContent: shelfContent))
func shelf<ShelfContent: View>(
spacing: CGFloat? = nil,
@ViewBuilder _ shelfContent: @escaping () -> ShelfContent
) -> some View {
modifier(ViewShelf(spacing: spacing, shelfContent: shelfContent))
}
}

Expand Down Expand Up @@ -73,6 +80,7 @@ public extension View {
.navigationTitle("Preview")
.shelf {
ProminentButton("Create") { }
ProminentButton("Cancel") { }
}
}
}

0 comments on commit 0646e3d

Please sign in to comment.