Open flackr opened 1 year ago
Overall it seems reasonable to me. I think defining it in terms of startTime
and endTime
is a nice way of keeping it at arms length from effect timing.
Note that endTime is infinite when either iterations or duration is infinite. In these cases currentProgress should probably be null or undefined?
Mathematically, should it be zero? Not sure if that would be the most useful result, however.
Open question - should it be read only or should we allow setting the progress which would be equivalent to setting currentTime to currentProgress * endTime?
I'd suggest making it readonly. As you pointed out, there are some cases where this value would be null
/ undefined
/ 0
or somesuch, and in those cases if set made it writeable I guess the setter would throw?
We already have enough ways of changing the animation position (setting currentTime
, setting startTime
, calling the various playback methods etc.) and it's easy enough to make a read-only attribute writeable later if compelling use cases present themselves.
Mathematically, should it be zero? Not sure if that would be the most useful result, however.
Yeah, mathematically it would be 0. I don't have a strong preference for it to be null/undefined, just thought it might be marginally more meaningful than 0 to distinguish from the case of a 0 that can make progress.
In favor of this general approach as described here, to tackle #8669.
Fine with making it readonly as a starting point.
Thanks @bramus. Adding to agenda to discuss/resolve:
Regarding 1. +1 on adding, with 2 suggestions:
currentTime
behavior and allow setting progress through this endpoint. It will both be, IMHO, more handy for authors, and if I'm not mistaken, should be necessary for animations with duration: auto
.progress
?The CSS Working Group just discussed [web-animations-2] Progress APIs
, and agreed to the following:
RESOLVED: Add progress to Animation and make it readonly
On the PR from @DavMila there is one point where we don't have a clear answer. Should the progress be clamped to [0, 1]. For the full discussion you can view the PR review https://github.com/w3c/csswg-drafts/pull/9937#discussion_r1491825782 however I'll do my best to summarize the pros and cons of each.
fill = backwards | both
). However, this also means that to correctly reflect the progress for 0 duration animations we would likely have to return -Infinity
and Infinity
when you are before or at/after the start time respectively.Ultimately, I think either works, but which is better comes back to how authors will use this. @bramus @fantasai @birtles any thoughts?
I'm leaning towards 2, since this will probably be used to sync a scroll/view timeline with another effect that can't be done with CSS, e.g.: canvas, SVG, video.
So, I think that as default behavior, having this perform as a sort of "manual" CustomEffect, with a clamped progress like KeyframeEffect's is a good way to start, and we could add a new property in the future, like you said, to reflect the more complex cases.
I agree that 2 makes most sense. I also think, as per the current PR, we shouldn't try to reflect the fill mode of the associated effect.
However, if we consider the above use-cases, having enter/exit events on the animations, similar requested by @bramus on #7962 may become quite crucial for easily creating such effects without extra IntersectionObserver or scroll
handler.
Although you can currently get a similar outcome with start
/end
events on CSS Animations like here: https://jsbin.com/jizahopixe/edit?css,js,console,output
I think it's currently not possible to achieve with WAAPI.
We could also resolve on adding start/end events on elements as per #9011 which should also help there
I'll agenda+ this issue so we can get a formal resolution on the question on whether to clamp to [0,1].
Perhaps we should extract the idea of checking/specifying an effect in a before/after state?
Currently it requires hacks to achieve this, like setting delay: 1ms; play-state: paused
for before.
For WAAPI you have to play and pause immediately.
If it helps, I can add an example from a research we started on doing exactly what I mentioned above:
I'm leaning towards 2, since this will probably be used to sync a scroll/view timeline with another effect that can't be done with CSS, e.g.: canvas, SVG, video.
Here: https://codepen.io/ydaniv/pen/VwNraKB - trying to scrub a <video>
's progress in-sync with a ScrollTimeline
(spoiler: it doesn't work, at least OOTB). This is the kind of usages I think we'll mostly see for this API.
The CSS Working Group just discussed [web-animations-2] Progress APIs
, and agreed to the following:
RESOLVED: Clamp progress to [0,1]
Got some feedback that having AnimationEffect.getComputedTiming().progress
and Animation.progress
which mean different things could be confusing.
Could we consider renaming progress
?
Perhaps totalProgress
to reflect that it accounts for all the animation's iterations as opposed to AnimationEffect.getComputedTiming().progress
which only accounts for the current iteration's progress.
Perhaps currentProgress
would better align it with currentTime
? I think we should also consider that if we want to later expose the effect phase (i.e. before/active/after), so if we went with currentProgress
, currentPhase
would make sense.
I like Rob’s suggestion
I don't know, IMHO, currentProgress
looks awkward. And don't really think that those specifically meed to be consistent. I've seen usage of progress
in libraries before. time
by itself could be ambiguous, like start
orend
, but don't think progress
is.
The concern isn't that progress
itself is confusing, it's that myAnimation.effect.getComputedTiming().progress
means one kind of progress, while myAnimation.progress
means a different kind, and nothing in the names indicates the difference. I actually think it'd be ideal for getComputedTiming().progress
to mention that it's the iteration's progress, but since that has been shipping for several years, I don't see much prospect for getting it renamed.
I'm not sure that currentProgress
expresses the relevant difference here either (where totalProgress
would), but the WG knows better than I do what context authors are likely to have when reading this code, and whether "current" is going to inspire the right intuition.
The CSS Working Group just discussed [web-animations-2] Progress APIs
, and agreed to the following:
RESOLVED: change Animation.progress to Animation.overallProgress
Can we add these APIs to CSS?
Can we add these APIs to CSS?
Do you mean to the CSSAnimation
interface? It inherits from Animation
, so naturally yes.
I'm making the required WPT change also in https://github.com/web-platform-tests/wpt/pull/49353.
In #8669, #8765 and #8201 there seems to be a common desire to have more convenient APIs for getting some representation of progress. Currently you can get the progress of the current iteration of an effect using the getComputedTiming() API as follows:
You can also get the overall effect progress by doing a calculation such as:
However, with several of the other linked issues it seems that it would be convenient for developers to have some form of access to the progress through the attached animation range, or to get that progress directly from the timeline.
We could add a convenience currentProgress helper alongside the currentTime API on Animation:
This could return the progress of currentTime through the entire range before which it is considered complete, e.g. calculated as follows:
currentProgress = currentTime / effect endTime
Note that endTime is infinite when either iterations or duration is infinite. In these cases currentProgress should probably be null or undefined?
Open question - should it be read only or should we allow setting the progress which would be equivalent to setting currentTime to currentProgress * endTime?
As per discussion on #8669 a progress reported on animation should be mostly independent of the effect timing, so we calculate it as the progress from startTime to the time when the animation would resolve its finished promise. This would intentionally not match the progress through the developer specified keyframes.
@birtles @bramus @fantasai
I also propose that given the uncertainty around what's expected from the
getCurrentTime
API on timeline, that we remove it until we have a better understanding of the specific use cases that developers need it for. Perhaps the animation progress API above will address some of them where it seems developers were trying to work this out through the timeline.