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

Idea: Composed Pow Effects Syntax #31

Open
mergesort opened this issue Jul 2, 2023 · 2 comments
Open

Idea: Composed Pow Effects Syntax #31

mergesort opened this issue Jul 2, 2023 · 2 comments

Comments

@mergesort
Copy link
Collaborator

I've recently found myself combining multiple effects, for example haptics and sounds or more complex effects like spinning and jumping an element at the same time.

I do this by adding two changeEffect calls, like so.

.changeEffect([.feedback(hapticImpact: .medium)], value: self.hasAnimated)
.changeEffect([.feedback(SoundEffect(url: SoundEffect.plinkSound))], value: self.hasAnimated)

The more effects I wish to chain together the longer the code grows, and the more call-sites I need to change grow the more I tweak the animation.

Instead I'd like to propose a few options that could work, as syntax that takes two modifiers and chains them together.

The simplest is an array:

.changeEffect([.feedback(hapticImpact: .medium), .feedback(SoundEffect(url: SoundEffect.plinkSound))], value: self.hasAnimated)

Which could even become variadics, now that they've become more powerful:

.changeEffect(.feedback(hapticImpact: .medium), .feedback(SoundEffect(url: SoundEffect.plinkSound)), value: self.hasAnimated)

Alternatively a function like composed(with: ) or adding(_ effect:) could be added to compose:

.changeEffect(.feedback(hapticImpact: .medium).composed(with: .feedback(SoundEffect(url: SoundEffect.plinkSound))), value: self.hasAnimated)

And lastly, perhaps using + operator:

.changeEffect(.feedback(hapticImpact: .medium) + .feedback(SoundEffect(url: SoundEffect.plinkSound)), value: self.hasAnimated)

Thank you as always! Would love to hear what you think, and if any of those seem like a good idea.

@robb
Copy link
Contributor

robb commented Jul 4, 2023

Sounds like a good idea. I'm leaning towards matching AnyTransition and going with something like

myView
  .changeEffect(
    .feedback(hapticImpact: .medium).combined(with: .feedback(SoundEffect(url: SoundEffect.plinkSound))),
    value: self.hasAnimated
  )

WDYT?

@mergesort
Copy link
Collaborator Author

I think matching the behavior is a great idea. I’ll admit that I’m not particularly picky about the name, so I’ll happily say that .combined sounds like a great choice for the API.

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

No branches or pull requests

2 participants