Skip to content

Instantly share code, notes, and snippets.

@parappathekappa
Last active April 27, 2018 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parappathekappa/de3bb375171e07ca9efbbd754aad42fe to your computer and use it in GitHub Desktop.
Save parappathekappa/de3bb375171e07ca9efbbd754aad42fe to your computer and use it in GitHub Desktop.
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