Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
feat(rn-camera): use and export constants
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed May 7, 2018
1 parent 9ba5a23 commit c8c6fde
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/RNCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ type StateType = {

type Status = 'READY' | 'PENDING_AUTHORIZATION' | 'NOT_AUTHORIZED';

const CameraStatus = {
READY: 'READY',
PENDING_AUTHORIZATION: 'PENDING_AUTHORIZATION',
NOT_AUTHORIZED: 'NOT_AUTHORIZED',
};

const CameraManager: Object = NativeModules.RNCameraManager ||
NativeModules.RNCameraModule || {
stubbed: true,
Expand Down Expand Up @@ -144,6 +150,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
BarCodeType: CameraManager.BarCodeType,
GoogleVisionBarcodeDetection: CameraManager.GoogleVisionBarcodeDetection,
FaceDetection: CameraManager.FaceDetection,
CameraStatus,
};

// Values under keys from this object will be transformed to native options
Expand Down Expand Up @@ -318,18 +325,21 @@ export default class Camera extends React.Component<PropsType, StateType> {

getStatus = (): Status => {
const { isAuthorized, isAuthorizationChecked } = this.state;
return isAuthorized ? 'READY' : isAuthorizationChecked ? 'NOT_AUTHORIZED' : 'PENDING_AUTHORIZATION';
}
if (isAuthorizationChecked) {
return CameraStatus.PENDING_AUTHORIZATION;
}
return isAuthorized ? CameraStatus.READY : CameraStatus.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 this.props.children({ camera: this, status: this.getStatus() });
}
return null;
}
};

render() {
const nativeProps = this._convertNativeProps(this.props);
Expand All @@ -348,7 +358,7 @@ export default class Camera extends React.Component<PropsType, StateType> {
onFacesDetected={this._onObjectDetected(this.props.onFacesDetected)}
onTextRecognized={this._onObjectDetected(this.props.onTextRecognized)}
>
{this.renderChildren()}
{this.renderChildren()}
</RNCamera>
);
} else if (!this.state.isAuthorizationChecked) {
Expand Down

0 comments on commit c8c6fde

Please sign in to comment.