Skip to content

Animations not smooth and equal timeout causes flicker #157

@webchaz

Description

@webchaz

This is the animation I'm using, taken from animate.css.

@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }

  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes fadeOutLeft {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
  }
}

.fadeLeft-enter {
  animation-name: fadeInLeft;
  animation-duration: 400ms;
}

.fadeLeft-enter.fadeLeft-enter-active {
  animation-name: fadeInLeft;
  animation-duration: 400ms;
}

.fadeLeft-exit {
  animation-name: fadeOutLeft;
  animation-duration: 400ms;
}

.fadeLeft-exit.fadeLeft-exit-active {
  animation-name: fadeOutLeft;
  animation-duration: 400ms;
}

I'm then using the react transition group with react-router:

<TransitionGroup>
    <CSSTransition
        key={this.props.location.key}
        classNames='fadeLeft'
        timeout={300}
        mountOnEnter={true}
        unmountOnExit={true}
    >
    <div>
      <Switch location={this.props.location}>
        <Route path='/one' exact component={Primary} />
        <Route path='/one/two' exact component={Secondary} />
      </Switch>
    </div>
  </CSSTransition>
</TransitionGroup>

I set the timeout here to 300, if I set it to 400 to match the animation duration, I get flickering where the animation seems to complete but the component is left behind and flashes quickly. I'm not sure exactly what the right "formula" is to avoid this or if my animations are incorrect for the different transition states.

So my question is how should the timeout be set with this kind of animation to avoid flickering and smooth transition?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions