From b58e1cdbb5e9a6f34f8c31d47e97078f8a7c6530 Mon Sep 17 00:00:00 2001 From: Ivan Cheung Date: Wed, 29 Sep 2021 10:58:46 -0400 Subject: [PATCH] Added delay parameter Added delay parameter to control delay between shimmers. --- Sources/Shimmer/Shimmer.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/Shimmer/Shimmer.swift b/Sources/Shimmer/Shimmer.swift index b2d7e88..8ce0b33 100644 --- a/Sources/Shimmer/Shimmer.swift +++ b/Sources/Shimmer/Shimmer.swift @@ -10,13 +10,15 @@ import SwiftUI /// an operation is in progress. public struct Shimmer: ViewModifier { @State private var phase: CGFloat = 0 - var duration = 1.5 - var bounce = false + var duration: Double = 1.5 + var delay: Double = 0 + var bounce: Bool = false public func body(content: Content) -> some View { content .modifier(AnimatedMask(phase: phase).animation( Animation.linear(duration: duration) + .delay(delay) .repeatForever(autoreverses: bounce) )) .onAppear { phase = 0.8 } @@ -63,10 +65,10 @@ public extension View { /// - duration: The duration of a shimmer cycle in seconds. Default: `1.5`. /// - bounce: Whether to bounce (reverse) the animation back and forth. Defaults to `false`. @ViewBuilder func shimmering( - active: Bool = true, duration: Double = 1.5, bounce: Bool = false + active: Bool = true, duration: Double = 1.5, delay: Double = 0, bounce: Bool = false ) -> some View { if active { - modifier(Shimmer(duration: duration, bounce: bounce)) + modifier(Shimmer(duration: duration, delay: delay, bounce: bounce)) } else { self }