Swiftpack.co - elegantchaos/RefreshableScrollView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by elegantchaos.
elegantchaos/RefreshableScrollView v1.3.1
SwiftUI ScrollView supporting pull-to-refresh
⭐️ 17
🕓 1 year ago
iOS macOS watchOS tvOS macCatalyst
.package(url: "https://github.com/elegantchaos/RefreshableScrollView.git", from: "v1.3.1")

RefreshableScrollView

Provides a SwiftUI implementation of ScrollView which supports the .refreshable modifier.

Currently, the only way to get pull-to-refresh behaviour in SwiftUI is to use a List. This may not always be what you want, as List has some performance issues.

The views in this package are intended for situations where you want pull-to-refresh, but don't want to use List.

This package provides two implementations:

  1. A pure SwiftUI one: RefreshableScrollView. This works when embedded in a navigation view, and has hint flags that you can pass to help adjust the layout of the refresh control. The downside is that the precise pull-to-refresh behaviour is very slightly different from the UIKit implementation. This is because we cannot use a UIRefreshControl, as that only works when attached to a UIScrollView, which we don't have.

  2. An implementation which uses UIKit: NativeRefreshableScrollView. This uses a real UIScrollView, which contains a UIHostingController, which contains the SwiftUI content views. Doing this means that we can use UIRefreshControl for the activity/refresh indicator, and get the precise pull-to-refresh behaviour and appearance from UIKit. The downside is that it does not seem to play well if embedded inside a NavigationView; the positioning of the refresh control seems to change as soon as the refresh task begins, causing it to disappear, which looks rubbish.

Example

See Extras/Example for an example Xcode project which uses this package.

Related

My FastList package is a client of this package. FastList is intended as a replacement for SwiftUI's native List, in situations where you have a large number of items and SwiftUI performance struggles (because of the fancy animations that it tries to do).

Credits

This code builds on or takes inspiration from a few examples out there, including:

Thanks to these and others for showing the way.

GitHub

link
Stars: 17
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.3.1
1 year ago

Don't suppress scrolling when user is searching.

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