Skip to content

Commit

Permalink
Merge pull request #11 from rohit9934/rohit9934/fix7
Browse files Browse the repository at this point in the history
Added feature to let user change animation speed
  • Loading branch information
omerfarukozturk authored Apr 4, 2023
2 parents 872dc21 + 5789453 commit fa6f06f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ extension UIView {
public func setTemplateWithSubviews(_ template: Bool,
color: UIColor? = nil,
animate: Bool = true,
viewBackgroundColor: UIColor? = nil) {
viewBackgroundColor: UIColor? = nil,
animationSpeed: CGFloat = 1.25) {
allTemplateViews.forEach {
$0.setTemplate(template, baseColor: color)
if animate {
$0.setShimmeringAnimation(template, viewBackgroundColor: viewBackgroundColor)
$0.setShimmeringAnimation(template, viewBackgroundColor: viewBackgroundColor,
animationSpeed: animationSpeed)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension UIView {
/// - Parameters:
/// - animate: Specifies the animation is on/off.
/// - viewBackgroundColor: The `backgroudColor` of specified views superview.
func setShimmeringAnimation(_ animate: Bool, viewBackgroundColor: UIColor? = nil) {
func setShimmeringAnimation(_ animate: Bool, viewBackgroundColor: UIColor? = nil, animationSpeed: CGFloat) {
let currentShimmerLayer = layer.sublayers?.first(where: { $0.name == Key.shimmer })
if animate {
if currentShimmerLayer != nil { return }
Expand Down Expand Up @@ -47,7 +47,7 @@ extension UIView {
animation.fromValue = [-1.0, -0.5, 0.0]
animation.toValue = [1.0, 1.5, 2.0]
animation.repeatCount = .infinity
animation.duration = 1.25
animation.duration = animationSpeed
gradientLayer.add(animation, forKey: animation.keyPath)
}
}

0 comments on commit fa6f06f

Please sign in to comment.