Skip to content

Conversation

@krishbee
Copy link

@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

@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.

2 participants