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

Not automatically play created animation #396

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/keyframe-effect-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
shared.deprecated('Custom KeyframeEffect', '2015-06-22', 'Use KeyframeEffect.onsample instead.');
this._normalizedKeyframes = effectInput;
} else {
if (!Array.isArray(effectInput) && this._timing.duration === 0) {
effectInput = [effectInput, effectInput];
}
this._normalizedKeyframes = new KeyframeList(effectInput);
}
this._keyframes = effectInput;
Expand Down
2 changes: 1 addition & 1 deletion src/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
// effect's children, and Animation.play is also recursive. We only need to call play on each
// animation in the tree once.
animation._updatePromises();
animation._animation.play();
animation._play();
animation._updatePromises();
return animation;
},
Expand Down
14 changes: 13 additions & 1 deletion src/web-animations-next-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
this._oldPlayState = 'idle';
this._rebuildUnderlyingAnimation();
// Animations are constructed in the idle state.
this._animation.cancel();
this._cancel();
this._updatePromises();
};

Expand Down Expand Up @@ -285,6 +285,12 @@
});
this._updatePromises();
},
_play: function() {
this._animation.play();
this._childAnimations.forEach(function(child) {
child._play();
});
},
pause: function() {
this._updatePromises();
if (this.currentTime) {
Expand All @@ -311,6 +317,12 @@
this._removeChildAnimations();
this._updatePromises();
},
_cancel: function() {
this._animation.cancel();
this._childAnimations.forEach(function(child) {
child._cancel();
});
},
reverse: function() {
this._updatePromises();
var oldCurrentTime = this.currentTime;
Expand Down
12 changes: 12 additions & 0 deletions test/js/keyframe-effect-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,16 @@ suite('keyframe-effect-constructor', function() {
effect.timing.iterations = 2;
assert.closeTo(Number(getComputedStyle(target).opacity), 0.75, 0.01, 't=125 after setting iterations');
});

test('Allow partial keyframes when duration is zero', function() {
var target = document.createElement('div');
document.body.appendChild(target);
var effect = new KeyframeEffect(
target,
{opacity: 0},
{fill: 'forwards'});
var animation = document.timeline.play(effect);
tick(1);
assert.equal(getComputedStyle(target).opacity, 0);
});
});
17 changes: 16 additions & 1 deletion test/js/web-animations-next-animation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
suite('animation-promises-tests', function() {
suite('web-animations-next-animation', function() {
test('Newly constructed animation has a resolved ready promise', function(done) {
var readyResolved = false;
var readyRejected = false;
Expand Down Expand Up @@ -315,4 +315,19 @@ suite('animation-promises-tests', function() {
}
}, 200);
});

test('Newly constructed animation is idle', function() {
var effect = new SequenceEffect([
new KeyframeEffect(document.body, [], 2000),
new GroupEffect([
new KeyframeEffect(document.body, [], 2000),
new KeyframeEffect(document.body, [], 1000)
])
]);
var animation = new Animation(effect, document.timeline);
(function isIdle(animation) {
assert.equal(animation.playState, 'idle');
animation._childAnimations.every(isIdle);
})(animation);
});
});