Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show Camera Function
showCamera = async () => {
this.setState({
cameraClicked: true
});
setTimeout(() => {
this.setState({
cameraClicked: false
});
}, 8000);
// Check camera permissions
Permissions.askAsync(Permissions.CAMERA)
.then(status => {
console.log("Camera Permission: ", status.status);
if (status.status != "granted") {
throw new Error(
"Camera permissions disabled. Please enable them in your settings."
);
}
})
// Also need file storage permissions to access camera
.then(_ => Permissions.askAsync(Permissions.CAMERA_ROLL))
.then(status => {
console.log("Camera Roll Permission: ", status.status);
if (status.status != "granted") {
throw new Error(
"Storage permissions disabled. Please enable them in your settings."
);
}
})
.then(_ => ImagePicker.launchCameraAsync({ exif: true }))
.then(result => {
this.uploadImage(result);
this.getPermissionAndLocation();
return;
})
.catch(error => {
console.log(error);
this.props.alertWithType("error", "", error);
});
};
showPicker = async () => {
this.setState({
cameraClicked: true
});
setTimeout(() => {
this.setState({
cameraClicked: false
});
}, 8000);
// Check permissions and open the photo album
Permissions.askAsync(Permissions.CAMERA_ROLL)
.then(status => {
console.log("Camera Roll Permission: ", status.status);
if (status.status != "granted") {
throw new Error(
"Storage permissions disabled. Please enable them in your settings."
);
}
})
.then(_ => ImagePicker.launchImageLibraryAsync({ exif: true }))
.then(result => {
this.uploadImage(result);
this.getPermissionAndLocation();
return;
})
.catch(error => {
console.log(error);
this.props.alertWithType("error", "", error);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.