From 92e322c07b77b217d44bdb3fe70c49f781029c5f Mon Sep 17 00:00:00 2001 From: OmarLabib Date: Mon, 24 May 2021 16:58:46 +0200 Subject: [PATCH] style: lint code --- .../Classes/Behaviors/BaseBehavior.swift | 19 +++++++++++--- .../Behaviors/CentreLoadingBehavior.swift | 17 +++++++------ .../Behaviors/EdgeLoadingBehavior.swift | 25 ++++++++++++++++--- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/SpinningButton/Classes/Behaviors/BaseBehavior.swift b/SpinningButton/Classes/Behaviors/BaseBehavior.swift index 50aa760..51505d0 100644 --- a/SpinningButton/Classes/Behaviors/BaseBehavior.swift +++ b/SpinningButton/Classes/Behaviors/BaseBehavior.swift @@ -31,11 +31,24 @@ extension BaseBehavior { static func create(for position: LoaderPosition, onButton button: SpinningButton) -> BaseBehavior { switch position { case .centre(let shrink): - return CentreLoadingBehavior(button: button, shrinkOnLoading: shrink) + return CentreLoadingBehavior( + button: button, + shrinkOnLoading: shrink + ) case .leading(let offset, let titleWhileLoading): - return EdgeLoadingBehavior(button: button, offset: offset, isTrailing: false, titleWhileLoading: titleWhileLoading) + return EdgeLoadingBehavior( + button: button, + offset: offset, + isTrailing: false, + titleWhileLoading: titleWhileLoading + ) case .trailing(let offset, let titleWhileLoading): - return EdgeLoadingBehavior(button: button, offset: offset, isTrailing: true, titleWhileLoading: titleWhileLoading) + return EdgeLoadingBehavior( + button: button, + offset: offset, + isTrailing: true, + titleWhileLoading: titleWhileLoading + ) } } } diff --git a/SpinningButton/Classes/Behaviors/CentreLoadingBehavior.swift b/SpinningButton/Classes/Behaviors/CentreLoadingBehavior.swift index ec5d52b..a1e4f13 100644 --- a/SpinningButton/Classes/Behaviors/CentreLoadingBehavior.swift +++ b/SpinningButton/Classes/Behaviors/CentreLoadingBehavior.swift @@ -54,14 +54,15 @@ class CentreLoadingBehavior: BaseBehavior { fullyShrunk = false button?.loadingSpinner.transform = CGAffineTransform(scaleX: 0, y: 0) - UIView.animate(withDuration: 0.3, - delay: 0, - usingSpringWithDamping: 0.45, - initialSpringVelocity: 0, - options: .curveEaseInOut, - animations: { - self.button?.loadingSpinner.transform = CGAffineTransform(scaleX: 1, y: 1) - }) { _ in + UIView.animate( + withDuration: 0.3, + delay: 0, + usingSpringWithDamping: 0.45, + initialSpringVelocity: 0, + options: .curveEaseInOut, + animations: { + self.button?.loadingSpinner.transform = CGAffineTransform(scaleX: 1, y: 1) + }) { _ in self.button?.loadingSpinner.startAnimating() self.animationCompleted = true if self.shouldShrinkOnLoading { diff --git a/SpinningButton/Classes/Behaviors/EdgeLoadingBehavior.swift b/SpinningButton/Classes/Behaviors/EdgeLoadingBehavior.swift index 6c420eb..454a473 100644 --- a/SpinningButton/Classes/Behaviors/EdgeLoadingBehavior.swift +++ b/SpinningButton/Classes/Behaviors/EdgeLoadingBehavior.swift @@ -17,7 +17,12 @@ class EdgeLoadingBehavior: BaseBehavior { private var cachedTitle: String? private var animationCompleted = false - init(button: SpinningButton, offset: CGFloat = 4.0, isTrailing: Bool, titleWhileLoading: String? ) { + init( + button: SpinningButton, + offset: CGFloat = 4.0, + isTrailing: Bool, + titleWhileLoading: String? + ) { self.offset = offset self.isTrailing = isTrailing self.titleWhileLoading = titleWhileLoading @@ -28,7 +33,13 @@ class EdgeLoadingBehavior: BaseBehavior { override func startAnimating() { animationCompleted = false guard let button = button else {return} - UIView.animate(withDuration: 0.3, delay: 0.05, usingSpringWithDamping: 0.45, initialSpringVelocity: 0, options: .curveEaseInOut, animations: { + UIView.animate( + withDuration: 0.3, + delay: 0.05, + usingSpringWithDamping: 0.45, + initialSpringVelocity: 0, + options: .curveEaseInOut, + animations: { button.loadingSpinner.transform = CGAffineTransform(scaleX: 1, y: 1) }) { _ in button.loadingSpinner.startAnimating() @@ -47,9 +58,15 @@ class EdgeLoadingBehavior: BaseBehavior { button.addSubview(button.loadingSpinner) button.loadingSpinner.centerYAnchor.constraint(equalTo: button.centerYAnchor).isActive = true if isTrailing { - button.loadingSpinner.trailingAnchor.constraint(equalTo: button.trailingAnchor, constant: -offset).isActive = true + button.loadingSpinner.trailingAnchor.constraint( + equalTo: button.trailingAnchor, + constant: -offset + ).isActive = true } else { - button.loadingSpinner.leadingAnchor.constraint(equalTo: button.leadingAnchor, constant: offset).isActive = true + button.loadingSpinner.leadingAnchor.constraint( + equalTo: button.leadingAnchor, + constant: offset + ).isActive = true } }