neon-animation icon indicating copy to clipboard operation
neon-animation copied to clipboard

Any reason why this._player.cancel() is called once animations finish in playAnimation function?

Open JustinXinLiu opened this issue 9 years ago • 3 comments

I asked a question on SO a few days ago regarding maintaining the end state of a neon animation (http://stackoverflow.com/questions/31692377/how-to-maintain-the-end-state-of-a-neon-animation-in-polymer) and today I found this piece of code inside the function playAnimation in neon-animation-runner-behavior.html.

playAnimation: function(type, cookie) {
  var allConfigs = this.getAnimationConfig(type);
  if (!allConfigs) {
    return;
  }
  var allAnimations = this._configureAnimationEffects(allConfigs);
  var allEffects = allAnimations.map(function(animation) {
    return animation.effect;
  });

  if (allEffects.length > 0) {
    this._player = this._runAnimationEffects(allEffects);
    this._player.onfinish = function() {
      this._completeAnimations(allAnimations);

      if (this._player) {
        // not sure why this is needed?
        this._player.cancel();
        this._player = null;
      }

      this.fire('neon-animation-finish', cookie, {bubbles: false});
    }.bind(this);

  } else {
    this.fire('neon-animation-finish', cookie, {bubbles: false});
  }
},

I don't really understand why we need to cancel the animation upon the completion of it. Doing so will remove all effects from the source object and I have to manually set its final state once the animation finishes.

Can someone please shed some light on this?

JustinXinLiu avatar Aug 11 '15 10:08 JustinXinLiu

OK, now I see the side effects of having this line commented out.

So for me the fix is that to add a check around this._player.cancel(), when a type argument is passed in, meaning it's a custom animation, ignore the cancel.

      if (this._player) {
          if (!type) {
              this._player.cancel();
          }
        this._player = null;
      }

JustinXinLiu avatar Aug 12 '15 03:08 JustinXinLiu

Just ran into this myself. I think there are many instances when you'd want to maintain the end state of the animation, at least until another event occurs, even for non-custom animations. Consider a login component, where you use a slide-up-animation to reveal the forgot password form. Right now, it would slide up to reveal the form, and then immediately slide back down out of view.

ghost avatar Aug 12 '15 21:08 ghost

+1

kornalius avatar Oct 08 '15 13:10 kornalius