View.js 1.23 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
const GLCanvas = require("./GLCanvas");
6 7 8 9 10

const {
  View,
} = React;

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

23
const renderVGL = function (props) {
24
  return <GLCanvas ref="canvas" {...props} />;
25 26
};

27
const renderVcontainer = function ({ style, width, height }, contents, renderer) {
28 29
  const parentStyle = {
    position: "relative",
30
    ...style,
31 32 33 34 35 36 37 38
    width: width,
    height: height,
    overflow: "hidden"
  };
  return <View style={parentStyle}>
    {contents}
    {renderer}
  </View>;
39 40
};

41
const GLView = createView(React, Shaders, Uniform, renderVcontainer, renderVcontent, renderVGL);
42 43 44 45 46 47

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

module.exports = GLView;