View.js 1.41 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 13
const Component = require("./Component");

const {
  requireNativeComponent,
  View,
} = React;

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

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

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

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

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

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

module.exports = GLView;