Last active
April 27, 2018 21:54
-
-
Save parappathekappa/de3bb375171e07ca9efbbd754aad42fe to your computer and use it in GitHub Desktop.
Show Camera Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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