Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions Sources/SPConfetti/SPConfetti.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Comment thread
krishbee marked this conversation as resolved.
- 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 }
Expand All @@ -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()
}
Expand All @@ -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`.
Comment thread
krishbee marked this conversation as resolved.
- 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()
})
Expand Down
4 changes: 3 additions & 1 deletion Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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<Bool>, animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval?) -> some View {
self.background(
ConfettiPlaceholderView(isPresented: isPresented, animation: animation, particles: particles, duration: duration)
Expand Down