View.js 1.41 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
const {createView} = require("gl-react-core");
const React = require("react-native");
const Shaders = require("./Shaders");
const Target = require("./Target");
const Component = require("./Component");

const {
  requireNativeComponent,
  View,
} = React;

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

const renderVtarget = function (style, width, height, id, children) {
  const childrenStyle = {
    position: "absolute",
    top: 0,
    left: 0,
    width: width,
    height: height,
    overflow: "hidden"
  };
  return <View style={[ childrenStyle, style ]}>{children}</View>;
};

26
const renderVGL = function (props, width, height, data, nbTargets, renderId) {
27 28 29
  return <GLCanvas
    ref="native"
    {...props}
30
    style={[ props.style, { width, height } ]}
31 32
    data={data}
    nbTargets={nbTargets}
33
    renderId={renderId}
34 35 36 37 38
  />;
};

const renderVcontainer = function (style, width, height, targets, renderer) {
  if (targets) {
39
    const parentStyle = [ style, {
40 41 42 43
      position: "relative",
      width: width,
      height: height,
      overflow: "hidden"
44
    }];
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    return <View style={parentStyle}>
      {targets}
      {renderer}
    </View>;
  }
  else {
    return renderer;
  }
};

const GLView = createView(React, Shaders, Target, Component, renderVcontainer, renderVtarget, renderVGL);

GLView.prototype.setNativeProps = function (props) {
  this.refs.native.setNativeProps(props);
};

module.exports = GLView;