cheapsteak / react-transition-group-plus

A more full-featured transition group for React
Other
268 stars 20 forks source link

Initial state on mount #13

Closed RanzQ closed 7 years ago

RanzQ commented 7 years ago

In the demo, the boxes start with opacity 0. How did you handle it? I'm having a problem with out-in transition since the incoming component starts with opacity 1.

It seems that the initial state is a common issue with React animations: https://github.com/facebook/react/issues/719

I've set up the animation like this:

    componentWillEnter (callback) {
      const el = findDOMNode(this)
      TweenLite.fromTo(el, options.enterDuration, {
        opacity: 0
      }, {
        opacity: 1,
        delay: options.enterDelay,
        onComplete: callback
      })
    }

And this works but seems like a hack to me. :)

    componentDidMount () {
      const el = findDOMNode(this)
      el.setAttribute('style', 'opacity: 0')
    }

But I guess this is the only way when setting the animation via a HOC.

cheapsteak commented 7 years ago

Yup, componentDidMount is indeed where I put it, you can see the code here :)

https://github.com/cheapsteak/react-transition-group-plus/blob/master/src/demo/animates/animates.jsx#L10-L23

RanzQ commented 7 years ago

@cheapsteak Thanks, don't know why I didn't find the demo source. :D