Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nikstar/scaffold
Scaffold SwiftUI component inspired by Jetpack Compose
https://github.com/nikstar/scaffold
Last synced: about 2 months ago
JSON representation
Scaffold SwiftUI component inspired by Jetpack Compose
- Host: GitHub
- URL: https://github.com/nikstar/scaffold
- Owner: nikstar
- License: mit
- Created: 2024-04-03T08:24:22.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-04-03T14:32:35.000Z (10 months ago)
- Last Synced: 2024-04-03T15:29:47.510Z (10 months ago)
- Language: Swift
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Scaffold
Scaffold SwiftUI component inspired by Jetpack Compose. Works as a more flexible replacement for NavigationStack's navigation bar.
Complete example:
```swift
struct TopAppBar: View {
@Environment(\.scaffoldScrollOffset) private var scaffoldScrollOffset: CGFloat
@Environment(\.scaffoldTopBarMaxHeight) private var scaffoldTopBarMaxHeight: CGFloat?
private var scrolledPastMaxHeight: Bool {
if let scaffoldTopBarMaxHeight {
scaffoldScrollOffset < scaffoldTopBarMaxHeight
} else {
false
}
}
var body: some View {
Text("Top bar")
.frame(maxWidth: .infinity)
.frame(minHeight: 44)
.background {
if scrolledPastMaxHeight {
Rectangle()
.fill(Material.bar)
.ignoresSafeArea()
}
}
.overlay(alignment: .bottom) {
if scrolledPastMaxHeight {
Rectangle()
.fill(Color(UIColor.separator))
.frame(height: 1.0/3.0)
}
}
.animation(.smooth(duration: 0.15), value: scrolledPastMaxHeight)
}
}#Preview {
Scaffold(
content: {
ScrollView {
VStack {
ForEach(0..<100) { i in
Text("Hello world #\(i)")
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
}
}
.scaffoldScrollConnection() // reports scroll offset to the top bar
}
},
topBar: {
TopAppBar()
}
)
}
```