-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathScrollContentView.swift
More file actions
82 lines (76 loc) · 3.29 KB
/
ScrollContentView.swift
File metadata and controls
82 lines (76 loc) · 3.29 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import Lottie
import PullToRefreshSwiftUI
import SwiftUI
struct ScrollContentView: View {
private enum AnimationType {
case native
case progressView
case lottie
}
@State private var isRefreshing: Bool = false
@State private var animationType: AnimationType = .native
var body: some View {
PullToRefreshScrollView(
options: PullToRefreshScrollViewOptions(pullToRefreshAnimationHeight: 100,
animationDuration: 0.3,
animatePullingViewPresentation: true,
animateRefreshingViewPresentation: true),
isRefreshing: $isRefreshing,
onRefresh: {
debugPrint("Refreshing")
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.seconds(5), execute: {
isRefreshing = false
})
},
animationViewBuilder: { (state) in
switch state {
case .idle:
Color.clear
case .pulling(let progress):
switch animationType {
case .native:
CircleAnimationWithProgressView(progress: progress)
case .progressView:
CircularProgressView(progress: progress)
case .lottie:
LottieView(animation: .named("animation-pulling-shakuro_logo"))
.playbackMode(.paused(at: .progress(progress)))
}
case .refreshing:
switch animationType {
case .native:
CircleAnimationWithRepeatView()
case .progressView:
ProgressView()
.progressViewStyle(.circular)
case .lottie:
LottieView(animation: .named("animation-refreshing-shakuro_logo"))
.playbackMode(.playing(.fromProgress(0, toProgress: 1, loopMode: .loop)))
}
}
},
contentViewBuilder: { _ in
VStack(spacing: 16, content: {
Text(isRefreshing ? "Refreshing" : "Idle")
.font(.largeTitle)
.foregroundStyle(isRefreshing ? .white : .black)
Picker("Current animation type", selection: $animationType) {
Text("Native").tag(AnimationType.native)
Text("ProgressView").tag(AnimationType.progressView)
Text("Lottie").tag(AnimationType.lottie)
}
.pickerStyle(.segmented)
Color.clear
})
.padding(EdgeInsets(top: 16, leading: 16, bottom: 16, trailing: 16))
.background(Color(isRefreshing ? .darkGray : .lightGray))
.animation(.linear(duration: 0.3), value: isRefreshing)
.frame(height: 1000)
})
.navigationTitle("Scroll View Example")
.navigationBarTitleDisplayMode(.inline)
}
}
#Preview {
ScrollContentView()
}