Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertSasak committed Sep 30, 2019
1 parent dd6484d commit dfeec13
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 64 deletions.
8 changes: 8 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
bracketSpacing: true,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
semi: false,
tabWidth: 2,
}
115 changes: 51 additions & 64 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,48 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
NativeModules,
Platform,
StyleSheet,
requireNativeComponent,
View,
} from 'react-native';

const CameraManager = NativeModules.ALPRCameraManager;
const CAMERA_REF = 'camera';
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { NativeModules, requireNativeComponent, View } from 'react-native'

const CameraManager = NativeModules.ALPRCameraManager
const CAMERA_REF = 'camera'

function convertNativeProps(props) {
const newProps = { ...props };
const newProps = { ...props }
if (typeof props.aspect === 'string') {
newProps.aspect = Camera.constants.Aspect[props.aspect];
newProps.aspect = Camera.constants.Aspect[props.aspect]
}

if (typeof props.torchMode === 'string') {
newProps.torchMode = Camera.constants.TorchMode[props.torchMode];
newProps.torchMode = Camera.constants.TorchMode[props.torchMode]
}

if (typeof props.captureQuality === 'string') {
newProps.captureQuality = Camera.constants.CaptureQuality[props.captureQuality];
newProps.captureQuality =
Camera.constants.CaptureQuality[props.captureQuality]
}

// delete this prop because we are going to replace it with our own
delete newProps.onPlateRecognized;
return newProps;
delete newProps.onPlateRecognized
return newProps
}

export default class Camera extends Component {

static constants = {
Aspect: CameraManager.Aspect,
CaptureQuality: CameraManager.CaptureQuality,
TorchMode: CameraManager.TorchMode
};
TorchMode: CameraManager.TorchMode,
}

static propTypes = {
...View.propTypes,
aspect: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
captureQuality: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
aspect: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
captureQuality: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
country: PropTypes.string,
onPlateRecognized: PropTypes.func,
plateOutlineColor: PropTypes.string,
showPlateOutline: PropTypes.bool,
torchMode: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
torchMode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
touchToFocus: PropTypes.bool,
};
}

static defaultProps = {
aspect: CameraManager.Aspect.fill,
Expand All @@ -67,33 +52,34 @@ export default class Camera extends Component {
showPlateOutline: true,
torchMode: CameraManager.TorchMode.off,
touchToFocus: true,
};
}

static checkVideoAuthorizationStatus = CameraManager.checkVideoAuthorizationStatus;
static checkVideoAuthorizationStatus =
CameraManager.checkVideoAuthorizationStatus

setNativeProps(props) {
this.refs[CAMERA_REF].setNativeProps(props);
this.refs[CAMERA_REF].setNativeProps(props)
}

constructor() {
super();
super()
this.state = {
isAuthorized: false
};
isAuthorized: false,
}
}

onPlateRecognized = (event) => {
if(this.props.onPlateRecognized) {
this.props.onPlateRecognized(event.nativeEvent);
}
onPlateRecognized = event => {
if (this.props.onPlateRecognized) {
this.props.onPlateRecognized(event.nativeEvent)
}
}

async componentWillMount() {
let check = Camera.checkVideoAuthorizationStatus;
let check = Camera.checkVideoAuthorizationStatus

if (check) {
const isAuthorized = await check();
this.setState({ isAuthorized });
const isAuthorized = await check()
this.setState({ isAuthorized })
}
}

Expand All @@ -102,26 +88,27 @@ export default class Camera extends Component {
// @return a Promise<String:uri>.
// @warn Currently only works on iOS.
async takePicture(options) {
return await CameraManager.takePicture(options);
return await CameraManager.takePicture(options)
}

render() {
const nativeProps = convertNativeProps(this.props);

return <ALPRCamera ref={CAMERA_REF} onPlateRecognized={this.onPlateRecognized} {...nativeProps} />;
const nativeProps = convertNativeProps(this.props)

return (
<ALPRCamera
ref={CAMERA_REF}
onPlateRecognized={this.onPlateRecognized}
{...nativeProps}
/>
)
}

}

export const constants = Camera.constants;

const ALPRCamera = requireNativeComponent(
'ALPRCamera',
Camera,
{
nativeOnly: {
'rotateMode': true,
'mounted': true
}
}
);
export const constants = Camera.constants

const ALPRCamera = requireNativeComponent('ALPRCamera', Camera, {
nativeOnly: {
rotateMode: true,
mounted: true,
},
})

0 comments on commit dfeec13

Please sign in to comment.