Skip to content
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

Add "exitBeforeEnter" prop to useTransition #1064

Closed
xzilja opened this issue Jun 21, 2020 · 7 comments · Fixed by #1773
Closed

Add "exitBeforeEnter" prop to useTransition #1064

xzilja opened this issue Jun 21, 2020 · 7 comments · Fixed by #1773
Assignees
Labels
kind: request New feature or request that should be actioned released in beta this has been released on a beta

Comments

@xzilja
Copy link

xzilja commented Jun 21, 2020

🚀 Feature Proposal

Add exitBeforeEnter property to useTransition hook. This property would be an optional boolean that when set will wait for "leave" animation to complete before starting "enter" animation of new element. Ideally we would also not need to worry about layout issues here and implement "hacks" like absolute positioning.

Motivation

I came across an issue similar to one described here #583
Essentially I want to create a page transition, where "initial" page fades out and only after it is not visible anymore "secondary" page fades in. This should be achievable without complex logic and delays.

Idea is taken from framer motion https://www.framer.com/api/motion/animate-presence/#animatepresenceprops.exitbeforeenter

I am down to try and implement this, but I am not sure where to start and if this is something that falls into the scope of the library.

Example

const transition = useTransition(toggle, {
   from: { opacity: 0 },
   enter: { opacity: 1 },
   leave: { opacity: 0 },
   exitBeforeEnter: true
});

// ...

transition((style, props) => {
  return <a.div style={style}>{toggle ? 🟢 : 🔴}</a.div> 
})
@xzilja xzilja added the kind: request New feature or request that should be actioned label Jun 21, 2020
@xzilja xzilja changed the title [Feature] add "exitBeforeEnter" prop to useTransition Add "exitBeforeEnter" prop to useTransition Jun 21, 2020
@tomdohnal
Copy link

tomdohnal commented Sep 15, 2020

This definitely is a pain point for me. It can now be "simulated" using the trail property and absolute positioning although it's not always ideal. Using position: absolute makes the parent element not take up the space of its children which can break the layout

Vue.js also offers similar functionality with "transition modes" https://vuejs.org/v2/guide/transitions.html#Transition-Modes

@tomdohnal
Copy link

I actually think that this functionality could be achieved just using the public react spring API, specifically using the onRest properties.

You could extract it into your own "useSwitch" or similar one.

I'll try to whip up a PoC and post a Codesandbox link here later this week

@tomdohnal
Copy link

@RemyMachado
Copy link

RemyMachado commented Feb 28, 2021

Here is a PoC
https://codesandbox.io/s/boring-shadow-v66x2?file=/src/App.js

First of all, thank you for your PoC!

It's a great workaround that uses the physic config! Unfortunately I struggle implementing it with a single component that should leave and enter on each prop changes like I explained here:
#583 (comment)

Do you think it's feasable with a single component? @tomdohnal

@joshuaellis
Copy link
Member

I've released this on 9.4.0-alpha.0. It is experimental i.e I did it in a hour because I need it for a work project, but if there are any obvious bugs you experience, please report them on here cause that will help me refine it into a stable addition! ⭐

@joshuaellis joshuaellis added the released in alpha this has been released on an alpha label Oct 15, 2021
@joshuaellis joshuaellis self-assigned this Oct 15, 2021
@joshuaellis joshuaellis linked a pull request Dec 1, 2021 that will close this issue
3 tasks
@joshuaellis joshuaellis added released in beta this has been released on a beta and removed released in alpha this has been released on an alpha labels Dec 1, 2021
@joshuaellis joshuaellis removed this from the v9.4.0 milestone Jan 3, 2022
cameron-martin pushed a commit to cameron-martin/react-spring that referenced this issue May 10, 2022
)

Co-authored-by: Neil Kistner <neil.kistner@gmail.com>
@yaroslavdraha
Copy link

yaroslavdraha commented Aug 1, 2022

@joshuaellis
Hi there! I'm experiencing a problem using useTransition and exitBeforeEnter, not sure if it's related to specifically this thread, but I will create a new bug if not.

My goal is to show two blocks and change them with a timeout (check the sandbox). For some reason, the animated components are gone when I change the tab in the browser for around 5 sec. I cannot reproduce that without exitBeforeEnter. Please help me, it's critical for my current project. Thank you ❤️

Codesandbox:
https://codesandbox.io/s/exitbeforeenter-removes-components-on-browser-tab-change-krs5jo

Video example
https://drive.google.com/file/d/1Pf1qfAI6FZxHlZPwwzVF_z49MZbHy3Vi/view?usp=sharing

@karenbanci
Copy link

Hello @yaroslavdraha ,

I'd like to know if your problem was solved.

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: request New feature or request that should be actioned released in beta this has been released on a beta
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants