-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surma,
I hope you don't feel too beat up by this. Your writing is always pretty clean of typos and easy to understand. What I hope you notice is that my suggestions are about writing simpler sentences and removing words that don't contribute meaning.
@@ -0,0 +1,493 @@ | |||
project_path: /web/_project.yaml | |||
book_path: /web/updates/_book.yaml | |||
description: Houdini’s Animation Worklet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy the snippet to here.
**TL;DR:** Animation Worklet allows you to write imperative animations that run | ||
at the device's native frame rate for that extra buttery jank-free smoothness™, | ||
make your animations more resilient against main thread jank and can be linked | ||
to scroll instead of time. Animation Worklet is in Chrome Canary (behind the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to: 'and are linkable to scrolling instead of time.'
|
||
## Another Animation API? | ||
|
||
Actually no, it is an extension of what we've already have, and with good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"we've" to "we".
## Another Animation API? | ||
|
||
Actually no, it is an extension of what we've already have, and with good | ||
reason! Bear with me, let's start at the beginning: What do we have? If you want |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete 'Bear with me,'. Change rest to: 'Let's start at the beginning. If you want...'
simple A to B transitions, [CSS | ||
Animations](https://developer.mozilla.org/en-US/docs/Web/CSS/animation) for | ||
potentially cyclical, more complex time-based animations and [Web Animations | ||
API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API) (or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete 'or'.
thread or run in a separate thread in sync with the compositor. | ||
|
||
Note: You should try avoiding "slow" properties at all costs. Limit yourself to | ||
animation `opacity` and `transform` to make sure your animations run smooth even |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'smooth' to 'smoothly'
access to all the new goodness at the same time. | ||
|
||
Animation Worklet is in Canary and we are aiming for an Origin Trial with Chrome | ||
69. We are eagerly awaiting you to build great new experiences on the web and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're 6 days from 70 going to stable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. The more accurate timeline is that it will be in origin trial for 71. Time flies.
access to all the new goodness at the same time. | ||
|
||
Animation Worklet is in Canary and we are aiming for an Origin Trial with Chrome | ||
69. We are eagerly awaiting you to build great new experiences on the web and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to 'We are eagerly awaiting your great new web experiences and hearing about what we can improve.'
69. We are eagerly awaiting you to build great new experiences on the web and | ||
telling us about your experiences and what we can improve. There is also a | ||
[polyfill](https://github.com/GoogleChromeLabs/houdini-samples/blob/master/animation-worklet/anim-worklet.js) | ||
that gives you the same API, but doesn't provide the performance isolation.tion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete 'tion.'
[polyfill](https://github.com/GoogleChromeLabs/houdini-samples/blob/master/animation-worklet/anim-worklet.js) | ||
that gives you the same API, but doesn't provide the performance isolation.tion. | ||
|
||
Keep in mind that CSS Transitions and CSS Animations are still very valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete 'very'
second you start scrolling up, it comes back into view, even if you are half way | ||
down that page. The animation depends not only on scroll position, but also on | ||
your previous scroll direction. It is _stateful_. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting example. I think there are two different things at play in this example:
- Direction itself is a state: to compute direction one needs to know the previous scroll position.
- You can think of this animation effect as if it is trying to keep the address bar attached to a particular baseline position as page is scrolled. In this model, the baseline position is also state.
Here is how the animation behaves:
- A) page is scrolling up (swipe down gesture) and address bar is fully shown => do not move the address bar and instead reset the baseline position.
- B) page is scrolling down (swipe up gesture) or address bar is not fully shown => move the address bar as if it is attached to the baseline position.
- C) scrolling is finished (i.e., animation) => reset the baseline to top of the document (so next time if user is scrolling up) it starts coming back into view.
Here both A & C are updating the state but there is a subtle difference: only (A) requires the animation itself to be stateful. (C) can be achieved even if state is kept outside the animation.
I think the example you gave 'But the second you start scrolling up, it comes back into view, even if you are half way down the page' is highlighting (C) but I think the case is more clear if we highlight (A) instead. Honestly this is a subtle distinction and maybe not worth trying to clarify.
Also perhaps worth making it clear that computing direction itself requires state (i.e., previous position). Another example of this is "velocity".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are technically correct. I’d like to lead this with a visual example of statefulness, even if the actual state is something else. When people start building this, they will hopefully discover what to do :D
// Some math to make sure that `localTime` is always > 0. | ||
effect.localTime = 2000 + this.direction * (currentTime % 2000); | ||
} | ||
destroy() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have resolved to move away from having a destroy hook. Instead the plan is to have the state as a property the class. However this is not been implemented or specc'ed.
We also plan to have the statefullness be clearly stated via a parent class that should be extended.
So I think the ultimate syntax will be something like.
registerAnimator('randomspin', class MyEffect extends StatefulAnimator {
constructor(options = {}, state = {}) {
this.direction = state.direction || (Math.random() > 0.5 ? 1 : -1);
}
animate(currentTime, effect) {
// Some math to make sure that `localTime` is always > 0.
effect.localTime = 2000 + this.direction * (currentTime % 2000);
}
get state() {
return {
direction: this.direction
};
}
}
Given however that this is not yet specc'd (my bad 😢 ), perhaps it is fine to talk about destroy
hook and then have a note with a link to potential changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol. I will add a note for now and update the article once it’s specced and landed :)
af2590d
to
3ce6963
Compare
Joe, I 100% appreciate you taking the time to give this monster an in-depth review. Thank you very much. Waiting for a LGTM from @petele and then this is probably good to go :) |
3ce6963
to
ec97e7d
Compare
Note: You should avoid "slow" properties at all costs. Limit yourself to | ||
animation `opacity` and `transform` to make sure your animations run smoothly | ||
even on slow devices. Currently, Chrome's implementation doesn't even allow you | ||
to animate slow properties with AnimationWorklet and will throw a warning at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now support slow properties in AnimationWorklet. They just run in sync with main thread. So they still have to be avoided. Here is a demo of width animating with a worklet.
Also we are actually going to remove the warning from devtools. We feel it is a bit spammy and not appropriate for console. We should instead expose this in devtools elsewhere (e.g., in animations panel). So maybe not mention this.
Whoops! There were 2 warnings that will prevent this PR from being merged. Please take a look, and either fix, or provide a justification for why they can't be fixed. WARNINGS |
🎉 This has been pushed live to https://developers.google.com/web/ |
What's changed, or what was fixed?
Target Live Date: ASAP
npm test
locally and all tests pass.type-something
label.CC: @petele @jpmedley @majido @flackr
@petele PTAL, specifically at videos and the code-in-tables situation :)