plus1tv / react-anime

✨ (ノ´ヮ´)ノ*:・゚✧ A super easy animation library for React!
https://codepen.io/collection/nrkjgo/
MIT License
1.55k stars 81 forks source link

props.children not working properly in react-anime.js? #36

Open ruizj-ibm opened 6 years ago

ruizj-ibm commented 6 years ago

I am having an issue when the props.children change for an <Anime>.

To solve my issue, I made this change to function componentWillReceiveProps in react-anime.js file:

this.children = {
        /*
        cur: children.filter(function (c) {
          return difChildren.indexOf(c) < 0;
        }),
        */
        cur: children,
        prev: childrenWereRemoved ? difChildren : this.children.prev,
        next: !childrenWereRemoved ? difChildren : this.children.next
      };

For some reason, the filter was returning zero children, even though there was a child component.

I am using anime like this;

//inside parent component
<FadeIn>{messageWords}</FadeIn>

let FadeIn = props => {
    return (
        <Anime easing="linear"
            autoplay={true}
            duration={500}
            direction="normal"
            loop={false}
            opacity={[0, 1]}
            delay={(el, index) => ((index * 200) + 1500)}>
            {props.children}
        </Anime>
    )
}
JordynMarcellus commented 6 years ago

+1 on this -- discovered this while playing with react-anime today.

Thanks @ruizj-ibm for the fix, it seems to have solved my issue!

jaylocke commented 6 years ago

+1 the same problem