Created
November 9, 2021 11:35
-
-
Save ddikodroid/a2a9605b56ee3da35c089aee7db4764f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const requestCameraPermission = async () => { | |
| try { | |
| const granted = await PermissionsAndroid.request( | |
| PermissionsAndroid.PERMISSIONS.CAMERA, | |
| { | |
| title: "App Camera Permission", | |
| message: "App needs access to your camera ", | |
| buttonNeutral: "Ask Me Later", | |
| buttonNegative: "Cancel", | |
| buttonPositive: "OK" | |
| } | |
| ); | |
| if (granted === PermissionsAndroid.RESULTS.GRANTED) { | |
| console.log("Camera permission given"); | |
| ImagePicker.launchCamera( | |
| { | |
| mediaType: 'photo', | |
| includeBase64: false, | |
| cameraType: 'back', | |
| quality: 0.75 | |
| }, | |
| (response) => { | |
| if (response.didCancel) { | |
| console.log('Image Picker Canceled') | |
| } else if (response.errorCode) { | |
| console.log(response.errorMessage) | |
| } else { | |
| setProductPhotos(photo => [...photo, { uri: response.uri }]) | |
| addPhotoRef.current.hideModal() | |
| } | |
| } | |
| ) | |
| } else { | |
| console.log("Camera permission denied"); | |
| } | |
| } catch (err) { | |
| console.warn(err); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment