-
Notifications
You must be signed in to change notification settings - Fork 0
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
Animations #11
Comments
@dariocravero Just FYI, after discussing with @tomatuxtemple we've decided to remove |
Hello, I've got a bit of a problem. 😬 So on native (well on both really, but lets look at one at a time 🙈) For example with this view
This is what i have so far ...
So its generating unique animated values for the different scopes, it's assigning them to the correct attributes in the style property and it's using the correct animated values in timing or spring but I have this...
Which obviously can't work because I have duplicates of the same attributes 😭 So I tried this instead...
where
But then it's only animated the first time I change to I feel like I'm going to have the same problem in implementing CSS vars on DOM... At the moment, I'm generating unique variable names like so...
Which is grand but I don't know how I'm going to handle it in the styled component...
Here's a sandbox of the issue on native. |
That's some tricky stuff :). I tinkered here with a few variations of it but it doesn't quite do what you wanted to do there https://snack.expo.io/@dariocravero/multiple-scopes. I stored the from/to colour in the state in that example. It helps a bit but it doesn't do exactly what you're after. Maybe we can try using the same animated value for the same prop? Let me try a few alternatives and come back to you on that. I'll cc @tomatuxtemple because maybe we don't even want to go this far, at least not now :). |
Reference implementation of the comment above https://snack.expo.io/H1SgJMd9f |
Until we get a chance to write up on the next iteration of animations to enable animations on mount and unmount, here is a sample project that may come in handy for it before I loose it again hehe. The upcoming syntax would deal with system scopes like
|
const Button1 = css({
label: 'Button1',
transformOrigin: 'left top',
transition: 'background-color 150ms linear 0ms',
willChange: 'transform, background-color',
transform: 'scale(var(--scale))',
backgroundColor: 'var(--backgroundColor)',
})
class Button extends React.Component {
state = {
hoverButton: false,
}
render() {
const { props, state } = this
return (
<Spring
native
from={{ scale: 1 }}
to={{ scale: state.hoverButton ? 2.5 : props.isActive ? 1.75 : 1 }}
config={{
speed: 12,
bounciness: 12,
}}
delay={0}
onRest={() => {
props.onAnimationDone({
scope: 'isActive',
props: ['scale'],
})
}}
>
{spring => (
<animated.button
data-test-id={`${props['data-test-id'] || 'Button'}|${
props.isActive ? 'isActive|' : ''
}`}
onMouseOver={() => this.setState({ hoverButton: true })}
onMouseOut={() => this.setState({ hoverButton: false })}
onClick={props.onClick}
onTransitionEnd={() => {
if (props.onAnimationDone) {
props.onAnimationDone({
scope: 'isActive',
props: ['backgroundColor'],
})
}
}}
style={{
'--scale': spring.scale,
'--backgroundColor': `${
props.isActive ? 'deepskyblue' : 'purple'
}`,
}}
className={`views-block ${Button1}`}
>
<span data-test-id={`Button.Text|`} className="views-block">
{props.text}
</span>
{props.children}
</animated.button>
)}
</Spring>
)
}
} |
Closing for now as we have the initial phase of animations done :) and we have other issues to track specific bits and pieces that we want to do later! |
Here's a summary of the first session on animations we did with @tomatuxtemple:
We want animations in Views to be easy to compose. As with any other feature of the language, the morpher should take care of doing the best animation possible for web and native while using the same code to produce it. It's a big challenge, in particular because springs don't exist on CSS transitions but we need to start somewhere, so let's iterate on a first version that gets animations in and we can improve the morphing later.
As a first step, we want to introduce animations in block scopes.
Animations will be added to a prop at the end of the value like:
color red linear duration 150
We'd like to use named values so that you don't need to mind the order. These are the values we want to support:
order (defaults to 0, meaning all values animate at the same time). Takes a number specifying the order in which the animation is supposed to trigger. The rest of the values in the same scope should wait for it to be done before starting.spring
(taken from React Native's Animated docs):stiffness (defaults to 100).damping *defaults to 10) defines how the spring’s motion should be damped due to the forces of friction.linear
,ease-out
, etc:The parser would have to clear out any animation values off the prop and attach those as metadata to it. This is a good point to get started with. We do all that parsing in the helpers.
We could make the curve the first parameter that tells the beginning of the animation. So if you have a complex prop like
boxShadow
there's no issue to parse it, eg:boxShadow 0 10px 10px red spring friction 10
. Even in that complex case we know where the animation starts.Then the morpher would generate the code we see below.
For React Native, see:
For React DOM, see:
Here's the example view we use on the video (we replaced
timing
forduration
after recording the video).Web example:
View with Emotion CSS in Codesandbox.
We could potentially support springs in web with keyframes and css-spring. The thing is that animation and transition in CSS are conceptually different for the browser and the starting state of animation would require more messing with the code, but it's definitely something worth looking at.
Here's a sandbox with an example - the result isn't all that great for this spring, it might be my choice of props to animate though :). It should be possible to use only one animation but it needs some extra stuff.
It should be possible to use https://github.com/animatedjs/animated too but I think that the react-emotion component would have to be tweaked for that to be the case. Also, JS animations aren't as performant as CSS ones yet, so they may feel a bit janky. However, it could be a good starting point since it makes the animation layer common. Here's an example using almost the same code that we used in RN below with in Web https://codesandbox.io/s/n0oyk8kzv0.
I don't know how we'd go about hover effects for instance in that scenario since the styles are inline. Here's an alternative approach using css variables instead https://codesandbox.io/s/2p5qrr584n! It won't work on IE11 but it's probably worth the tradeoff since it works with hovers!
Native example (same but with spring because that already works in Animated as is):
Expo Snack to try it out with the generated code.
We still need to cover block, list and view animations in further sessions but this should be enough to get something started.
The text was updated successfully, but these errors were encountered: