ScrollKit is a SwiftUI SDK that adds powerful scroll features, like offset tracking and a header view that stretches & transforms as you pull down, and sticks to the top when you scroll.
ScrollKit is a SwiftUI SDK that adds powerful scroll features, like offset tracking and a header view that stretches & transforms as you pull down, and sticks to the top when you scroll.
ScrollKit works on all major Apple platforms and is designed to be easy to use. It current doesn’t use the new ScrollView
APIs for OS backwards compatibility reasons, but will eventually do so.
ScrollKit can be installed with the Swift Package Manager:
https://github.com/danielsaidi/ScrollKit.git
ScrollKit has a ScrollViewWithOffsetTracking
view that can detect scrolling:
ScrollViewWithOffsetTracking { offset in
print(offset)
} content: {
// Add your scroll content here, e.g. a `LazyVStack`
}
ScrollKit also has a ScrollViewWithStickyHeader
that makes it easy to set up a stretchy, sticky header:
struct MyView: View {
@State
private var offset = CGPoint.zero
@State
private var visibleRatio = CGFloat.zero
func handleOffset(_ scrollOffset: CGPoint, visibleHeaderRatio: CGFloat) {
self.offset = scrollOffset
self.visibleRatio = visibleHeaderRatio
}
func header() -> some View {
ZStack(alignment: .bottomLeading) {
Color.blue
Color.yellow.opacity(visibleRatio) // Fades in
}
}
var body: some View {
ScrollViewWithStickyHeader(
header: header,
headerHeight: 250,
headerMinHeight: 150,
onScroll: handleOffset
) {
// Add your scroll content here, e.g. a `LazyVStack`
}
}
}
For more information, please see the getting started guide.
The online documentation has more information, articles, code examples, etc.
The demo app lets you explore the library. To try it out, just open and run the Demo
project.
You can sponsor me on GitHub Sponsors or reach out for paid support, to help support my open-source projects.
Your support makes it possible for me to put more work into these projects and make them the best they can be.
Feel free to reach out if you have questions or want to contribute in any way:
ScrollKit is available under the MIT license. See the LICENSE file for more info.