Skip to content

Commit

Permalink
style: lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
O-labib committed May 24, 2021
1 parent 3150660 commit 92e322c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
19 changes: 16 additions & 3 deletions SpinningButton/Classes/Behaviors/BaseBehavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
}
17 changes: 9 additions & 8 deletions SpinningButton/Classes/Behaviors/CentreLoadingBehavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 21 additions & 4 deletions SpinningButton/Classes/Behaviors/EdgeLoadingBehavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
}
}

Expand Down

0 comments on commit 92e322c

Please sign in to comment.