Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added delay parameter #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Sources/Shimmer/Shimmer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
}
Expand Down