From e44558e45936ec66d5084899e7c11654b9b4be84 Mon Sep 17 00:00:00 2001 From: Kristoffer Frank Date: Tue, 2 Apr 2024 10:43:08 +0200 Subject: [PATCH 1/7] wip: fix color changing issue --- Sources/SPConfetti/Models/SPConfettiConfiguration.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/SPConfetti/Models/SPConfettiConfiguration.swift b/Sources/SPConfetti/Models/SPConfettiConfiguration.swift index 4060928..8dafac5 100644 --- a/Sources/SPConfetti/Models/SPConfettiConfiguration.swift +++ b/Sources/SPConfetti/Models/SPConfettiConfiguration.swift @@ -51,7 +51,7 @@ public class SPConfettiConfiguration { */ public static var particlesConfig: SPConfettiParticlesConfig { get { shared.particlesConfig } - set { shared.particlesConfig = newValue } + set { shared.updateParticlesConfig(with: newValue) } } // MARK: - Internal @@ -64,4 +64,9 @@ public class SPConfettiConfiguration { private static let shared = SPConfettiConfiguration() private init() {} + + // MARK: - Methods + private func updateParticlesConfig(with newConfig: SPConfettiParticlesConfig) { + particlesConfig = newConfig + } } From 181f199b3afa3d3c2ba250d0ea22de9f7953b622 Mon Sep 17 00:00:00 2001 From: Kristoffer Frank Date: Tue, 2 Apr 2024 13:38:38 +0200 Subject: [PATCH 2/7] issue 14: adding logic to change color + added logic to change birthrate --- .../Models/SPConfettiConfiguration.swift | 25 +++++++++++++------ .../Models/SPConfettiParticlesConfig.swift | 10 -------- Sources/SPConfetti/SPConfetti.swift | 10 +++++--- Sources/SPConfetti/SPConfettiView.swift | 18 ++++++++++--- .../SwiftUI/SPConfettiModifier.swift | 25 ++++++++++++++----- 5 files changed, 59 insertions(+), 29 deletions(-) diff --git a/Sources/SPConfetti/Models/SPConfettiConfiguration.swift b/Sources/SPConfetti/Models/SPConfettiConfiguration.swift index 8dafac5..396db87 100644 --- a/Sources/SPConfetti/Models/SPConfettiConfiguration.swift +++ b/Sources/SPConfetti/Models/SPConfettiConfiguration.swift @@ -51,7 +51,22 @@ public class SPConfettiConfiguration { */ public static var particlesConfig: SPConfettiParticlesConfig { get { shared.particlesConfig } - set { shared.updateParticlesConfig(with: newValue) } + set { shared.particlesConfig = newValue } + } + /** + SPConfetti: sets the colors of the animation + */ + public static var colors: [UIColor] { + get { shared.colors } + set { shared.colors = newValue } + } + + /** + SPConfetti: The number of emitted objects created every second. + */ + public static var birthRate: Float { + get { shared.birthRate } + set { shared.birthRate = newValue } } // MARK: - Internal @@ -59,14 +74,10 @@ public class SPConfettiConfiguration { private var animation: SPConfettiAnimation = .fullWidthToDown private var particles: [SPConfettiParticle] = [.arc] private var particlesConfig = SPConfettiParticlesConfig() - + private var colors: [UIColor] = [] + private var birthRate: Float = 24 // MARK: - Singltone private static let shared = SPConfettiConfiguration() private init() {} - - // MARK: - Methods - private func updateParticlesConfig(with newConfig: SPConfettiParticlesConfig) { - particlesConfig = newConfig - } } diff --git a/Sources/SPConfetti/Models/SPConfettiParticlesConfig.swift b/Sources/SPConfetti/Models/SPConfettiParticlesConfig.swift index 1bd5336..3a481d5 100644 --- a/Sources/SPConfetti/Models/SPConfettiParticlesConfig.swift +++ b/Sources/SPConfetti/Models/SPConfettiParticlesConfig.swift @@ -32,16 +32,6 @@ public struct SPConfettiParticlesConfig { */ public var colored: Bool = true - /** - SPConfetti: Style of particles. Can be custom image. - */ - public var colors: [UIColor] = [.systemRed, .systemPink, .systemYellow, .systemTeal, .systemBlue, .systemGreen] - - /** - SPConfetti: The number of emitted objects created every second. - */ - public var birthRate: Float = 24 - /** SPConfetti: The lifetime of the cell, in second. */ diff --git a/Sources/SPConfetti/SPConfetti.swift b/Sources/SPConfetti/SPConfetti.swift index c6dedc1..f094c70 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 colors: set the colors of the animation */ @available(iOSApplicationExtension, unavailable) - public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], in window: UIWindow? = nil) { + public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], in window: UIWindow? = nil, colors: [UIColor], birthRate: Float) { shared.view.animation = animation shared.view.particles = particles let keyWindow = UIApplication.shared.windows.first { $0.isKeyWindow } @@ -53,6 +54,8 @@ public class SPConfetti { window.addSubview(shared.view) } shared.view.frame = window.bounds + shared.view.colors = colors + shared.view.birthRate = birthRate shared.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] shared.view.startAnimating() } @@ -64,10 +67,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 colors: set the colors of the animation */ @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, in window: UIWindow? = nil, colors: [UIColor], birthRate: Float) { + startAnimating(animation, particles: particles, in: window, colors: colors, birthRate: birthRate) delay(duration, closure: { stopAnimating() }) diff --git a/Sources/SPConfetti/SPConfettiView.swift b/Sources/SPConfetti/SPConfettiView.swift index 26fdae1..d5dca46 100644 --- a/Sources/SPConfetti/SPConfettiView.swift +++ b/Sources/SPConfetti/SPConfettiView.swift @@ -60,11 +60,13 @@ open class SPConfettiView: UIView { - parameter animation: Kind of animation, position and direction of particles. - parameter particles: Particles style. Can be custom image. + - parameter colors: set the colors of the animation */ - public init(animation: SPConfettiAnimation, particles: [SPConfettiParticle]) { + public init(animation: SPConfettiAnimation, particles: [SPConfettiParticle], colors: [UIColor]) { super.init(frame: .zero) self.animation = animation self.particles = particles + self.colors = colors commomInit() } @@ -100,6 +102,16 @@ open class SPConfettiView: UIView { */ public lazy var particlesConfig = SPConfettiConfiguration.particlesConfig + /** + SPConfetti: sets the colors of the animation + */ + public lazy var colors: [UIColor] = SPConfettiConfiguration.colors + + /** + SPConfetti: The number of emitted objects created every second. + */ + public lazy var birthRate: Float = SPConfettiConfiguration.birthRate + /** SPConfetti: Start animating with selected animation and particles style. */ @@ -125,7 +137,7 @@ open class SPConfettiView: UIView { } emitterLayer.emitterCells = [] - for color in particlesConfig.colors { + for color in colors { for particle in particles { let cell = makeEmitterCell(particle: particle, color: color) emitterLayer.emitterCells?.append(cell) @@ -208,7 +220,7 @@ open class SPConfettiView: UIView { */ private func makeEmitterCell(particle: SPConfettiParticle, color: UIColor) -> CAEmitterCell { let cell = CAEmitterCell() - cell.birthRate = particlesConfig.birthRate / Float(particlesConfig.colors.count) / Float(particles.count) + cell.birthRate = birthRate / Float(colors.count) / Float(particles.count) cell.lifetime = particlesConfig.lifetime cell.lifetimeRange = .zero cell.velocity = particlesConfig.velocity diff --git a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift index 90f476b..5e92dd2 100644 --- a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift +++ b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift @@ -33,9 +33,11 @@ struct ConfettiPlaceholderView: UIViewRepresentable { var animation: SPConfettiAnimation var particles: [SPConfettiParticle] var duration: TimeInterval? + var colors: [UIColor] + var birthRate: Float func makeUIView(context: Context) -> UnderlyingView { - UnderlyingView(isPresented: $isPresented) + UnderlyingView(isPresented: $isPresented, colors: colors, birthRate: birthRate) } func updateUIView(_ view: UnderlyingView, context: Context) { @@ -43,6 +45,8 @@ struct ConfettiPlaceholderView: UIViewRepresentable { view.particles = particles view.duration = duration view.particleConfig = context.environment.confettiParticlesConfiguration + view.colors = colors + view.birthRate = birthRate if isPresented && !view.isReleasesParticles { view.play() @@ -60,15 +64,19 @@ struct ConfettiPlaceholderView: UIViewRepresentable { var particles: [SPConfettiParticle] = [] var duration: TimeInterval? = nil var particleConfig: SPConfettiParticlesConfig = .defaultValue + var colors: [UIColor] = [] + var birthRate: Float = 24 private(set) var isReleasesParticles: Bool - init(isPresented: Binding) { + init(isPresented: Binding, colors: [UIColor], birthRate: Float) { self.isPresented = isPresented isReleasesParticles = false super.init(frame: .zero) backgroundColor = .clear isUserInteractionEnabled = false + self.colors = colors + self.birthRate = birthRate } required init?(coder: NSCoder) { @@ -84,7 +92,9 @@ struct ConfettiPlaceholderView: UIViewRepresentable { SPConfetti.startAnimating(animation, particles: particles, duration: duration, - in: self.window) + in: self.window, + colors: colors, + birthRate: birthRate) delay(duration) { [weak self] in self?.stop() @@ -92,7 +102,9 @@ struct ConfettiPlaceholderView: UIViewRepresentable { } else { SPConfetti.startAnimating(animation, particles: particles, - in: self.window) + in: self.window, + colors: colors, + birthRate: birthRate) } } @@ -128,10 +140,11 @@ extension View { - parameter animation: Kind of animation, position and direction of particles. - parameter particles: Particles style. Can be custom image. - parameter duration: Automatically stop animation after this time interval. + - parameter colors: set the colors of the animation */ - public func confetti(isPresented: Binding, animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval?) -> some View { + public func confetti(isPresented: Binding, animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval?, colors: [UIColor], birthRate: Float) -> some View { self.background( - ConfettiPlaceholderView(isPresented: isPresented, animation: animation, particles: particles, duration: duration) + ConfettiPlaceholderView(isPresented: isPresented, animation: animation, particles: particles, duration: duration, colors: colors, birthRate: birthRate) .allowsHitTesting(false) ) } From 311b690b79145eac86abb531b3689a8b94fbf8f5 Mon Sep 17 00:00:00 2001 From: Kristoffer Frank Date: Tue, 2 Apr 2024 14:12:05 +0200 Subject: [PATCH 3/7] the problem was more simple than i initially thought --- .../Models/SPConfettiConfiguration.swift | 18 +---------- .../Models/SPConfettiParticlesConfig.swift | 10 +++++++ Sources/SPConfetti/SPConfetti.swift | 11 +++---- Sources/SPConfetti/SPConfettiView.swift | 18 ++--------- .../SwiftUI/SPConfettiModifier.swift | 30 ++++++++----------- 5 files changed, 30 insertions(+), 57 deletions(-) diff --git a/Sources/SPConfetti/Models/SPConfettiConfiguration.swift b/Sources/SPConfetti/Models/SPConfettiConfiguration.swift index 396db87..4060928 100644 --- a/Sources/SPConfetti/Models/SPConfettiConfiguration.swift +++ b/Sources/SPConfetti/Models/SPConfettiConfiguration.swift @@ -53,29 +53,13 @@ public class SPConfettiConfiguration { get { shared.particlesConfig } set { shared.particlesConfig = newValue } } - /** - SPConfetti: sets the colors of the animation - */ - public static var colors: [UIColor] { - get { shared.colors } - set { shared.colors = newValue } - } - - /** - SPConfetti: The number of emitted objects created every second. - */ - public static var birthRate: Float { - get { shared.birthRate } - set { shared.birthRate = newValue } - } // MARK: - Internal private var animation: SPConfettiAnimation = .fullWidthToDown private var particles: [SPConfettiParticle] = [.arc] private var particlesConfig = SPConfettiParticlesConfig() - private var colors: [UIColor] = [] - private var birthRate: Float = 24 + // MARK: - Singltone private static let shared = SPConfettiConfiguration() diff --git a/Sources/SPConfetti/Models/SPConfettiParticlesConfig.swift b/Sources/SPConfetti/Models/SPConfettiParticlesConfig.swift index 3a481d5..1bd5336 100644 --- a/Sources/SPConfetti/Models/SPConfettiParticlesConfig.swift +++ b/Sources/SPConfetti/Models/SPConfettiParticlesConfig.swift @@ -32,6 +32,16 @@ public struct SPConfettiParticlesConfig { */ public var colored: Bool = true + /** + SPConfetti: Style of particles. Can be custom image. + */ + public var colors: [UIColor] = [.systemRed, .systemPink, .systemYellow, .systemTeal, .systemBlue, .systemGreen] + + /** + SPConfetti: The number of emitted objects created every second. + */ + public var birthRate: Float = 24 + /** SPConfetti: The lifetime of the cell, in second. */ diff --git a/Sources/SPConfetti/SPConfetti.swift b/Sources/SPConfetti/SPConfetti.swift index f094c70..f52d2c6 100644 --- a/Sources/SPConfetti/SPConfetti.swift +++ b/Sources/SPConfetti/SPConfetti.swift @@ -40,10 +40,9 @@ 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 colors: set the colors of the animation */ @available(iOSApplicationExtension, unavailable) - public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], in window: UIWindow? = nil, colors: [UIColor], birthRate: Float) { + public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], in window: UIWindow? = nil, config: SPConfettiParticlesConfig) { shared.view.animation = animation shared.view.particles = particles let keyWindow = UIApplication.shared.windows.first { $0.isKeyWindow } @@ -54,8 +53,7 @@ public class SPConfetti { window.addSubview(shared.view) } shared.view.frame = window.bounds - shared.view.colors = colors - shared.view.birthRate = birthRate + shared.view.particlesConfig = config shared.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] shared.view.startAnimating() } @@ -67,11 +65,10 @@ 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 colors: set the colors of the animation */ @available(iOSApplicationExtension, unavailable) - public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval, in window: UIWindow? = nil, colors: [UIColor], birthRate: Float) { - startAnimating(animation, particles: particles, in: window, colors: colors, birthRate: birthRate) + public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval, in window: UIWindow? = nil, config: SPConfettiParticlesConfig) { + startAnimating(animation, particles: particles, in: window, config: config) delay(duration, closure: { stopAnimating() }) diff --git a/Sources/SPConfetti/SPConfettiView.swift b/Sources/SPConfetti/SPConfettiView.swift index d5dca46..26fdae1 100644 --- a/Sources/SPConfetti/SPConfettiView.swift +++ b/Sources/SPConfetti/SPConfettiView.swift @@ -60,13 +60,11 @@ open class SPConfettiView: UIView { - parameter animation: Kind of animation, position and direction of particles. - parameter particles: Particles style. Can be custom image. - - parameter colors: set the colors of the animation */ - public init(animation: SPConfettiAnimation, particles: [SPConfettiParticle], colors: [UIColor]) { + public init(animation: SPConfettiAnimation, particles: [SPConfettiParticle]) { super.init(frame: .zero) self.animation = animation self.particles = particles - self.colors = colors commomInit() } @@ -102,16 +100,6 @@ open class SPConfettiView: UIView { */ public lazy var particlesConfig = SPConfettiConfiguration.particlesConfig - /** - SPConfetti: sets the colors of the animation - */ - public lazy var colors: [UIColor] = SPConfettiConfiguration.colors - - /** - SPConfetti: The number of emitted objects created every second. - */ - public lazy var birthRate: Float = SPConfettiConfiguration.birthRate - /** SPConfetti: Start animating with selected animation and particles style. */ @@ -137,7 +125,7 @@ open class SPConfettiView: UIView { } emitterLayer.emitterCells = [] - for color in colors { + for color in particlesConfig.colors { for particle in particles { let cell = makeEmitterCell(particle: particle, color: color) emitterLayer.emitterCells?.append(cell) @@ -220,7 +208,7 @@ open class SPConfettiView: UIView { */ private func makeEmitterCell(particle: SPConfettiParticle, color: UIColor) -> CAEmitterCell { let cell = CAEmitterCell() - cell.birthRate = birthRate / Float(colors.count) / Float(particles.count) + cell.birthRate = particlesConfig.birthRate / Float(particlesConfig.colors.count) / Float(particles.count) cell.lifetime = particlesConfig.lifetime cell.lifetimeRange = .zero cell.velocity = particlesConfig.velocity diff --git a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift index 5e92dd2..82dcce2 100644 --- a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift +++ b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift @@ -33,11 +33,9 @@ struct ConfettiPlaceholderView: UIViewRepresentable { var animation: SPConfettiAnimation var particles: [SPConfettiParticle] var duration: TimeInterval? - var colors: [UIColor] - var birthRate: Float func makeUIView(context: Context) -> UnderlyingView { - UnderlyingView(isPresented: $isPresented, colors: colors, birthRate: birthRate) + UnderlyingView(isPresented: $isPresented) } func updateUIView(_ view: UnderlyingView, context: Context) { @@ -45,8 +43,6 @@ struct ConfettiPlaceholderView: UIViewRepresentable { view.particles = particles view.duration = duration view.particleConfig = context.environment.confettiParticlesConfiguration - view.colors = colors - view.birthRate = birthRate if isPresented && !view.isReleasesParticles { view.play() @@ -64,19 +60,15 @@ struct ConfettiPlaceholderView: UIViewRepresentable { var particles: [SPConfettiParticle] = [] var duration: TimeInterval? = nil var particleConfig: SPConfettiParticlesConfig = .defaultValue - var colors: [UIColor] = [] - var birthRate: Float = 24 private(set) var isReleasesParticles: Bool - init(isPresented: Binding, colors: [UIColor], birthRate: Float) { + init(isPresented: Binding) { self.isPresented = isPresented isReleasesParticles = false super.init(frame: .zero) backgroundColor = .clear isUserInteractionEnabled = false - self.colors = colors - self.birthRate = birthRate } required init?(coder: NSCoder) { @@ -93,9 +85,7 @@ struct ConfettiPlaceholderView: UIViewRepresentable { particles: particles, duration: duration, in: self.window, - colors: colors, - birthRate: birthRate) - + config: particleConfig) delay(duration) { [weak self] in self?.stop() } @@ -103,8 +93,7 @@ struct ConfettiPlaceholderView: UIViewRepresentable { SPConfetti.startAnimating(animation, particles: particles, in: self.window, - colors: colors, - birthRate: birthRate) + config: particleConfig) } } @@ -140,11 +129,16 @@ extension View { - parameter animation: Kind of animation, position and direction of particles. - parameter particles: Particles style. Can be custom image. - parameter duration: Automatically stop animation after this time interval. - - parameter colors: set the colors of the animation */ - public func confetti(isPresented: Binding, animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval?, colors: [UIColor], birthRate: Float) -> some View { +// public func confetti(isPresented: Binding, animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval?, colors: [UIColor], birthRate: Float) -> some View { +// self.background( +// ConfettiPlaceholderView(isPresented: isPresented, animation: animation, particles: particles, duration: duration, colors: colors, birthRate: birthRate) +// .allowsHitTesting(false) +// ) +// } + public func confetti(isPresented: Binding, animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval?) -> some View { self.background( - ConfettiPlaceholderView(isPresented: isPresented, animation: animation, particles: particles, duration: duration, colors: colors, birthRate: birthRate) + ConfettiPlaceholderView(isPresented: isPresented, animation: animation, particles: particles, duration: duration) .allowsHitTesting(false) ) } From 19b734e7c9c19d2a2d04cb410f6f38f6f1e299cc Mon Sep 17 00:00:00 2001 From: Kristoffer Frank Date: Tue, 2 Apr 2024 14:15:04 +0200 Subject: [PATCH 4/7] unused line comments deleted --- Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift index 82dcce2..5d1c1fb 100644 --- a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift +++ b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift @@ -130,12 +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?, colors: [UIColor], birthRate: Float) -> some View { -// self.background( -// ConfettiPlaceholderView(isPresented: isPresented, animation: animation, particles: particles, duration: duration, colors: colors, birthRate: birthRate) -// .allowsHitTesting(false) -// ) -// } + public func confetti(isPresented: Binding, animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval?) -> some View { self.background( ConfettiPlaceholderView(isPresented: isPresented, animation: animation, particles: particles, duration: duration) From f58766d2f1d74b0579e9db13ab0676ec87aa3aec Mon Sep 17 00:00:00 2001 From: Kristoffer Frank Date: Wed, 3 Apr 2024 14:35:01 +0200 Subject: [PATCH 5/7] parameter names and explanations updated --- Sources/SPConfetti/SPConfetti.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/SPConfetti/SPConfetti.swift b/Sources/SPConfetti/SPConfetti.swift index f52d2c6..2bebc48 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, config: SPConfettiParticlesConfig) { + public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], in window: UIWindow? = nil, particlesConfig: SPConfettiParticlesConfig) { shared.view.animation = animation shared.view.particles = particles let keyWindow = UIApplication.shared.windows.first { $0.isKeyWindow } @@ -53,7 +54,7 @@ public class SPConfetti { window.addSubview(shared.view) } shared.view.frame = window.bounds - shared.view.particlesConfig = config + shared.view.particlesConfig = particlesConfig shared.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] shared.view.startAnimating() } @@ -65,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, config: SPConfettiParticlesConfig) { - startAnimating(animation, particles: particles, in: window, config: config) + public static func startAnimating(_ animation: SPConfettiAnimation, particles: [SPConfettiParticle], duration: TimeInterval, in window: UIWindow? = nil, particlesConfig: SPConfettiParticlesConfig) { + startAnimating(animation, particles: particles, in: window, particlesConfig: particlesConfig) delay(duration, closure: { stopAnimating() }) From 1f092d80933578ff59b99dacce8aed923d097ecf Mon Sep 17 00:00:00 2001 From: Kristoffer Frank Date: Wed, 3 Apr 2024 14:36:37 +0200 Subject: [PATCH 6/7] parameter names and explanations updated --- Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift index 5d1c1fb..b5929df 100644 --- a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift +++ b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift @@ -85,7 +85,7 @@ struct ConfettiPlaceholderView: UIViewRepresentable { particles: particles, duration: duration, in: self.window, - config: particleConfig) + particlesConfig: particleConfig) delay(duration) { [weak self] in self?.stop() } @@ -93,7 +93,7 @@ struct ConfettiPlaceholderView: UIViewRepresentable { SPConfetti.startAnimating(animation, particles: particles, in: self.window, - config: particleConfig) + particlesConfig: particleConfig) } } From d9cf5def7c6c303fa6d667d21beddc214ac5ada6 Mon Sep 17 00:00:00 2001 From: Kristoffer Frank Date: Wed, 3 Apr 2024 14:40:59 +0200 Subject: [PATCH 7/7] parameter names and explanations updated --- Sources/SPConfetti/SPConfetti.swift | 6 +++--- Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/SPConfetti/SPConfetti.swift b/Sources/SPConfetti/SPConfetti.swift index 2bebc48..9c4dee0 100644 --- a/Sources/SPConfetti/SPConfetti.swift +++ b/Sources/SPConfetti/SPConfetti.swift @@ -43,7 +43,7 @@ public class SPConfetti { - 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, particlesConfig: SPConfettiParticlesConfig) { + 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 } @@ -69,8 +69,8 @@ public class SPConfetti { - 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, particlesConfig: SPConfettiParticlesConfig) { - startAnimating(animation, particles: particles, in: window, particlesConfig: particlesConfig) + 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 b5929df..99d2eaf 100644 --- a/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift +++ b/Sources/SPConfetti/SwiftUI/SPConfettiModifier.swift @@ -84,16 +84,16 @@ struct ConfettiPlaceholderView: UIViewRepresentable { SPConfetti.startAnimating(animation, particles: particles, duration: duration, - in: self.window, - particlesConfig: particleConfig) + particlesConfig: particleConfig, + in: self.window) delay(duration) { [weak self] in self?.stop() } } else { SPConfetti.startAnimating(animation, particles: particles, - in: self.window, - particlesConfig: particleConfig) + particlesConfig: particleConfig, + in: self.window) } }