Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -54,9 +57,9 @@ let package = Package(
),
.target(
name: "StickyHeader",
dependencies: [
]
dependencies: []
),
.target(name: "TopBar"),
.testTarget(
name: "DynamicListTests",
dependencies: ["DynamicList"]
Expand Down
42 changes: 42 additions & 0 deletions Sources/TopBar/TopBar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import SwiftUI

public struct TopBar<Content: View>: 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)
}