question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onAnimationEnd callback should be executed after content is hidden

See original GitHub issue

First of all, thanks for this lib!

I think onAnimationEnd callback should be executed after content is hidden because one may need to remove the content on the callback itself. I’ve just encountered this issue myself.

Right now, it is not possible to remove the animated content inside the onAnimationEnd callback in a synchronous way since your lib will complain when trying to access this.contentElement to hide the removed content.

captura de pantalla 2017-10-25 a las 18 33 32

By shifting the order in which content is hidden and onAnimationEnd callback is executed, we get the best of both worlds, don’t you think?

To workaround this limitation I’m making the removal operation asynchronous so your lib can hide content before removal but it’s a bit hacky for my taste.

Ping me if you want me to make a PR for you.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jakoandersencommented, Jul 12, 2018

Works like a charm, thank you once again!

For anyone interested, this was my final solution: (i don’t have a button that triggers the toggle, put a received prop (condition) via redux):

interface Props {
    dispatch: any;
    groupOption: GroupOption;
    condition: boolean;
}

interface State {
    hide: boolean;
    height: number | string;
}

class GroupConditionContainer extends React.PureComponent<Props, State> {

    componentWillReceiveProps(nextProps: Readonly<Props>, nextContext: any): void {
        this.setState({
            height: nextProps.condition ? 'auto' : 0,
            hide: false
        });
    }

    constructor(props: Props) {
        super(props);
        this.state = {
            height: props.condition ? 'auto' : 0,
            hide: !props.condition
        };
    }

    render() {
        const { height, hide } = this.state;

        return (
            <AnimateHeight
                duration={500}
                height={height}
                animateOpacity={true}
                onAnimationEnd={() => {
                    if (height === 0) {
                        this.setState({ hide: true });
                    }
                }}
            >
                {!hide && this.props.children}
            </AnimateHeight>
        );
    }
}
0reactions
Stankocommented, Jul 12, 2018

Try this: https://codesandbox.io/s/mm6yy0llv9

I was writing the previous snippet out of my head. But thank you, as I discovered a tiny bug I introduced with v2.

Cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I launch an Android animation in the onanimationEnd ...
I am attempting to launch one animation after another has finished by monitoring the onanimationEnd callback of the first one. However Android gives...
Read more >
Element: transitionend event - Web APIs | MDN
The transitionend event is fired when a CSS transition has completed. In the case where a transition is removed before completion, ...
Read more >
Animated - React Native
The Animated library is designed to make animations fluid, powerful, ... completion callback that will be called when the animation is done.
Read more >
WebView - Android Developers
To learn more about WebView and alternatives for serving web content, ... Called after onStartTemporaryDetach() when the container is done changing the view ......
Read more >
react-animate-height | Yarn - Package Manager
Slide an element up and down or animate it to any specific height. Content's opacity can be optionally animated as well (check animateOpacity...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found