Skip to content

pull-to-refresh functionality for List and ScrollView controls

Notifications You must be signed in to change notification settings

HumorousGhost/RefreshableScrollView

Repository files navigation

RefreshableScrollView

This project is only for SwiftUI

Pull-to-refresh functionality for List and ScrollView controls

Encapsulated UITableView, UIScrollView, UICollectionView can also be used

Supported Platforms

  • iOS 13.0
  • macOS 10.15
  • tvOS 13.0
  • watchOS 6.0

Usage

        class ViewModel: ObservableObject {
        @Published var isRefresh: Bool = false
    }
    
    let array = ["text1", "text2", "text3"]
    @StateObject private var vm = ViewModel()
    
    var body: some View {
        List {
            ForEach(0..<array.count) { index in
                let text = array[index]
                HStack {
                    Text(text)
                }
            }
        }
        .pullToRefresh($vm.isRefresh) {
            // refresh done
            DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
                vm.isRefresh = false
            }
        }
    }

Installation

You can add RefreshableScrollView to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Swift PackagesAdd Package Dependency…
  2. Enter https://github.com/HumorousGhost/RefreshableScrollView into the package repository URL text field
  3. Link RefreshableScrollView to your application target

About

pull-to-refresh functionality for List and ScrollView controls

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages