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

Nested animated.div on leave #98

Open
SugarDarius opened this issue Mar 19, 2018 · 0 comments
Open

Nested animated.div on leave #98

SugarDarius opened this issue Mar 19, 2018 · 0 comments

Comments

@SugarDarius
Copy link

Hi !

I've got an issue when my component leave on nested animated.div.

Here's my code :

import TransitionGroup                                      from 'react-transition-group/TransitionGroup';

class RouteTransition extends Component {
    constructor(props) {
        super(props);

        this.state = {
            animate: new Animated.Value(0)
        };
    }

    componentWillEnter(cb) {
        setTimeout(() => {
            Animated.spring(this.state.animate, {
                toValue: 1,
                bounciness: 0,
                velocity: 1.2
            }).start();
        }, 10);

        cb();
    }

    componentWillLeave(cb) {
        Animated.spring(this.state.animate, {
            toValue: 0,
            bounciness: 0,
            velocity: 1.2
        }).start();

        setTimeout(() => { cb(); }, 450);
    }

    render() {
        const { children } = this.props;

        return (
            <Animated.div
                className='transition-motion-component-box'
                style={{
                    opacity: Animated.template`${this.state.animate}`
                }}
            >
                <Animated.div
                    className='transition-motion-component-box__translate-box'
                    style={{
                        transform: Animated.template`
                            translate3d(${this.state.animate.interpolate({
                                inputRange: [0, 1], outputRange: [`${window.innerWidth}px`, '0px']
                            })}, 0, 0)
                        `
                    }}
                >
                    {React.Children.only(children)}
                </Animated.div>
            </Animated.div>
        );
    }
}

<TransitionGroup component={TransitionGroupComponent}>
    <RouteTransition>
        <Route
            exact={exact}
            path={path}
            render={render}
        />
    </RouteTransition>
</TransitionGroup>

When the component RouteTransition enter everything is okay. The first Animated.div performs the animation of the opacity from 0 to 1 and the second Animated.div performs the animation of the translate3d on x from window.innerWidth to 0.

The problem occurs when the component leave. The animation of the opacity is good, I see it well but the animation of translate3d is completely ruined. The second Animated.div don't performs his animation and disappears in a blink. I don't really understand why.

Can you help me ?

Many thanks,
Aurélien

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant