-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: useTransition rewrite #809
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
Conversation
TodoQuestions
Ideas
|
78bc5a5 to
672393e
Compare
|
Feature proposal for the new
A real-world use case for (1) above is when animating an interactive chart. Use a Spring value to animate the chart's x/y axis, while // Pass the animated value `x` to the `expires` prop of transition,
// so that the unmount event can wait for the X-axis animation to rest,
// instead of in the middle of X-axis animation.
const [{ x }, setAxis] = useSpring(() => { x: 100 });
const transition = useTransition(elements, { ...props, expires: [x] }); |
7ff0d8d to
0d71b81
Compare
423592a to
bef8d1c
Compare
d6baddb to
1854f36
Compare
f9ab364 to
4dea3e1
Compare
1854f36 to
1a2be58
Compare
aa2db98 to
6b3a7c0
Compare
|
@aleclarson My apologies. Don't know why I thought I was linking a new sandbox. I am indeed working from the code you linked. I cannot prevent it from running the last line in the If I comment out that line, then |
|
@aleclarson Just now saw your edit. I tried it, but it still runs
|
|
@Lynges Yeah that's a bug I'm looking into now. My suggested edit was still wrong though, for other reasons. Give me a minute to figure this out. :) |
|
@Lynges Ok, sorry for the wait. Things got a little tricky (and I was distracted by the React Conf stream 😜), but 6 fixes later, everything should work as expected. Add the following prop to the onRest: ({ finished }) => finished && cancelMap.get(item)()Note: You'll need to install
|
|
Thanks a bunch @aleclarson :) Got it all working. Found a couple of things with regards to when the components are re-rendered. I will do some more digging on Monday to see if it's just my code or something that might be relevant. |
|
I still don't understand how to toggle with new useTransition |
|
@dellwatson Hi, the following should work if you pass the proper index but there might be better options : const items = ['😄',' 🤪']export default () => {
const [toggled, setToggled] = useState(false)
const transition = useTransition(items[+toggled], {
from: { opacity: 0 },
enter: { opacity: 1 },
})
return (
<>
<button onClick={() => setToggled(!toggled)}>Switch please</button>
<div className="simple-trans-main">
{transition((values, item) => (
<animated.div style={values}>{item}</animated.div>
))}
</div>
</>
)
}Live example here : https://codesandbox.io/s/eager-cerf-r78kw |
|
Does |
|
@Inviz Which version are you using? |
|
Hi @aleclarson, I am trying the latest canary. My question : is there any effect if I set the I want to reverse the transition animation from last item to first item instead of first item to last item like usual and it seems that option is not working at all Thank you in advance! |
This PR is a rewrite of
useTransitionfrom scratch in hopes of simplifying both the API and the internals. Here's an example of the new API:Once #670 is merged, you can pass a deps array and you'll get the
updateandstopfunctions returned to you:Also, the
Transitioncomponent has changed. Itschildrenprop now takes different arguments:Notable changes
keysargument is now thekeypropkeyprop is optional for primitive items and mutable object itemstransitionfunction instead of atransitionsarraykeyprop set for you automaticallyphaseisn't exposed to the user anymoreuniqueprop was removed for simplification)lazyprop was removed in favor ofexpires)props.onFrame), but you can still pass them in specific phases (eg:props.enter.onFrame)resetprop now uses theinitialprop if it existsonDestroyedprop was removed (was there a good use case for this?)orderprop was removedNew
keypropAlias:
keysWhen immutable objects are passed as items, they need explicit keys in order to reconnect them with any existing transitions.
For an array of immutable objects, pass a function that maps over the array and returns the unique id of each item...
... or pass an array of keys.
For a single immutable object, you can pass its key directly (no function required).
New
expirespropFor controlling when deleted items are dismounted after their leave animation finishes. Set to
0for immediate dismount. By default, dismounting is postponed until (1) next render, or (2) all transitions are resting. Any value above0is interpreted as "milliseconds to wait before dismounting is forced".