-
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.
Merge pull request #3420 from kidroca/kidroca/update-image-picker-dep…
…endencies Fix: [Android] Opening camera/gallery does not work on Android 11
- Loading branch information
Showing
7 changed files
with
61 additions
and
21 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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; |