Skip to content

Commit

Permalink
Merge pull request #22 from KetanChopda/master
Browse files Browse the repository at this point in the history
- Completion type none and back to defaults completion block not called issue fixed.
- On back to defaults, not back to initial width issue fixed.
  • Loading branch information
simform-solutions authored Dec 21, 2018
2 parents d6c251a + 5270639 commit af90257
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions SSSpinnerButton/SSSpinnerButton/SpinnerButton/SSSpinnerButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ open class SSSpinnerButton: UIButton {

fileprivate var spinnerType: SpinnerType = .ballClipRotate

fileprivate var storedWidth: CGFloat?
fileprivate var storedHeight: CGFloat?

/// Sets the button corner radius
@IBInspectable var cornrRadius: CGFloat = 0 {
willSet {
Expand Down Expand Up @@ -314,6 +317,8 @@ private extension SSSpinnerButton {
storedHighlightedImage = self.image(for: .highlighted)

storedBackgroundColor = self.backgroundColor
storedWidth = frame.width
storedHeight = frame.height

self.setImage(nil, for: .normal)
self.setImage(nil, for: .disabled)
Expand Down Expand Up @@ -358,7 +363,7 @@ private extension SSSpinnerButton {
switch completionType {
case .none:
self.setDefaultDataToButton(complete: complete)
break
return
case .success:
let animation: SSSpinnerAnimationDelegate = SpinnerCompletionType.checkMark.animation()
animation.setupSpinnerAnimation(layer: self.layer, frame: self.frame, color: self.spinnerColor, spinnerSize: self.spinnerSize)
Expand All @@ -370,16 +375,21 @@ private extension SSSpinnerButton {
animation.setupSpinnerAnimation(layer: self.layer, frame: self.frame, color: self.spinnerColor, spinnerSize: self.spinnerSize)
}

if setToDefaults {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.setDefaultDataToButton(complete: complete)
if completionType != .none {
if setToDefaults {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.setDefaultDataToButton(complete: complete)
self.isUserInteractionEnabled = true
}
} else {

if complete != nil {
complete!()
}
self.isUserInteractionEnabled = true
}
} else {
self.isUserInteractionEnabled = true
}


self.isUserInteractionEnabled = true
}

/// set default state
Expand Down Expand Up @@ -421,8 +431,8 @@ private extension SSSpinnerButton {
self.isUserInteractionEnabled = true

let animation = CABasicAnimation(keyPath: "bounds.size.width")
animation.fromValue = self.frame.height
animation.toValue = self.frame.width
animation.fromValue = storedHeight
animation.toValue = storedWidth
animation.duration = self.animationDuration
animation.fillMode = CAMediaTimingFillMode.forwards
animation.isRemovedOnCompletion = false
Expand Down

0 comments on commit af90257

Please sign in to comment.