Comments (4)
@AndreasFaust Each primitive can take in onRest
and onFrame
, the former triggers when the animation concludes, the latter triggers on every frame and gives you the current values. Keyframes are similar, internally they also just use these callbacks. The difference here is that keyframes can be awaited and chained, each promise yields the end-state values.
Try this:
console.log("start...")
return <Spring onFrame={v => console.log(v)} onRest={v => console.log("the end")} ...>
The start of the animation is yours anyway, since you are the one that triggers it by passing props to Spring.
As for transition, it has even deeper events:
<Transition
keys={item => item.key}
items={this.props.items}
from={item => console.log(item, "starts"}
enter={item => console.log(item, "enters"}
leave={item => console.log(item, "leaves"}
update={item => console.log(item, "updates"}
onFrame={item, v => console.log(item, "animates to", v}
onRest={item, v => console.log(item, "ends"} ...>
from react-spring.
Thank you very much for the quick reply!
I didn't know, that onFrame and onRest also apply to Transition. But how can I bind these events to certain Transition states only? I want to create a routing transition, where the next route is faded in, when the previous has faded out. For that I want to dispatch a redux action ("hasLeft") on "Transition leave rest" (and not "Transition enter rest"). To differ these states I could use the styles-property (if opacity === 0 for example), but that is not ideal. Or am I missing something?
I am asking, because in "React Move", I have been using in this case so far, these events exist.
from react-spring.
Actually i got that wrong myself, you're supposed to return the animation values in from/enter/leave/update, so that makes it possible to return individual values or listen to app state:
<Transition items={...} keys={...} from={...} enter={item => {
if (this.props.something) return ({ opacity: item.opacity })
else if (this.props.somethingElse) return ({ opacity: item.opacity / 2 })
else return ({ color: 'red' })
}} ...>
Transition.onRest generally is limited when it's being used in transitions since they doesn't really have an end and a beginning (they just watch lifecycles). You can use it, but Transition itself uses onRest when the element leaves, so it will overwrite your handler in that case. Play around with it all for a while and look if it fulfills your usecase already, if not we can probably think of something to make it possible.
If you don't get any further, a very reduced codesandbox focussed on the problem at hand would be a good starting point.
from react-spring.
Thanks for explaining, you helped me a lot!
Have a nice weekend!
from react-spring.
Related Issues (20)
- [bug]: Wrong source-maps
- [bug]: ./node_modules/@react-spring/shared/dist/react-spring_shared.legacy-esm.js 1023:7 HOT 3
- [bug]: update transform
- [bug]: react-spring Identifier 'React' has already been declared HOT 3
- [bug]: Incorrect tooltips in useTransition docs HOT 1
- [bug]: React-Spring.dev main website down HOT 1
- [bug]: useResize is jumpy
- [bug]: The leave option in config object behaves inconsistently when using useTransition HOT 1
- [bug]: Website with docs not working in chrome (120.0.6099.72) HOT 3
- [bug]: Documentation website is broken after the first visit on most desktop browser HOT 8
- [bug]: libc++abi: terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument HOT 1
- [bug]: It’s the same problem. There is no CSS style when visiting the website. HOT 1
- [bug]: Animation did not run when using useSpring in next 14 Dev Mode. HOT 1
- [bug]: styles are not updated when using useSprings in conjunction with deleting items from a list HOT 1
- [bug]: `Dynamic require of "react-native" is not supported` on react native web
- Parallax has double/inner scrollbar.
- [bug]: useTransition When uninstalling, double-clicking causes DOM destroy
- [bug]: animated.div exception removes the zeros from the end of the number.
- [feat]: UseSprings for Object
- [Feature][AzureDevOps GO/GitHub] Support extracting Azure Pipelines metrics from GitHub Repositories
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-spring.