Skip to content

Commit 3b12bc3

Browse files
UNT-T11872 Bug fixes
1 parent 8cf11b3 commit 3b12bc3

File tree

7 files changed

+72
-47
lines changed

7 files changed

+72
-47
lines changed

SSSwiftUIAnimations/SSSwiftUIAnimations.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
B19E0B662BF7498700E65974 /* ExampleProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B19E0B652BF7498700E65974 /* ExampleProgressView.swift */; };
2222
B1DFCA512BF4FA3D00F01505 /* ProgressCircle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DFCA502BF4FA3D00F01505 /* ProgressCircle.swift */; };
2323
B1DFCA532BF4FC7900F01505 /* ArrowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DFCA522BF4FC7900F01505 /* ArrowView.swift */; };
24+
B1FE861E2BFF6BC000FB111C /* ViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1FE861D2BFF6BC000FB111C /* ViewExtension.swift */; };
2425
/* End PBXBuildFile section */
2526

2627
/* Begin PBXFileReference section */
@@ -39,6 +40,7 @@
3940
B19E0B652BF7498700E65974 /* ExampleProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleProgressView.swift; sourceTree = "<group>"; };
4041
B1DFCA502BF4FA3D00F01505 /* ProgressCircle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressCircle.swift; sourceTree = "<group>"; };
4142
B1DFCA522BF4FC7900F01505 /* ArrowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrowView.swift; sourceTree = "<group>"; };
43+
B1FE861D2BFF6BC000FB111C /* ViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewExtension.swift; sourceTree = "<group>"; };
4244
/* End PBXFileReference section */
4345

4446
/* Begin PBXFrameworksBuildPhase section */
@@ -99,6 +101,7 @@
99101
B1098E7C2BD94ED900BC19DD /* WaveView.swift */,
100102
B11B98392BCE9C3F00D76016 /* CheckView.swift */,
101103
B177713E2BF39A60001723EC /* ModelClass.swift */,
104+
B1FE861D2BFF6BC000FB111C /* ViewExtension.swift */,
102105
);
103106
path = ProgressAnimation;
104107
sourceTree = "<group>";
@@ -203,6 +206,7 @@
203206
B11B983A2BCE9C3F00D76016 /* CheckView.swift in Sources */,
204207
B1DFCA512BF4FA3D00F01505 /* ProgressCircle.swift in Sources */,
205208
B14AB36C2BC41B05004B09C4 /* ProgressView.swift in Sources */,
209+
B1FE861E2BFF6BC000FB111C /* ViewExtension.swift in Sources */,
206210
);
207211
runOnlyForDeploymentPostprocessing = 0;
208212
};

