아래로 당기면 refresh 되도록 하는 방법
struct PullToRefresh: View {
@State private var items = AppleProduct.sampleList[0 ..< 2]
@State private var index = 2
var body: some View {
List(items) { item in
Text(item.name)
}
.refreshable {
await refresh()
}
}
private func refresh() async {
do {
try await Task.sleep(nanoseconds: 1_000_000_000 * 2)
} catch {
}
guard index < AppleProduct.sampleList.count - 1 else { return }
items.append(AppleProduct.sampleList[index])
index += 1
}
}
기본(애니메이션 X)
애니메이션 O (easeInOut)
var body: some View {
List(items) { item in
Text(item.name)
}
.animation(.easeInOut, value: items)
.refreshable {
await refresh()
}
}