-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathARMonoView.js
More file actions
69 lines (69 loc) · 2 KB
/
ARMonoView.js
File metadata and controls
69 lines (69 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { ARMonoView as NativeMonoView } from "./RNSwiftBridge";
import PropTypes from "prop-types";
import React, { Component } from "react";
import { ARSessionConsumer, ARSessionProvider } from "./ARSessionProvider";
class ARBaseMonoView extends Component {
render() {
return (
<ARSessionConsumer>
{value => {
const { isStarted } = value;
if (typeof isStarted === "undefined") {
return (
<ARSessionProvider
alignment={
this.props.alignment
? this.props.alignment
: ARSessionProvider.defaultProps.alignment
}
>
<ARMonoView {...this.props} />
</ARSessionProvider>
);
} else
return [
<NativeMonoView
{...this.props}
children={null}
key="ARMonoViewNative"
/>,
typeof this.props.children == "function" ? (
<ARSessionConsumer key="ARMonoViewConsumer">
{value => {
return this.props.children(value);
}}
</ARSessionConsumer>
) : this.props.children ? (
this.props.children
) : null
];
}}
</ARSessionConsumer>
);
}
componentDidMount() {
if (typeof this.props.start == "function") this.props.start();
}
componentWillUnmount() {
if (typeof this.props.stop == "function") this.props.stop();
}
}
ARBaseMonoView.propTypes = {
preview: PropTypes.bool,
start: PropTypes.func,
stop: PropTypes.func,
debugMode: PropTypes.bool
};
ARBaseMonoView.defaultProps = {
preview: true,
debugMode: false
};
const ARMonoView = props => (
<ARSessionConsumer>
{({ start, stop }) => (
<ARBaseMonoView {...props} start={start} stop={stop} />
)}
</ARSessionConsumer>
);
ARMonoView.propTypes = { ...ARBaseMonoView.propTypes };
export default ARMonoView;