Skip to content

Commit

Permalink
Fix: UILabel placeholder animations doesn't work in ProfileViewContro…
Browse files Browse the repository at this point in the history
…ller (#241)

* Account icon should come from local

* Fix the issue where label animations get interrupted easily
  • Loading branch information
pinarol authored May 3, 2024
1 parent 2609db7 commit a131bfb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ProfilePlaceholderActivityIndicator: ProfileActivityIndicator {
guard placeholderDisplayer.isShowing else { return }
shouldStopAnimating = false
self.placeholderDisplayer.elements?.forEach { element in
element.prepareForAnimation()
element.animationWillBegin()
}
doLoadingAnimation(index: 0, animatingColors: baseView.placeholderColors.loadingAnimationColors)
}
Expand All @@ -31,6 +31,7 @@ class ProfilePlaceholderActivityIndicator: ProfileActivityIndicator {
animator?.stopAnimation(true)
}
self.placeholderDisplayer.elements?.forEach { element in
element.animationDidEnd()
if placeholderDisplayer.isShowing {
element.refreshColor()
} else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/GravatarUI/ProfileView/BaseProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ open class BaseProfileView: UIView, UIContentView {
}

func createAccountIconView(model: AccountModel) -> UIView {
let button: UIControl = if UIImage(named: model.shortname) != nil {
let button: UIControl = if UIImage(localName: model.shortname) != nil {
createAccountButton(model: model)
} else if let iconURL = model.iconURL { // If we have the iconURL try downloading the icon
createRemoteSVGButton(url: iconURL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ class AccountButtonsPlaceholderDisplayer: PlaceholderDisplaying {
}
}

func prepareForAnimation() {}
func animationWillBegin() {}
func animationDidEnd() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ class BackgroundColorPlaceholderDisplayer<T: UIView>: PlaceholderDisplaying {
baseView.layer.backgroundColor = newColor?.cgColor
}

func prepareForAnimation() {}
func animationWillBegin() {}
func animationDidEnd() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,23 @@ import UIKit
/// A ``PlaceholderDisplaying`` implementation for a UILabel.
@MainActor
class LabelPlaceholderDisplayer: RectangularPlaceholderDisplayer<UILabel> {
override func prepareForAnimation() {
var isAnimating: Bool = false

override func animationDidEnd() {
isAnimating = false
}

override func animationWillBegin() {
// If UILabel's backgroundColor is set, the animation won't be visible. So we need to clear it. This is only needed for UILabel so far.
set(viewColor: .clear)
isAnimating = true
}

override func set(viewColor newColor: UIColor?) {
if !isAnimating {
// If UILabel's backgroundColor is set, the animation won't be visible.
// So prevent setting it if there's an animation in progress.
super.set(viewColor: newColor)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public protocol PlaceholderDisplaying {
func set(layerColor newColor: UIColor?)
/// Sets the `backgroundColor` of the underlying view element.
func set(viewColor newColor: UIColor?)
/// Prepares for color animations.
func prepareForAnimation()
/// Informs the element before the animations begin.
func animationWillBegin()
/// Informs the element after the animations end.
func animationDidEnd()
/// Refreshes the color. `backgroundColor` is set to `placeholderColor` and`layer.backgroundColor` to nil.
func refreshColor()
}
Expand Down

0 comments on commit a131bfb

Please sign in to comment.