Swiftpack.co -  phuhuynh2411/RefreshableScrollView as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
phuhuynh2411/RefreshableScrollView
Add a Pull to Refresh feature to the ScrollView or List
.package(url: "https://github.com/phuhuynh2411/RefreshableScrollView.git", from: "v1.1")

RefreshableScrollView

A refershable scroll view that supports List and ScrollView

The original code from this article https://swiftui-lab.com/scrollview-pull-to-refresh/. It helped me a lot. Thank you. Refresh

Platform Support

  • iOS
  • macOS

Installation

In your project, go to File -> Swift Packages -> Add Package Dependency. Copy and paste the url below into the search box https://github.com/phuhuynh2411/RefreshableScrollView.git

Basic Usage

It uses the ScrollView as a wrapper for the content

RefreshableScrollView(refreshing: $refresh, action: {
    // add your code here
    // remmber to set the refresh to false
    DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
        self.refresh = false
    }
}) {
    ForEach(0..<20){ index in
        Text("Item \(index)")
    }
}

Use with List

In some cases, you would like to use List view instead of Scrollview. You could change the scrollType to .list. There are two kinds of scroll type.

  • .list
  • .scrollView: this is a default value
RefreshableScrollView(refreshing: $refresh, scrollType: .list
    action: { self.load() }
) {
    ForEach(0..<20){ index in
        Text("Item \(index)")
    }
}

Customize Activity View

RefreshableScrollView(refreshing: $refresh,
                      activityView: AnyView(InfiniteProgressView().frame(width: 20, height: 20, alignment: .center)),
                      action: { self.load() }) {
    ForEach(0..<20){ index in
        Text("Item \(index)")
    }
}

Customize Pull View

RefreshableScrollView(refreshing: $refresh,
                      activityView: AnyView(InfiniteProgressView().frame(width: 20, height: 20, alignment: .center)),
                      pullView: { height, rotation, loading, frozen in
                        let image = Image(systemName: "shift") // If not loading, show the arrow
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: height * 0.25, height: height * 0.25).fixedSize()
                            .padding(height * 0.375)
                            .rotationEffect(rotation)
                            .offset(y: -height + (loading && frozen ? +height : 0.0))
                        return AnyView(image) },
                      action: { self.load() }
) {
    ForEach(0..<20){ index in
        Text("Item \(index)")
    }
}

GitHub

link
Stars: 3
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Fix error in iPhone 11 Pro Max
13 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API