GLCanvas.js 734 Bytes
Newer Older
1 2 3 4
const React = require("react-native");

const {
  Component,
5 6
  requireNativeComponent,
  NativeModules: { GLCanvasManager }
7 8 9 10 11 12 13 14 15
} = React;

const GLCanvasNative = requireNativeComponent("GLCanvas", GLCanvas);

class GLCanvas extends Component {
  constructor (props) {
    super(props);
  }
  captureFrame (cb) {
16 17 18 19 20 21
    GLCanvasManager.capture(
      React.findNodeHandle(this.refs.native),
      (error, frame) => {
        if (error) console.error(error); // eslint-disable-line no-console
        else cb(frame);
      });
22 23 24 25 26 27 28 29 30 31 32 33
  }
  render () {
    const { width, height, ...restProps } = this.props;
    return <GLCanvasNative
      ref="native"
      {...restProps}
      style={{ width, height }}
    />;
  }
}

module.exports = GLCanvas;