Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_record() {
this.camera.capture({
mode: Camera.constants.CaptureMode.video,
audio: true
}).then((data) => {
if (this.props.setID) {
this.props.saveVideo(this.props.setID, data.path, this.props.videoType);
}
// TODO: share options can be here, but for now just finish
}).catch((err) => {
console.tron.log("ERROR " + err);
this.props.saveVideoError(this.props.setID, err);
Alert.alert('There was an issue saving your video. Please try again');
});
}
constructor(props) {
super(props);
this.updateIsAuthorized = this.updateIsAuthorized.bind(this);
let isAuthorized = true;
if (Platform.OS === 'ios') {
// Asks for permissions if not defined, returns choice otherwise
isAuthorized = undefined;
Camera.checkDeviceAuthorizationStatus().then(this.updateIsAuthorized);
}
this.state = { isAuthorized };
this.onQRCodeScanned = _.debounce(props.onQRCodeScanned, 1000, { leading: true, trailing: false });
}
return (
)
}
// for ios
return (
)
}
async _requestCameraPermission() {
try {
const permissionGranted = await Camera.checkVideoAuthorizationStatus()
this.setState({permissionGranted})
} catch (err) {
console.warn("Can't get camera permissions", err)
this.setState({permissionGranted: false})
}
}
componentDidMount() {
Camera.checkVideoAuthorizationStatus().then(data => {
console.log(data);
this.setState({ allowed: data });
});
}
takePicture = async function () {
if (Host.isIOS) {
if (!await Camera.checkDeviceAuthorizationStatus()) {
alert('相机权限未开启')
return
}
}
if (Host.isAndroid) {
if (!await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.CAMERA)) {
alert('相机权限未开启')
return
} else {
console.log('相机权限已开启');
}
}
if (this.camera) {
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePictureAsync(options);
renderCameraModal = () => (
{
this.camera = camera;
}}
style={{ flex: 1 }}
type={RNCamera.Constants.Type.back}
autoFocus={RNCamera.Constants.AutoFocus.on}
flashMode={RNCamera.Constants.FlashMode.off}
permissionDialogTitle={"Permission to use camera"}
permissionDialogMessage={
"We need your permission to use your camera phone"
}
/>
{ this.renderImagesList() }
Cancelar
renderCamera() {
const { scanning } = this.state;
return (
{
if (!scanning) this.handleOnBarCodeRead(data);
}}
/>
);
}
_clickTakePicture = async () => {
if (this.camera) {
const item = await this.camera.takePictureAsync({
mirrorImage: this.state.sideType === RNCamera.Constants.Type.front,
fixOrientation: true,
forceUpOrientation: true,
...this.props.pictureOptions
});
if (Platform.OS === 'ios') {
if (item.uri.startsWith('file://')) {
item.uri = item.uri.substring(7);
}
}
if (this.props.maxSize > 1) {
if (this.state.data.length >= this.props.maxSize) {
Alert.alert('', this.props.maxSizeTakeAlert(this.props.maxSize));
} else {
this.setState({
data: [...this.state.data, item],
});
switchFlash = () => {
let newFlashMode;
const {auto, on, off} = RNCamera.Constants.FlashMode;
if (this.state.camera.flashMode === auto) {
newFlashMode = on;
} else if (this.state.camera.flashMode === on) {
newFlashMode = off;
} else if (this.state.camera.flashMode === off) {
newFlashMode = auto;
}
this.setState({
camera: {
...this.state.camera,
flashMode: newFlashMode,
},
});
};