Skip to content

Commit 8d20825

Browse files
committed
Fix stop animation with waiting flag
1 parent 4f573bc commit 8d20825

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

SpringIndicator/SpringIndicator.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ open class SpringIndicator: UIView {
5151
return rotateDuration / 2
5252
}
5353

54-
fileprivate var stopAnimationsHandler: ((SpringIndicator) -> Void)?
55-
5654
public override init(frame: CGRect) {
5755
indicatorView = UIView(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height))
5856
super.init(frame: frame)
@@ -240,8 +238,6 @@ open class SpringIndicator: UIView {
240238
public extension SpringIndicator {
241239
/// If start from a state in spread is True.
242240
public func startAnimation(_ expand: Bool = false) {
243-
stopAnimationsHandler = nil
244-
245241
if isSpinning() {
246242
return
247243
}
@@ -255,11 +251,15 @@ public extension SpringIndicator {
255251
/// true is wait for stroke animation.
256252
public func stopAnimation(_ waitAnimation: Bool, completion: ((SpringIndicator) -> Void)? = nil) {
257253
if waitAnimation {
258-
stopAnimationsHandler = { indicator in
259-
indicator.stopAnimation(false, completion: completion)
254+
if let layer = pathLayer?.presentation() {
255+
let time = Double(2 - layer.strokeStart - layer.strokeEnd)
256+
DispatchQueue.main.asyncAfter(deadline: .now() + time) {
257+
self.stopAnimation(false, completion: completion)
258+
}
259+
} else {
260+
stopAnimation(false, completion: completion)
260261
}
261262
} else {
262-
stopAnimationsHandler = nil
263263
indicatorView.layer.removeAllAnimations()
264264
pathLayer?.strokeEnd = 0
265265
pathLayer = nil

0 commit comments

Comments
 (0)