sunyazhou13 / ScrollKit

ScrollKit is a SwiftUI library that adds powerful scrolling features to SwiftUI, such as offset tracking and sticky scroll view headers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ScrollKit Logo

Version Swift 5.7 Swift UI MIT License Twitter: @danielsaidi Mastodon: @danielsaidi@mastodon.social

About ScrollKit

ScrollKit adds powerful scrolling features to SwiftUI, such as scroll offset tracking and scroll view headers that stretch out as you pull down and stick to the top when you scroll.

The result can look like this, or completely different:

ScrollKit has a ScrollViewWithOffset that provides you with the scroll view offset, a ScrollViewHeader that automatically stretches out when the scroll view is pulled down, and a ScrollViewWithStickyHeader that pins the header view to the top as it is scrolled below the navigation bar.

ScrollKit's views are designed to be easy to use, and basically just add more properties to the standard SwiftUI ScrollView. They can be used on all Apple platforms, including iOS, macOS, tvOS and watchOS.

ScrollKit supports iOS 14, macOS 11, tvOS 14 and watchOS 7.

Installation

ScrollKit can be installed with the Swift Package Manager:

https://github.com/danielsaidi/ScrollKit.git

If you prefer to not have external dependencies, you can also just copy the source code into your app.

Getting started

The online documentation has a getting started guide guide to help you get started with ScrollKit.

To create a scroll view with a stretchable, sticky header, just create a ScrollViewWithStickyHeader and provide it with a header view and header height:

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.visible = 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,
            onScroll: handleOffset
        ) {
            // Add your scroll view content here as regular
        }
    }
}

The header visible ratio is based on the header height and scroll view offset and lets you adjust your content as the header is scrolled under the navigation bar, for instance to modify the header and fade in a navigation title.

For more information, please see the online documentation and getting started guide guide.

Documentation

The online documentation contains more information, code examples, etc., and makes it easy to overview the various parts of the library.

Demo Application

The demo app lets you explore the library on iOS and macOS. To try it out, just open and run the Demo project.

Support this library

I manage my various open-source projects in my free time and am really thankful for any help I can get from the community.

You can sponsor this project on GitHub Sponsors or get in touch for paid support.

Contact

Feel free to reach out if you have questions or if you want to contribute in any way:

License

ScrollKit is available under the MIT license. See the LICENSE file for more info.

About

ScrollKit is a SwiftUI library that adds powerful scrolling features to SwiftUI, such as offset tracking and sticky scroll view headers.

License:MIT License


Languages

Language:Swift 89.0%Language:Ruby 11.0%