react-spring icon indicating copy to clipboard operation
react-spring copied to clipboard

Problem With Transition !!!

Open kryptonian41 opened this issue 8 years ago • 4 comments

This is what's happening, only the loader fades in and out the other component just get in and out normally. And also distorts the whole layout while the transition.

ezgif-2-d417a82282

Here is my code for the component: https://github.com/kryptonian41/sereact/blob/master/src/components/dashboard.js

kryptonian41 avatar Sep 02 '18 20:09 kryptonian41

Doesn't look like you pass on animation-styles in the Content component at all, also a little strange that Loader in your source uses "styles" Content uses "style".

Adapt this to your liking:

<Transition
  keys={dataLoaded}
  from={{ opacity: 0 }}
  enter={{ opacity: 1 }}
  leave={{ opacity: 0 }}>
  {dataLoaded
    ? style => <Content style={{ ...style, ...styles.contentContainer }}>dashboard</Content>
    : style => <Loader style={style} />}
</Transition>

Also make sure that Loader and Content can actually lay on top of one another (position: absolute for instance), otherwise they'll push each other away since Transition is can be a stack of elements, due to enter/exit transitions.

Check out some of the examples on the GH front-page, this isn't a problem with transition.

drcmda avatar Sep 02 '18 20:09 drcmda

Loader is my own component ... So I have set up a prop called styles inside it. Please check the loader.js file in the components folder of the repo. And Content is a component exported by ant design library which exposes a prop called style to use custom styles , so that's why the difference.

Also I passed the styles ... Sorry I don't know how I made this mistake ...

Also regarding stacking the components on top of each other. . I totally understand it ... But it will make my use of the components on the external ant design library very difficult as it will distort the flex layout... Is there any other way to achieve what I am trying to achieve here ... Without using absolute positioning ...?

And can I ask why you passed dataLoaded as the key prop to the Transition component ?

kryptonian41 avatar Sep 02 '18 23:09 kryptonian41

Loader is my own component

Sure, just looked a little off to me. The main reason was probably passing styles.

Also regarding stacking the components on top of each other.

You can also use a spring, it doesn't have to be a transition. It can even be faster since elements don't have to re-mount when they come in again. I personally do this even for sidebars. Other than that, transition isn't magic, it basically is a lifecycle preserver, the output stack it gives you is raw html, how you treat it or visualize it is up to you.

And can I ask why you passed dataLoaded as the key prop to the Transition component ?

When you don't specify a key it takes the function itself as a key, the full thing, as a string. It works but it's cleaner when you already have a atomic key.

drcmda avatar Sep 03 '18 07:09 drcmda

Okay, I got it and thanks for reciprocating so quickly.

kryptonian41 avatar Sep 03 '18 10:09 kryptonian41