SSSwiftUIAnimations/SSSwiftUIAnimations/ProgressAnimation/ArrowView.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@ struct Arrow: View {
1414
var style: SSProgressViewStyle
1515
@Binding var progress: Float
1616
@Binding var bounceEffect: CGFloat
17+
@State var verticalLine = true
1718

1819
var body: some View {
1920
VStack(spacing: 0) {
2021

2122
// Vertical line of arrow
22-
RoundedRectangle(cornerRadius: style.circleStrokeWidth/2)
23-
.frame(
24-
width: arrowStyle.isAnimating ? style.circleStrokeWidth : style.arrowStrokeWidth + 1,
25-
height: arrowStyle.isAnimating ? (!arrowStyle.animationStarted ? style.circleStrokeWidth : style.circleStrokeWidth ) : style.circleSize * 0.40
26-
)
27-
.opacity(arrowStyle.showVerticalLine ? 1 : 0)
28-
.foregroundColor(style.arrowColor)
29-
.offset(y: arrowStyle.isAnimating ? (!arrowStyle.animationStarted ? -10 : -(style.circleSize/2)) : 0)
30-
.animation(Animation.linear.speed(!arrowStyle.animationStarted ? 100 : .zero), value: 0)
23+
RoundedRectangle(cornerRadius: style.circleStrokeWidth/2)
24+
.frame(
25+
width: arrowStyle.isAnimating ? style.circleStrokeWidth : style.arrowStrokeWidth + 1,
26+
height: arrowStyle.isAnimating ? (!arrowStyle.animationStarted ? style.circleStrokeWidth : style.circleStrokeWidth ) : style.circleSize * 0.40
27+
).opacity((progress >= 0.001) ? 0 : 1)
28+
.foregroundColor(arrowStyle.isAnimating ? style.fillStrokeColor : style.arrowColor)
29+
.offset(y: arrowStyle.isAnimating ? (!arrowStyle.animationStarted ? -10 : -(style.circleSize/2)) : 0)
3130

32-
if progress < 0.1 {
33-
31+
if progress <= 0.0 {
32+
3433
// if progress is less than 0.1 then showing down arrow animation
3534
DownArrow(
3635
initialAnim: arrowStyle.initialAnim,
@@ -45,7 +44,7 @@ struct Arrow: View {
4544
.offset(y: arrowStyle.isAnimating ? 22 : .zero)
4645
.foregroundColor(style.arrowColor)
4746
.scaleEffect(CGSize(width: 1, height: arrowStyle.isAnimating ? 1 : style.circleSize * 0.005))
48-
} else if progress >= 0.1 && progress < 1.0 {
47+
} else if progress > 0.0 && progress < 1.0 {
4948

5049
// if progress is between >= 0.1 and < 1.0 starting wave animation
5150
WaveView(

SSSwiftUIAnimations/SSSwiftUIAnimations/ProgressAnimation/CheckView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct CheckView: View {
3333
x: isAnimating ? 0.3 : x,
3434
y: isAnimating ? 4.5 : y),
3535
height: size,
36-
stright: straight)
36+
straight: straight)
3737
.stroke(style: StrokeStyle(lineWidth: isAnimating ? arrowStrokeWidth / (size * 0.01) : arrowStrokeWidth, lineCap: .round))
3838
.frame(width: width * 0.57, height: 105)
3939
.offset(CGSize(width: 0, height: isAnimating ? offset : 0))
@@ -68,7 +68,7 @@ struct Check: Shape {
6868
// MARK: - Variables
6969
var endPoint: CGPoint
7070
var height: CGFloat
71-
var stright: CGFloat
71+
var straight: CGFloat
7272

7373
// MARK: - Animatable data
7474
var animatableData: AnimatablePair<CGFloat, CGFloat> {
@@ -91,7 +91,7 @@ struct Check: Shape {
9191
)
9292
let start2 = CGPoint(
9393
x: rect.maxX/rightLine,
94-
y: rect.midY - 21 * endPoint.x - stright
94+
y: rect.midY - 21 * endPoint.x - straight
9595
)
9696
var path = Path()
9797
path.move(to: start)

SSSwiftUIAnimations/SSSwiftUIAnimations/ProgressAnimation/ModelClass.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ struct SSProgressViewStyle {
3636
self.circleSize = max(circleSize, 100)
3737

3838
// Circle stroke width
39-
self.circleStrokeWidth = circleStrokeWidth
39+
self.circleStrokeWidth = max(circleStrokeWidth, 1)
4040

4141
// Arrow stroke width
42-
self.arrowStrokeWidth = arrowStrokeWidth
42+
self.arrowStrokeWidth = max(arrowStrokeWidth, 1)
4343

4444
// Progress text font size
4545
self.fontSize = fontSize

SSSwiftUIAnimations/SSSwiftUIAnimations/ProgressAnimation/ProgressView.swift

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ struct SSProgressView: View {
2626
// Start/stop dot animation
2727
@State private var startDotAnim = false
2828

29-
// Hide show vertical arrow
30-
@State private var showVerticalLine = true
31-
3229
// Stating shape is down arrow or not
3330
@State private var isDownArrow = true
3431

@@ -61,30 +58,22 @@ struct SSProgressView: View {
6158
ZStack {
6259
// Progress Circle with animation
6360
ProgressCircle(progress: $progress, style: style)
64-
.animation(.linear, value: progress)
61+
.if(progress > 0.0) {
62+
$0.animation(.linear, value: progress)
63+
}
6564

6665
// Progress percentage text view
6766
ProgressText(showPercent: showPercent, progress: $progress, style: style)
6867

6968
// Arrow view parameters
70-
let arrowStyle = ArrowViewParams(isAnimating: isAnimating, progress: Double(progress), initialAnim: initialAnim, isDownward: isDownArrow, animationStarted: startDotAnim, showVerticalLine: showVerticalLine)
69+
let arrowStyle = ArrowViewParams(isAnimating: isAnimating, progress: Double(progress), initialAnim: initialAnim, isDownward: isDownArrow, animationStarted: startDotAnim)
7170

7271
// Arrow view
7372
Arrow(arrowStyle: arrowStyle, style: style, progress: $progress, bounceEffect: $bounceEffect)
7473
}.allowsHitTesting(canTap)
7574
.onTapGesture {
76-
if style.allowCancelProgress && !isReset {
77-
isStarted.toggle()
78-
if isStarted {
79-
// Cancel animation on clicking again
80-
resetProgress()
81-
onCancelProgress?()
82-
} else {
83-
startAnimation()
84-
}
85-
} else {
86-
isReset = false
87-
startAnimation()
75+
if canTap && !(progress > 1.0) {
76+
manageAnimation()
8877
}
8978
}
9079
}
@@ -122,6 +111,22 @@ struct SSProgressView: View {
122111
}
123112
}
124113

114+
private func manageAnimation() {
115+
if style.allowCancelProgress && !isReset {
116+
isStarted.toggle()
117+
if isStarted {
118+
// Cancel animation on clicking again
119+
resetProgress()
120+
onCancelProgress?()
121+
} else {
122+
startAnimation()
123+
}
124+
} else {
125+
isReset = false
126+
startAnimation()
127+
}
128+
}
129+
125130
private func progressAnimation() {
126131
// Showing percentage text once initial animation is done
127132
initialTimer = Timer.scheduledTimer(withTimeInterval: 0.6, repeats: false) { timer in
@@ -131,14 +136,9 @@ struct SSProgressView: View {
131136
}
132137
}
133138

134-
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
139+
DispatchQueue.main.asyncAfter(deadline: .now()) {
135140
endTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { timer in
136141

137-
// Hiding dot once progress starts
138-
if progress > 0.0 {
139-
showVerticalLine = false
140-
}
141-
142142
// Reset progress after progress is completed
143143
if progress >= 1.0 {
144144
timer.invalidate()
@@ -149,7 +149,7 @@ struct SSProgressView: View {
149149
}
150150

151151
// Reset progress with animation
152-
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
152+
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
153153
withAnimation {
154154
resetProgress()
155155
isReset = true
@@ -199,7 +199,6 @@ struct SSProgressView: View {
199199
isDownArrow = true
200200
bounceEffect = 1.0
201201
startDotAnim = false
202-
showVerticalLine = true
203202
showPercent = false
204203
}
205204
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// ViewExtension.swift
3+
// SSSwiftUIAnimations
4+
//
5+
// Created by Mansi Prajapati on 23/05/24.
6+
//
7+
8+
import SwiftUI
9+
10+
// For using property based on condition
11+
extension View {
12+
@ViewBuilder
13+
func `if`<Transform: View>(
14+
_ condition: Bool,
15+
transform: (Self) -> Transform
16+
) -> some View {
17+
if condition {
18+
transform(self)
19+
} else {
20+
self
21+
}
22+
}
23+
}

SSSwiftUIAnimations/SSSwiftUIAnimations/ProgressAnimation/WaveView.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ struct WaveView: View {
1919

2020
var body: some View {
2121
VStack(spacing: 0) {
22-
let progresss = 1.0 / CGFloat(5)
23-
let normedAmplitude = (1.5 * progresss - 0.8) * self.amplitude
22+
let waveProgress = 1.0 / CGFloat(5)
23+
let normedAmplitude = (1.5 * waveProgress - 0.8) * self.amplitude
2424

2525
Wave(
2626
phase: phase,
@@ -31,19 +31,19 @@ struct WaveView: View {
3131
.frame(width: width * 0.44, height: height)
3232
.onAppear {
3333
Timer.scheduledTimer(withTimeInterval: 0.3, repeats: true) { timer in
34-
if progress > 0.1 && progress < 0.90 {
34+
if progress >= 0.001 && progress < 0.92 {
3535
// Wave animation
3636
withAnimation( Animation.linear(duration: 2).repeatForever(autoreverses: false)) {
3737
self.amplitude = 0.8
3838
self.phase -= 6.0
3939
}
40-
} else if progress >= 0.90 && progress <= 0.95 {
40+
} else if progress >= 0.92 && progress < 0.99 {
4141
// Slowly transforming wave to straight line
4242
withAnimation(Animation.linear(duration: 2)) {
4343
self.amplitude = 0
4444
self.phase -= 0.3
4545
}
46-
} else if progress > 0.95 {
46+
} else if progress >= 0.99 {
4747
timer.invalidate()
4848
}
4949
}

0 commit comments

Comments
 (0)