拉动刷新,可基于SwiftUI刷新
可刷新
用于将任何 SwiftUI 视图标记为可刷新的库,类似于 Apple 的可刷新(action:),
该库可从 iOS 15 使用,并且仅在列表中🤷🏼 ♂️可用。
您可以与任何视图一起使用(例如LazyVStack)。Refreshable
👨🏻 💻 随意订阅频道 SwiftUI 开发 在电报中。
要求
基本上,将此软件包添加到您的项目中没有任何限制,iOS 14 以下的开发最少。
但是,您可以从iOS 14开始使用视图。Refreshable
使用或用于这个。@available(iOS 14.0, *)
if #available(iOS 14, *)
安装
Swift Package Manager
要使用 SwiftPM 将 Refreshable 集成到您的项目中,请将以下内容添加到您的 :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
}
}
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.