Refreshable

0.2.0

Pull to refresh, refreshable based on SwiftUI
c-villain/Refreshable

What's New

0.2.0

2022-12-20T18:01:39Z

Add ScrollDistance to control responsiveness for refreshable during scrolling

import Refreshable

struct Constants {
    public static let isPad: Bool = UIDevice.current.userInterfaceIdiom == .pad
}

struct YourView: View {
    
    var body: some View {
        ScrollView {
            RefreshControl(Constants.isPad ? .long : .short, // <= HERE
                           coordinateSpace: .named("List")) { 
                // do your work on refresh here
            }
            
            LazyVStack {
                ...
            }
        }
        .coordinateSpace(name: "List")
    }
}

Refreshable

Library for marking any SwiftUI view as refreshable, similar to Apple's refreshable(action:) that available from iOS 15 and only in List 🤷🏼‍♂️.

You can use Refreshable with any view (e.g. LazyVStack).

👨🏻‍💻 Feel free to subscribe to channel SwiftUI dev in telegram.

Requirements

Basically there is no any restriction to add this package to your project with minimum developments below iOS 14.

But you can use Refreshable with views starting with iOS 14.

Use @available(iOS 14.0, *) or if #available(iOS 14, *) for this one.

Installation

Swift Package Manager

To integrate Refreshable into your project using SwiftPM add the following to your Package.swift:

dependencies: [
    .package(url: "https://github.com/c-villain/Refreshable", from: "0.1.0"),
],

or via XcodeGen insert into your project.yml:

name: YourProjectName
options:
  deploymentTarget:
    iOS: 12.0
packages:
  Refreshable:
    url: https://github.com/c-villain/Refreshable
    from: 0.1.0
targets:
  YourTarget:
    type: application
    ...
    dependencies:
       - package: Refreshable

Quick start

Basically there are two ways to mark your view as Refreshable.

The easiest one is to add modifier refreshable to your view.
import Refreshable

struct YourView: View {
    
    var body: some View {
        ScrollView {
            LazyVStack {
                ...
            }
            .refreshable {
                // do your work on refresh here
            }
        }
    }
}
Second one is to add manually RefreshControl to your view implementation. Don't forget to name your view’s coordinate space!
import Refreshable

struct YourView: View {
    
    var body: some View {
        ScrollView {
            RefreshControl(coordinateSpace: .named("List")) { // <= HERE
                // do your work on refresh here
            }
            
            LazyVStack {
                ...
            }
        }
        .coordinateSpace(name: "List") // <= DON'T FORGET
    }
}
To control responsiveness for refreshable during scrolling use ScrollDistance. Or use defaults 😊.
import Refreshable

struct Constants {
    public static let isPad: Bool = UIDevice.current.userInterfaceIdiom == .pad
}

struct YourView: View {
    
    var body: some View {
        ScrollView {
            RefreshControl(Constants.isPad ? .long : .short, // <= HERE
                           coordinateSpace: .named("List")) { 
                // do your work on refresh here
            }
            
            LazyVStack {
                ...
            }
        }
        .coordinateSpace(name: "List")
    }
}

Communication

  • If you found a bug, open an issue or submit a fix via a pull request.
  • If you have a feature request, open an issue or submit a implementation via a pull request or hit me up on lexkraev@gmail.com or telegram.
  • If you want to contribute, submit a pull request onto the master branch.

License

Refreshable package is released under an MIT license.

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Jun 30 2024 13:22:37 GMT-0900 (Hawaii-Aleutian Daylight Time)