-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: launchCamera.js and launchCamera.android.js
When an user installs E.cash on Android they've automatically granted camera permission since it's included in the manifest, but if they ever revoke the Permission we need to check and request it again as the image-picker library does not handle this
- Loading branch information
Showing
3 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {PermissionsAndroid} from 'react-native'; | ||
import {launchCamera} from 'react-native-image-picker'; | ||
|
||
/** | ||
* Launching the camera for Android involves checking for permissions | ||
* And only then starting the camera | ||
* If the user deny permission the callback will be called with an error response | ||
* in the same format as the error returned by react-native-image-picker | ||
* @param {CameraOptions} options | ||
* @param {function} callback - callback called with the result | ||
*/ | ||
export default function launchCameraAndroid(options, callback) { | ||
// Checks current camera permissions and prompts the user in case they aren't granted | ||
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA) | ||
.then((permission) => { | ||
if (permission !== PermissionsAndroid.RESULTS.GRANTED) { | ||
const error = new Error('User did not grant permissions'); | ||
error.errorCode = 'permission'; | ||
throw error; | ||
} | ||
|
||
launchCamera(options, callback); | ||
}) | ||
.catch((error) => { | ||
/* Intercept the permission error as well as any other errors and call the callback | ||
* follow the same pattern expected for image picker results */ | ||
callback({ | ||
errorMessage: error.message, | ||
errorCode: error.errorCode || 'others', | ||
}); | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {launchCamera} from 'react-native-image-picker'; | ||
|
||
export default launchCamera; |