Skip to content

v2.1.1

Compare
Choose a tag to compare
@gre gre released this 18 Jan 20:36
· 510 commits to master since this release

Experimental support of Animated object

gl-react-native 2.18.0 has been released with an experimental support for Animated object on uniforms.

A simple example is this HelloGL component:

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 = {
      value: new Animated.Value(0)
    };
  }
  componentDidMount () {
    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();
  }
  render () {
    const { width, height } = this.props;
    const { value } = this.state;
    return <Surface width={width} height={height}>
      <GL.Node
        shader={shaders.helloGL}
        uniforms={{ value }}
      />
    </Surface>;
  }
}

Notice how this no longer requires to loop over render(). This allows to get even better performance for animations, removing the need of complex diffing but instead directly building the data object and calling setNativeProps. Animated is also very smooth, here is an example of profiling:

Without animated (5.7ms)

screen shot 2016-01-18 at 21 32 44

After animated (4ms)

screen shot 2016-01-18 at 21 29 57

This should also work in gl-react-dom as long as you implement a local web version of Animated. We will eventually have it.

Internal refactoring to simplify the duck-typing logic of uniform values

see this commit for more detail