-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathview.js
73 lines (73 loc) · 1.99 KB
/
view.js
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
70
71
72
73
import { requireNativeComponent, NativeModules, View } from "react-native";
import { attachCameraView } from "./module";
import { RNVisionConsumer } from "./wrapper";
import PropTypes from "prop-types";
import React, { Component } from "react";
import Region from "./region";
import { RHDVisionCameraView } from "./RNSwiftBridge";
const { Provider, Consumer: CameraConsumer } = React.createContext();
class RNVision extends Component {
state = {
viewPortRectangle: null,
height: null,
width: null
};
stringified = "";
constructor(props) {
super(props);
}
componentDidMount() {
attachCameraView();
}
onLayout(e) {
const layout = e.nativeEvent.layout;
this.setState({ height: layout.height, width: layout.width });
}
render() {
return (
<View
style={this.props.style}
onLayout={e => {
this.onLayout(e);
}}
>
<RHDVisionCameraView {...{ ...this.props, children: null }} />
<Provider
value={{
viewPortDimensions: {
height: this.state.height,
width: this.state.width
},
viewPortGravity: this.props.gravity
}}
>
{typeof this.props.children == "function" ? (
<RNVisionConsumer>
{value => {
const newValue = {
...value,
viewPortDimensions: {
height: this.state.height,
width: this.state.width
},
viewPortGravity: this.props.gravity
};
return this.props.children(newValue);
}}
</RNVisionConsumer>
) : (
this.props.children
)}
</Provider>
</View>
);
}
}
RNVision.defaultProps = {
gravity: "fill"
};
RNVision.propTypes = {
gravity: PropTypes.string.isRequired
};
export { RNVision as RNVCameraView, CameraConsumer as RNVCameraConsumer };
export default RNVision;