Skip to content

Commit

Permalink
#137 animationcomplete event fix (#158)
Browse files Browse the repository at this point in the history
* [animation] fix event test

* [animation] add issue test case

* [animation] fix animationcomplete event
  • Loading branch information
krzysztof-grzybek authored and ngokevin committed Jun 27, 2018
1 parent 0510ae3 commit f511474
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
12 changes: 11 additions & 1 deletion components/animation/dist/aframe-animation-component.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@
beginAnimation: function () { beginAnimation: function () {
this.updateConfig(); this.updateConfig();
this.time = 0; this.time = 0;
this.animation.seek(0);
this.animationIsPlaying = true; this.animationIsPlaying = true;
this.stopRelatedAnimations(); this.stopRelatedAnimations();
this.el.emit('animationbegin', this.eventDetail); this.el.emit('animationbegin', this.eventDetail);
Expand All @@ -250,6 +249,12 @@
* startEvents callback. * startEvents callback.
*/ */
onStartEvent: function () { onStartEvent: function () {
this.updateConfig();
if (this.animation) {
this.animation.pause();
}
this.animation = anime(this.config);

// Include the delay before each start event. // Include the delay before each start event.
if (this.data.delay) { if (this.data.delay) {
setTimeout(this.beginAnimation, this.data.delay); setTimeout(this.beginAnimation, this.data.delay);
Expand Down Expand Up @@ -472,6 +477,7 @@
var componentName; var componentName;
var data = this.data; var data = this.data;
var el = this.el; var el = this.el;
var self = this;


if (data.from) { return false; } if (data.from) { return false; }


Expand All @@ -483,6 +489,9 @@
el.addEventListener('componentinitialized', function wait (evt) { el.addEventListener('componentinitialized', function wait (evt) {
if (evt.detail.name !== componentName) { return; } if (evt.detail.name !== componentName) { return; }
cb(); cb();
// Since the config was created async, create the animation now since we missed it
// earlier.
self.animation = anime(self.config);
el.removeEventListener('componentinitialized', wait); el.removeEventListener('componentinitialized', wait);
}); });
return true; return true;
Expand All @@ -500,6 +509,7 @@
component = this.el.components[componentName]; component = this.el.components[componentName];
if (componentName === this.attrName) { continue; } if (componentName === this.attrName) { continue; }
if (component.name !== 'animation') { continue; } if (component.name !== 'animation') { continue; }
if (!component.animationIsPlaying) { continue; }
if (component.data.property !== this.data.property) { continue; } if (component.data.property !== this.data.property) { continue; }
component.animationIsPlaying = false; component.animationIsPlaying = false;
} }
Expand Down
Loading

0 comments on commit f511474

Please sign in to comment.