diff --git a/Package.swift b/Package.swift index 4b2a4db..334a8b3 100644 --- a/Package.swift +++ b/Package.swift @@ -24,25 +24,28 @@ let package = Package( name: "StickyHeader", targets: ["StickyHeader"] ), + .library( + name: "TopBar", + targets: ["TopBar"] + ), ], dependencies: [ .package(url: "https://github.com/FluidGroup/swift-indexed-collection", from: "0.2.1"), .package(url: "https://github.com/siteline/swiftui-introspect", from: "1.3.0"), - .package(url: "https://github.com/FluidGroup/swift-with-prerender", from: "1.0.0") + .package(url: "https://github.com/FluidGroup/swift-with-prerender", from: "1.0.0"), ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. // Targets can depend on other targets in this package and products from dependencies. .target( name: "DynamicList", - dependencies: [ - ] + dependencies: [] ), .target( name: "CollectionView", dependencies: [ "ScrollTracking", - .product(name: "IndexedCollection", package: "swift-indexed-collection"), + .product(name: "IndexedCollection", package: "swift-indexed-collection"), ] ), .target( @@ -54,9 +57,9 @@ let package = Package( ), .target( name: "StickyHeader", - dependencies: [ - ] + dependencies: [] ), + .target(name: "TopBar"), .testTarget( name: "DynamicListTests", dependencies: ["DynamicList"] diff --git a/Sources/TopBar/TopBar.swift b/Sources/TopBar/TopBar.swift new file mode 100644 index 0000000..1d33eef --- /dev/null +++ b/Sources/TopBar/TopBar.swift @@ -0,0 +1,42 @@ +import SwiftUI + +public struct TopBar: View { + + private let content: Content + private let height: CGFloat + private let backgroundColor: Color + + public init( + height: CGFloat = 44, + backgroundColor: Color = Color(.systemBackground), + @ViewBuilder content: () -> Content + ) { + self.height = height + self.backgroundColor = backgroundColor + self.content = content() + } + + public var body: some View { + content + .frame(height: height) + .frame(maxWidth: .infinity, alignment: .center) + .background( + backgroundColor + ) + } +} + +#Preview { + VStack { + TopBar { + HStack { + Text("Title") + .font(.headline) + } + .padding(.horizontal) + } + Spacer() + } + .background(Color.purple) +} +