RefreshableScrollView

1.3.1

SwiftUI ScrollView supporting pull-to-refresh
elegantchaos/RefreshableScrollView

What's New

1.3.1

2022-11-29T16:22:28Z

Don't suppress scrolling when user is searching.

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.

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

Last updated: Tue Mar 12 2024 10:29:59 GMT-0900 (Hawaii-Aleutian Daylight Time)