diff --git a/Sources/SPConfetti/SPConfetti.swift b/Sources/SPConfetti/SPConfetti.swift index c6dedc1..9c4dee0 100644 --- a/Sources/SPConfetti/SPConfetti.swift +++ b/Sources/SPConfetti/SPConfetti.swift @@ -40,9 +40,10 @@ public class SPConfetti { - parameter animation: Kind of animation, position and direction of particles. - parameter particles: Particles style. Can be custom image. - parameter window: The targe window. Use key window if `nil`. + - parameter particlesConfig: The configuration for the particles, colors, velocity, spin, etc. */ @available(iOSApplicationExtension, unavailable) - public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], in window: UIWindow? = nil) { + public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], particlesConfig: SPConfettiParticlesConfig, in window: UIWindow? = nil) { shared.view.animation = animation shared.view.particles = particles let keyWindow = UIApplication.shared.windows.first { $0.isKeyWindow } @@ -53,6 +54,7 @@ public class SPConfetti { window.addSubview(shared.view) } shared.view.frame = window.bounds + shared.view.particlesConfig = particlesConfig shared.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] shared.view.startAnimating() } @@ -64,10 +66,11 @@ public class SPConfetti { - parameter particles: Particles style. Can be custom image. - parameter duration: Automatically stop animation after this time interval. - parameter window: The targe window. Use key window if `nil`. + - parameter particlesConfig: The configuration for the particles, colors, velocity, spin, etc. */ @available(iOSApplicationExtension, unavailable) - public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval, in window: UIWindow? = nil) { - startAnimating(animation, particles: particles, in: window) + public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval, particlesConfig: SPConfettiParticlesConfig, in window: UIWindow? = nil) { + startAnimating(animation, particles: particles, particlesConfig: particlesConfig, in: window) delay(duration, closure: { stopAnimating() }) diff --git a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift index 90f476b..99d2eaf 100644 --- a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift +++ b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift @@ -84,14 +84,15 @@ struct ConfettiPlaceholderView: UIViewRepresentable { SPConfetti.startAnimating(animation, particles: particles, duration: duration, + particlesConfig: particleConfig, in: self.window) - delay(duration) { [weak self] in self?.stop() } } else { SPConfetti.startAnimating(animation, particles: particles, + particlesConfig: particleConfig, in: self.window) } } @@ -129,6 +130,7 @@ extension View { - parameter particles: Particles style. Can be custom image. - parameter duration: Automatically stop animation after this time interval. */ + public func confetti(isPresented: Binding, animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval?) -> some View { self.background( ConfettiPlaceholderView(isPresented: isPresented, animation: animation, particles: particles, duration: duration)