Skip to content

A simple implementation of the very commonly used (yet surprisingly unavailable in SwiftUI framework) UIScrollView's pull to refresh functionality implemented natively in SwiftUI without using UIViewRepresentable.

License

Notifications You must be signed in to change notification settings

alivecor/BBRefreshableScrollView

 
 

Repository files navigation

BBRefreshableScrollView

A simple implementation of the very commonly used (yet surprisingly unavailable in SwiftUI framework) UIScrollView's pull to refresh functionality implemented natively in SwiftUI without using UIViewRepresentable. Package is compiled using Xcode 12.0 on MacOS 10.15.7 using Swift 5.3 compiler.


Support

Platform iOS Xcode Swift


Code

import SwiftUI
import BBRefreshableScrollView

struct ContentView: View {

    @State private var rows = [1, 2, 3, 4]

    var body: some View {
        NavigationView {
            BBRefreshableScrollView { completion in
                addNewRow {
                    completion()
                }
            } content: {
                VStack {
                    Divider()
                    ForEach(rows, id: \.self) { row in
                        HStack {
                            Text("Row \(row)")
                                .fontWeight(.semibold)
                                .padding()
                            Spacer()
                        }
                    }
                }
            }
            .navigationTitle("iOS Example")
        }
    }

    func addNewRow(completion: @escaping () -> Void) {
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            rows.append(rows.count + 1)
            completion()
        }
    }
}

Screenshots

Dark mode Light mode

Installation

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but BBAlert does support its use on supported platforms.

Once you have your Swift package set up, adding BBAlert as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/bibinjacobpulickal/BBRefreshableScrollView", .upToNextMajor(from: "1.0.0"))
]

Example

Clone or download the project. Open .xcodeproj file in Xcode. Change target to iOSExample and run on a device or simulator.

License

BBAlert is released under the MIT license. See LICENSE for details.

About

A simple implementation of the very commonly used (yet surprisingly unavailable in SwiftUI framework) UIScrollView's pull to refresh functionality implemented natively in SwiftUI without using UIViewRepresentable.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%