Surface.js 1.25 KB
Newer Older
1
const invariant = require("invariant");
2
const {createSurface} = require("gl-react");
3
invariant(typeof createSurface === "function", "gl-react createSurface is not a function. Check your gl-react dependency");
4
const React = require("react-native");
5
const GLCanvas = require("./GLCanvas");
6 7 8 9 10

const {
  View,
} = React;

11
function renderVcontent (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
    left: 0,
    width: width,
    height: height,
18
    overflow: "hidden",
19
  };
20
  return <View key={id} style={childrenStyle}>{children}</View>;
21
}
22

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

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

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