index.js 1.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
import React, {Component} from "react";
import {View, Animated } from "react-native";
import {AnimatedSurface} from "gl-react-native";
import GL from "gl-react";
import Dimensions from "Dimensions";
const { width: viewportW, height: viewportH } = Dimensions.get("window");

export default class Tests extends Component {
  state = {
    heightValue: new Animated.Value(200)
  };
  componentWillMount () {
    let i = 0;
    this.interval = setInterval(() => {
      Animated.spring(this.state.heightValue, {
        toValue: ++i % 2 ? 500 : 200,
      }).start();
    }, 1000);
  }
  componentWillUnmount () {
    clearInterval(this.interval);
  }
  render () {
    const { heightValue } = this.state;
    return <View style={{
        backgroundColor: "#000",
        flex: 1,
        paddingTop: 60,
        alignItems: "center"
      }}>
      <AnimatedSurface
        width={200}
        height={heightValue}>
        <GL.Node shader={{
            frag: `
precision highp float;
varying vec2 uv;
void main () {
  gl_FragColor = vec4(uv.x, uv.y, 0.5, 1.0);
}
            `
          }}
        />
    </AnimatedSurface>
    </View>;
  }
}