Merge pull request #1547 from react-native-community/n1ru4l-patch-1

fix status for non authorized/pending camera
This commit is contained in:
Sibelius Seraphini 2018-05-07 10:56:59 -03:00 committed by GitHub
commit 86125a0a79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,
@ -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
@ -318,18 +325,21 @@ export default class Camera extends React.Component<PropsType, StateType> {
getStatus = (): Status => {
const { isAuthorized, isAuthorizationChecked } = this.state;
return isAuthorized ? 'READY' : isAuthorizationChecked ? 'PENDING_AUTHORIZATION' : 'NOT_AUTHORIZED';
}
if (isAuthorizationChecked === false) {
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);
@ -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) {