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

Animating an array of values (clip-path) #85

Open
benjamingeorge opened this issue Dec 24, 2017 · 0 comments
Open

Animating an array of values (clip-path) #85

benjamingeorge opened this issue Dec 24, 2017 · 0 comments

Comments

@benjamingeorge
Copy link

I'm using Animated on the web. I am animating an array of values but I would like to be able to handle a dynamic amount of "points" in a clip-path. I can't seem to find a way to assemble a dynamic Animated.template string. Is there a way to do this that is not hardcoding references like i'm doing here in the render function?

class App extends Component {
    startPoints = [0, 0, 100, 0, 100, 100, 0, 100];
    endPoints = [0, 0, 33, 0, 33, 100, 0, 100];

    anims = this.startPoints.map(coord => new Animated.Value(coord)); 

    animate = () => {
        const ends = this.anims.map((anim, i) =>
            Animated.timing(anim, {
                toValue: this.endPoints[i],
                duration: 300
            })
        );

        Animated.parallel(ends).start();
    };

    render() {
        const styles = {
            clipPath: Animated.template`polygon(${this.anims[0]}% ${
                this.anims[1]
            }%, ${this.anims[2]}% ${this.anims[3]}%, ${this.anims[4]}% ${
                this.anims[5]
            }%, ${this.anims[6]}% ${this.anims[7]}%)`
        };

        return (
            <Animated.div
                className="container"
                style={styles}
                onClick={this.animate}
            >
                <img src="./run.jpg" />
            </Animated.div>
        );
    }
}
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