-
Notifications
You must be signed in to change notification settings - Fork 1
/
SwiftUIFreshControl.swift
64 lines (56 loc) · 1.65 KB
/
SwiftUIFreshControl.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// SwiftUIFreshControl.swift
// FreshScrollView
//
// Created by WeIHa'S on 2021/12/8.
//
import SwiftUI
public struct FreshScrollView<Content>: View where Content : View{
private let content: () -> Content
private let action: () -> Void
init(@ViewBuilder content: @escaping () -> Content, action: @escaping ()-> Void){
self.content = content
self.action = action
}
@State var startY: Double = 10000
public var body: some View{
ScrollView{
GeometryReader{ geometry in
HStack {
Spacer()
if geometry.frame(in: .global) .minY - startY > 30{
ProgressView()
.padding(.top, -30)
.animation(.easeInOut)
.transition(.move(edge: .top))
.onAppear{
let noti = UIImpactFeedbackGenerator(style: .light)
noti.prepare()
noti.impactOccurred()
action()
}
}
Spacer()
}
.onAppear {
startY = geometry.frame(in:.global).minY
}
}
content()
}
}
}
#if DEBUG
struct FreshScrollView_Previews: PreviewProvider {
static var previews: some View {
FreshScrollView {
Text("A")
Text("B")
Text("C")
Text("D")
} action: {
print("text")
}
}
}
#endif