-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ios.js
125 lines (106 loc) · 3.14 KB
/
index.ios.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* Copyright (c) 2017, HouseRater LLC.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule react-native-camera-ios
*/
import PropTypes from 'prop-types';
import React from "react";
import {
NativeModules,
requireNativeComponent,
StyleSheet,
I18nManager,
View
} from "react-native";
import AppContainer from "AppContainer";
const RNCameraHostViewManager = NativeModules.RNCameraHostViewManager;
export default class RNCamera extends React.Component {
static propTypes = {
visible: PropTypes.bool,
animationType: PropTypes.oneOf([ 'none', 'fade', 'slide' ]),
cameraDevice: PropTypes.oneOf([ 'front', 'rear' ]),
cameraFlashMode: PropTypes.oneOf([ 'off', 'auto', 'on' ]),
onCancel: PropTypes.func,
onCapture: PropTypes.func,
};
static defaultProps = {
visible: false,
animationType: 'slide',
cameraFlashMode: 'off'
};
static contextTypes = {
rootTag: PropTypes.number,
};
capture() {
RNCameraHostViewManager.capture();
}
static checkFlashAvailable(callback, cameraDevice = 'rear') {
RNCameraHostViewManager.checkFlashAvailableWithCameraDevice(cameraDevice, callback);
}
static resizeImage(filePath, outputPath, options) {
return new Promise((resolve, reject) => {
RNCameraHostViewManager.resizeImage(filePath, outputPath, options, (err, data) => {
if (err) {
reject(err);
return;
}
resolve(data);
});
});
}
_onCapture(event) {
const { onCapture } = this.props;
const { image, width, height } = event.nativeEvent;
let captureEvent = {
image: {
path: image,
width,
height
}
};
onCapture(captureEvent);
}
render() {
const { visible, children, ...otherProps } = this.props;
if (!visible) {
return null;
}
const innerChildren = children && (__DEV__ ? (
<AppContainer rootTag={this.context.rootTag}>
{children}
</AppContainer>
) : children);
return (
<RNCameraHostView
{...otherProps}
onCapture={(event) => this._onCapture(event)}
style={styles.modal}
onStartShouldSetResponder={() => true}
>
{innerChildren && (
<View
style={styles.container}
>
{innerChildren}
</View>
)}
</RNCameraHostView>
)
}
}
const RNCameraHostView = requireNativeComponent('RNCameraHostView', RNCamera);
const side = I18nManager.isRTL ? 'right' : 'left';
const styles = StyleSheet.create({
modal: {
position: 'absolute',
},
container: {
position: 'absolute',
[side] : 0,
top: 0,
}
});