Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Flack committed Dec 20, 2023
1 parent 00ae9df commit 1db7fe1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/proxy-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function createReadyPromise(details) {
details.readyPromise = new PromiseWrapper();
// Trigger the pending task on the next animation frame.
requestAnimationFrame(() => {
const timelineTime = details.timeline.currentTime;
const timelineTime = details.timeline ? details.timeline.currentTime : null;
if (timelineTime !== null)
notifyReady(details);
});
Expand Down Expand Up @@ -612,6 +612,11 @@ function renormalizeTiming() {
}

function notifyReady(details) {
// If the timeline has been changed, resolve the previous ready promise.
if (!details.timeline) {
details.readyPromise.resolve(details.proxy);
return;
}
if (details.pendingTask == 'pause') {
commitPendingPause(details);
} else if (details.pendingTask == 'play') {
Expand Down
20 changes: 11 additions & 9 deletions src/scroll-timeline-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ export function initCSSPolyfill() {
window.addEventListener('animationstart', (evt) => {
evt.target.getAnimations().filter(anim => anim.animationName === evt.animationName).forEach(anim => {
const result = createScrollTimeline(anim, anim.animationName, evt.target);
// If the CSS Animation refers to a scroll or view timeline we need to proxy the animation instance.
if (result.timeline && !(anim instanceof ProxyAnimation)) {
const proxyAnimation = new ProxyAnimation(anim, result.timeline, result.animOptions);
anim.pause();
proxyAnimation.play();
} else {
// If the timeline was removed or the animation was already an instance of a proxy animation,
// invoke the set the timeline procedure on the existing animation.
anim.timeline = result.timeline;
if (result) {
// If the CSS Animation refers to a scroll or view timeline we need to proxy the animation instance.
if (result.timeline && !(anim instanceof ProxyAnimation)) {
const proxyAnimation = new ProxyAnimation(anim, result.timeline, result.animOptions);
anim.pause();
proxyAnimation.play();
} else {
// If the timeline was removed or the animation was already an instance of a proxy animation,
// invoke the set the timeline procedure on the existing animation.
anim.timeline = result.timeline;
}
}
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ FAIL /scroll-animations/css/animation-timeline-deferred.html Animation.timeline
FAIL /scroll-animations/css/animation-timeline-deferred.html Animation.timeline returns null for inactive deferred timeline
FAIL /scroll-animations/css/animation-timeline-deferred.html Animation.timeline returns null for inactive (overattached) deferred timeline
FAIL /scroll-animations/css/animation-timeline-ignored.tentative.html Changing animation-timeline changes the timeline (sanity check)
FAIL /scroll-animations/css/animation-timeline-ignored.tentative.html animation-timeline ignored after setting timeline with JS (ScrollTimeline from JS)
PASS /scroll-animations/css/animation-timeline-ignored.tentative.html animation-timeline ignored after setting timeline with JS (ScrollTimeline from JS)
FAIL /scroll-animations/css/animation-timeline-ignored.tentative.html animation-timeline ignored after setting timeline with JS (ScrollTimeline from CSS)
PASS /scroll-animations/css/animation-timeline-ignored.tentative.html animation-timeline ignored after setting timeline with JS (document timeline)
PASS /scroll-animations/css/animation-timeline-ignored.tentative.html animation-timeline ignored after setting timeline with JS (null)
FAIL /scroll-animations/css/animation-timeline-ignored.tentative.html animation-timeline ignored after setting timeline with JS (document timeline)
FAIL /scroll-animations/css/animation-timeline-ignored.tentative.html animation-timeline ignored after setting timeline with JS (null)
FAIL /scroll-animations/css/animation-timeline-in-keyframe.html The animation-timeline property may not be used in keyframes
PASS /scroll-animations/css/animation-timeline-multiple.html animation-timeline works with multiple timelines
FAIL /scroll-animations/css/animation-timeline-none.html Animation with animation-timeline:none holds current time at zero
Expand Down Expand Up @@ -957,4 +957,4 @@ FAIL /scroll-animations/view-timelines/view-timeline-sticky-block.html View time
FAIL /scroll-animations/view-timelines/view-timeline-sticky-inline.html View timeline with sticky target, block axis.
FAIL /scroll-animations/view-timelines/view-timeline-subject-size-changes.html View timeline with subject size change after the creation of the animation
FAIL /scroll-animations/view-timelines/zero-intrinsic-iteration-duration.tentative.html Intrinsic iteration duration is non-negative
Passed 356 of 959 tests.
Passed 355 of 959 tests.

0 comments on commit 1db7fe1

Please sign in to comment.