Surface.js 1010 Bytes
Newer Older
1
const {createSurface} = require("gl-react-core");
2
const React = require("react-native");
3
const GLCanvas = require("./GLCanvas");
4 5 6 7 8

const {
  View,
} = React;

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

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

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

39
module.exports = createSurface(renderVcontainer, renderVcontent, renderVGL);