AnimatedHelloGL.js 990 Bytes
Newer Older
1 2 3
import React, {Animated} from "react-native";
import GL from "gl-react";
import {Surface} from "gl-react-native";
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

const shaders = GL.Shaders.create({
  helloGL: {
    frag: `
precision highp float;
varying vec2 uv;

uniform float value;

void main () {
  gl_FragColor = vec4(uv.x, uv.y, value, 1.0);
}
    `
  }
});

class HelloGL extends React.Component {
  constructor (props) {
    super(props);
    this.state = {
24
      value: new Animated.Value(0)
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
25 26 27
    };
  }
  componentDidMount () {
28 29 30 31 32
    const loop = () => Animated.sequence([
      Animated.timing(this.state.value, { toValue: 1, duration: 1000 }),
      Animated.timing(this.state.value, { toValue: 0, duration: 1000 })
    ]).start(loop);
    loop();
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
33 34 35 36
  }
  render () {
    const { width, height } = this.props;
    const { value } = this.state;
37 38 39 40 41 42
    return <Surface width={width} height={height}>
      <GL.Node
        shader={shaders.helloGL}
        uniforms={{ value }}
      />
    </Surface>;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
43 44 45 46
  }
}

module.exports = HelloGL;