View.js 1.36 KB
Newer Older
1 2 3
const {createView} = require("gl-react-core");
const React = require("react-native");
const Shaders = require("./Shaders");
4
const Uniform = require("./Uniform");
5 6 7 8 9 10 11 12

const {
  requireNativeComponent,
  View,
} = React;

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

13
const renderVcontent = function (width, height, id, children, { visibleContent }) {
14 15
  const childrenStyle = {
    position: "absolute",
16
    top: visibleContent ? 0 : height, // as a workaround for RN, we offset the content so it is not visible but still can be rasterized
17 18 19 20 21
    left: 0,
    width: width,
    height: height,
    overflow: "hidden"
  };
22
  return <View key={id} style={childrenStyle}>{children}</View>;
23 24
};

25 26
const renderVGL = function (props) {
  const { width, height, ...restProps } = props;
27
  return <GLCanvas
28 29 30
    key="native"
    {...restProps}
    style={{ width, height }}
31 32 33
  />;
};

34
const renderVcontainer = function ({ style, width, height }, contents, renderer) {
35 36
  const parentStyle = {
    position: "relative",
37
    ...style,
38 39 40 41 42 43 44 45
    width: width,
    height: height,
    overflow: "hidden"
  };
  return <View style={parentStyle}>
    {contents}
    {renderer}
  </View>;
46 47
};

48
const GLView = createView(React, Shaders, Uniform, renderVcontainer, renderVcontent, renderVGL);
49 50 51 52 53 54

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

module.exports = GLView;