diff --git a/docs/RNCamera.md b/docs/RNCamera.md
index 10355dd0d..7147e3f99 100644
--- a/docs/RNCamera.md
+++ b/docs/RNCamera.md
@@ -78,6 +78,98 @@ const styles = StyleSheet.create({
AppRegistry.registerComponent('BadInstagramCloneApp', () => BadInstagramCloneApp);
```
+## FaCC (Function as Child Components)
+
+**You can also use it with Facc.*
+
+```javascript
+ 'use strict';
+import React, { Component } from 'react';
+import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
+import { RNCamera } from 'react-native-camera';
+
+const PendingView = () => (
+
+ Waiting
+
+);
+
+class App extends Component {
+ render() {
+ return (
+
+
+ {({ camera, status }) => {
+ if (status !== 'READY') return ;
+ return (
+
+ this.takePicture(camera)} style={styles.capture}>
+ SNAP
+
+
+ );
+ }}
+
+
+ );
+ }
+
+ takePicture = async function(camera) {
+ const options = { quality: 0.5, base64: true };
+ const data = await camera.takePictureAsync(options);
+ // eslint-disable-next-line
+ console.log(data.uri);
+ }
+}
+
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ flexDirection: 'column',
+ backgroundColor: 'black',
+ },
+ preview: {
+ flex: 1,
+ justifyContent: 'flex-end',
+ alignItems: 'center',
+ },
+ capture: {
+ flex: 0,
+ backgroundColor: '#fff',
+ borderRadius: 5,
+ padding: 15,
+ paddingHorizontal: 20,
+ alignSelf: 'center',
+ margin: 20,
+ },
+});
+
+AppRegistry.registerComponent('BadInstagramCloneApp', () => App);
+```
+
+#### `camera`
+
+*It's the RNCamera's reference*
+
+#### `status`
+
+'READY' | 'PENDING_AUTHORIZATION' | 'NOT_AUTHORIZED'
+
+
+
## Properties
#### `autoFocus`
diff --git a/src/RNCamera.js b/src/RNCamera.js
index 31e26e629..37e836101 100644
--- a/src/RNCamera.js
+++ b/src/RNCamera.js
@@ -100,6 +100,8 @@ type StateType = {
isAuthorizationChecked: boolean,
};
+type Status = 'READY' | 'PENDING_AUTHORIZATION' | 'NOT_AUTHORIZED';
+
const CameraManager: Object = NativeModules.RNCameraManager ||
NativeModules.RNCameraModule || {
stubbed: true,
@@ -314,10 +316,25 @@ export default class Camera extends React.Component {
this.setState({ isAuthorized, isAuthorizationChecked: true });
}
+ getStatus = (): Status => {
+ const { isAuthorized, isAuthorizationChecked } = this.state;
+ return isAuthorized ? 'READY' : isAuthorizationChecked ? 'PENDING_AUTHORIZATION' : 'NOT_AUTHORIZED';
+ }
+
+ // FaCC = Function as Child Component;
+ hasFaCC = (): * => typeof this.props.children === 'function';
+
+ renderChildren = (): * => {
+ if (this.hasFaCC()) {
+ return this.props.children({ camera: this, status: this.getStatus() })
+ }
+ return null;
+ }
+
render() {
const nativeProps = this._convertNativeProps(this.props);
- if (this.state.isAuthorized) {
+ if (this.state.isAuthorized || this.hasFaCC()) {
return (
{
onBarCodeRead={this._onObjectDetected(this.props.onBarCodeRead)}
onFacesDetected={this._onObjectDetected(this.props.onFacesDetected)}
onTextRecognized={this._onObjectDetected(this.props.onTextRecognized)}
- />
+ >
+ {this.renderChildren()}
+
);
} else if (!this.state.isAuthorizationChecked) {
return this.props.pendingAuthorizationView;