material-motion / material-motion-swift

A toolkit for building responsive motion using Core Animation.
Apache License 2.0
1.42k stars 79 forks source link

Property chaining can cause over-completion of core animation animations #65

Open jverkoey opened 7 years ago

jverkoey commented 7 years ago

Scenario:

  1. Add a Tween or Spring to a property.
  2. Connect that property to another property.

When the interaction emits its animation event on the core animation channel, the info will be propagated to the first property and then the second. Both will add an animation with a CATransaction using the provided completion handler. Because these are two individual animations, each completion handler will be invoked individually, causing the interaction's completion handler to be invoked twice.

In practice this won't be particularly noticeable because the timings for both animations should be similar, but there is a chance that this could cause an interaction to be marked as completed before all animations have, in fact, completed.

A potential solution here is to create an intermediary counting completion handler that supports being added to multiple transactions. This handler would propagate up to the original handler once all known animations have completed.