Commit b3abf3a1 authored by Gaëtan Renaudeau's avatar Gaëtan Renaudeau

migrate AnimatedHelloGL to use Animated value

parent 3efbab54
...@@ -30,7 +30,7 @@ class Banner extends React.Component { ...@@ -30,7 +30,7 @@ class Banner extends React.Component {
return <Surface width={width} height={height} opaque={false} return <Surface width={width} height={height} opaque={false}
onLoad={() => console.log("Banner onLoad")} onLoad={() => console.log("Banner onLoad")}
onProgress={e => console.log("Banner onProgress", e.nativeEvent)}> onProgress={e => console.log("Banner onProgress", e.nativeEvent)}>
<GL.Node shader={shaders.banner} uniforms={{ time: time }} /> <GL.Node shader={shaders.banner} uniforms={{ time }} />
</Surface>; </Surface>;
} }
} }
......
const React = require("react-native"); const React = require("react-native");
const GL = require("gl-react"); const GL = require("gl-react");
const {Surface} = require("gl-react-native"); const {Surface} = require("gl-react-native");
const {Animated} = React;
const shaders = GL.Shaders.create({ const shaders = GL.Shaders.create({
helloGL: { helloGL: {
...@@ -21,20 +22,15 @@ class HelloGL extends React.Component { ...@@ -21,20 +22,15 @@ class HelloGL extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
this.state = { this.state = {
value: 0 value: new Animated.Value(0)
}; };
} }
componentDidMount () { componentDidMount () {
const loop = time => { const loop = () => Animated.sequence([
this.raf = requestAnimationFrame(loop); Animated.timing(this.state.value, { toValue: 1, duration: 1000 }),
this.setState({ Animated.timing(this.state.value, { toValue: 0, duration: 1000 })
value: (1 + Math.cos(time / 1000)) / 2 // cycle between 0 and 1 ]).start(loop);
}); loop();
};
this.raf = requestAnimationFrame(loop);
}
componentWillUnmount () {
cancelAnimationFrame(this.raf);
} }
render () { render () {
const { width, height } = this.props; const { width, height } = this.props;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment