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

fix: Issue #14: Resetting Global color in config does not work as expected #16

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

krishbee
Copy link
Contributor

@krishbee krishbee commented Apr 2, 2024

Goal

To be able to change the config. Meaning that you can now change the animations behavior.
#14

Checklist

  • Testing in compability platforms
  • Installed correct via Swift Package Manager and Cocoapods

Sources/SPConfetti/SPConfetti.swift Outdated Show resolved Hide resolved
Sources/SPConfetti/SPConfetti.swift Outdated Show resolved Hide resolved
Sources/SPConfetti/SPConfetti.swift Show resolved Hide resolved
Sources/SPConfetti/SPConfetti.swift Show resolved Hide resolved
@KristofferHermansen
Copy link

It seems the problem stems from the shared.view never receiving updates when the environment values for .confettiParticlesConfiguration is changed. This is because the SPConfettiView is create once for the SPConfetti and loads the current static SPConfettiConfiguration.particlesConfig when its first created, but never updates it again.

This solution passes the particleConfiguration into the SPConfettiView each time an animation is played. This already sort of happens because the ConfettiPlaceholderView.UnderlyingView.play() functions sets SPConfettiConfiguration.particlesConfig = particleConfig. So another solution to this could be to directly set the views particlesConfig to the SPConfettiConfiguration.particlesConfig in the SPConfetti.startAnimating() function: shared.view.particlesConfig = SPConfettiConfiguration.particlesConfig

@KristofferHermansen
Copy link

It seems the problem stems from the shared.view never receiving updates when the environment values for .confettiParticlesConfiguration is changed. This is because the SPConfettiView is create once for the SPConfetti and loads the current static SPConfettiConfiguration.particlesConfig when its first created, but never updates it again.

This solution passes the particleConfiguration into the SPConfettiView each time an animation is played. This already sort of happens because the ConfettiPlaceholderView.UnderlyingView.play() functions sets SPConfettiConfiguration.particlesConfig = particleConfig. So another solution to this could be to directly set the views particlesConfig to the SPConfettiConfiguration.particlesConfig in the SPConfetti.startAnimating() function: shared.view.particlesConfig = SPConfettiConfiguration.particlesConfig

The solution proposed here does seem more correct when considering the use of SwiftUI Environment values for setting the configurations. As passing them to a static value kinda defeats the purpose of the environment value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants