Skip to content

Commit

Permalink
Fix current time for inactive timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesodland committed Jan 7, 2024
1 parent 2ccfc00 commit f7c6551
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
12 changes: 10 additions & 2 deletions src/proxy-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,11 @@ function autoAlignStartTime(details) {
// 5. Let start offset be the resolved timeline time corresponding to the start of the animation attachment range.
// In the case of view timelines, it requires a calculation based on the proportion of the cover range.
try {
startOffset = CSS.percent(fractionalStartDelay(details) * 100);
const startDelayFraction = fractionalStartDelay(details);
if (startDelayFraction === null)
return;

startOffset = CSS.percent(startDelayFraction * 100);
} catch {
// TODO: Validate supported values for range start, to avoid exceptions when resolving the values.

Expand All @@ -907,7 +911,11 @@ function autoAlignStartTime(details) {
// 6. Let end offset be the resolved timeline time corresponding to the end of the animation attachment range.
// In the case of view timelines, it requires a calculation based on the proportion of the cover range.
try {
endOffset = CSS.percent((1 - fractionalEndDelay(details)) * 100);
const endDelayFraction = fractionalEndDelay(details);
if (endDelayFraction === null)
return;

endOffset = CSS.percent((1 - endDelayFraction) * 100);
} catch {
// TODO: Validate supported values for range end, to avoid exceptions when resolving the values.

Expand Down
11 changes: 7 additions & 4 deletions src/scroll-timeline-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ function updateMeasurements(source) {
}
}

requestAnimationFrame(() => {
// Defer ticking timeline to animation frame to prevent
// "ResizeObserver loop completed with undelivered notifications"
setTimeout(() => {
// Schedule a task to update timelines after all measurements are completed
// TODO: run task only once if there are multiple calls to updateMeasurements for the same source
for (const ref of details.timelineRefs) {
const timeline = ref.deref();
if (timeline) {
Expand Down Expand Up @@ -593,6 +593,9 @@ function range(timeline, phase) {
if (!(timeline instanceof ViewTimeline))
return unresolved;

if (!sourceMeasurements || !subjectMeasurements)
return unresolved;

return calculateRange(phase, sourceMeasurements, subjectMeasurements, details.axis, details.inset);
}

Expand Down Expand Up @@ -776,7 +779,7 @@ export function relativePosition(timeline, phase, offset) {

export function calculateRelativePosition(phaseRange, offset, coverRange, subject) {
if (!phaseRange || !coverRange)
return 0;
return null;

let style = getComputedStyle(subject)
const info = {
Expand Down
8 changes: 4 additions & 4 deletions test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ PASS /scroll-animations/scroll-timelines/cancel-animation.html The finished prom
PASS /scroll-animations/scroll-timelines/cancel-animation.html The cancel event should NOT be fired if the animation is already idle
PASS /scroll-animations/scroll-timelines/cancel-animation.html Canceling an animation should fire cancel event on orphaned element
PASS /scroll-animations/scroll-timelines/cancel-animation.html Canceling an animation with inactive timeline should cause its start time and hold time to be unresolved
FAIL /scroll-animations/scroll-timelines/cancel-animation.html oncancel event is fired when the timeline is inactive.
TIMEOUT /scroll-animations/scroll-timelines/cancel-animation.html oncancel event is fired when the timeline is inactive.
PASS /scroll-animations/scroll-timelines/constructor-no-document.html The source can be null if the document.scrollingElement does not exist
PASS /scroll-animations/scroll-timelines/constructor.html A ScrollTimeline can be created with a source
PASS /scroll-animations/scroll-timelines/constructor.html A ScrollTimeline can be created with a non-scrolling source
Expand Down Expand Up @@ -790,12 +790,12 @@ PASS /scroll-animations/scroll-timelines/scroll-animation-effect-phases.tentativ
PASS /scroll-animations/scroll-timelines/scroll-animation-inactive-timeline.html Play pending task doesn't run when the timeline is inactive.
PASS /scroll-animations/scroll-timelines/scroll-animation-inactive-timeline.html Animation start and current times are correct if scroll timeline is activated after animation.play call.
PASS /scroll-animations/scroll-timelines/scroll-animation-inactive-timeline.html Animation start and current times are correct if scroll timeline is activated after setting start time.
FAIL /scroll-animations/scroll-timelines/scroll-animation-inactive-timeline.html Animation current time is correct when the timeline becomes newly inactive and then active again.
PASS /scroll-animations/scroll-timelines/scroll-animation-inactive-timeline.html Animation current time is correct when the timeline becomes newly inactive and then active again.
FAIL /scroll-animations/scroll-timelines/scroll-animation.html Animation start and current times are correct for each animation state.
FAIL /scroll-animations/scroll-timelines/scroll-animation.html Animation start and current times are correct for each animation state when the animation starts playing with advanced scroller.
PASS /scroll-animations/scroll-timelines/scroll-animation.html Finished animation plays on reverse scrolling.
FAIL /scroll-animations/scroll-timelines/scroll-animation.html Sending animation finished events by finished animation on reverse scrolling.
FAIL /scroll-animations/scroll-timelines/scroll-timeline-invalidation.html Animation current time and effect local time are updated after scroller content size changes.
PASS /scroll-animations/scroll-timelines/scroll-timeline-invalidation.html Animation current time and effect local time are updated after scroller content size changes.
PASS /scroll-animations/scroll-timelines/scroll-timeline-invalidation.html Animation current time and effect local time are updated after scroller size changes.
FAIL /scroll-animations/scroll-timelines/scroll-timeline-invalidation.html If scroll animation resizes its scroll timeline scroller, layout reruns once per frame.
FAIL /scroll-animations/scroll-timelines/scroll-timeline-range.html Scroll timeline with percentage range [JavaScript API]
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 432 of 959 tests.
Passed 434 of 959 tests.

0 comments on commit f7c6551

Please sign in to comment.