Skip to content

Commit

Permalink
Merge pull request #10 from aakashsrivastav/master
Browse files Browse the repository at this point in the history
Resolves button image visibility issue during animation
  • Loading branch information
twho authored Mar 19, 2021
2 parents dd9cfc8 + 0627a87 commit 740199b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions LoadingButtons/LoadingButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ open class LoadingButton: UIButton {
case outline
}
// Private properties
private var imageAlpha: CGFloat = 1.0
private var loaderWorkItem: DispatchWorkItem?
// Init
public override init(frame: CGRect) {
Expand Down Expand Up @@ -198,8 +199,11 @@ open class LoadingButton: UIButton {
loaderWorkItem = DispatchWorkItem { [weak self] in
guard let self = self, let item = self.loaderWorkItem, !item.isCancelled else { return }
UIView.transition(with: self, duration: 0.2, options: .curveEaseOut, animations: {
viewsToBeHidden.forEach {
$0?.alpha = 0.0
viewsToBeHidden.forEach { view in
if view == self.imageView {
self.imageAlpha = 0.0
}
view?.alpha = 0.0
}
self.indicator.alpha = 1.0
}) { _ in
Expand Down Expand Up @@ -233,6 +237,7 @@ open class LoadingButton: UIButton {
UIView.transition(with: self, duration: 0.2, options: .curveEaseIn, animations: {
self.titleLabel?.alpha = 1.0
self.imageView?.alpha = 1.0
self.imageAlpha = 1.0
}) { _ in
guard !item.isCancelled else { return }
completion?()
Expand All @@ -251,6 +256,9 @@ open class LoadingButton: UIButton {
// layoutSubviews
open override func layoutSubviews() {
super.layoutSubviews()
if let imageView = imageView {
imageView.alpha = imageAlpha
}
indicator.center = CGPoint(x: self.frame.size.width/2, y: self.frame.size.height/2)
}
// MARK: Touch
Expand Down

0 comments on commit 740199b

Please sign in to comment.