Get permissions doesn't trigger callback
See original GitHub issueDescription
On Android 23+ with React Native 0.43+ (targetSDKVersion 23), the very first time you try to take a picture ou to select one from the library, the permission popups (WRITE_EXTERNAL_STORAGE and PERMISSIONS.CAMERA) shows up, but the callback is never triggered. You have to recall the method to get it working
How to repeat issue and example
gotPhotoResponse(response:{didCancel:boolean,error:{}}) {
if (response.didCancel) {
this.props.onCancel();
}
else if (response.error) {
Alert.alert(
I18n.t('issue_creation_take_picture_error_title'),
I18n.t('issue_creation_take_picture_error_message'),
[
{
text: I18n.t('issue_creation_take_picture_error_settings'),
onPress: this.goToSettings
},
{
text: I18n.t('text_cancel'),
onPress: this.props.onCancel
}
]
);
}
else {
this.props.onSelect(response);
}
}
selectTakePhotoTapped() {
ImagePicker.launchCamera(options, this.gotPhotoResponse.bind(this));
}
selectPickPhotoTapped() {
ImagePicker.launchImageLibrary(options, this.gotPhotoResponse.bind(this));
}
render() {
return <View style={styles.container}>
<View style={styles.bigButton}>
<Button onPress={this.selectTakePhotoTapped} title={I18n.t('issue_creation_take_picture')}/>
</View>
<View style={styles.smallButton}>
<Button onPress={this.selectPickPhotoTapped}
title={I18n.t('issue_creation_select_picture')}/>
</View>
</View>
}
In this case, this.gotPhotoResponse
is never triggered after allowing or denying the permissions. Any subsequent call to this.selectTakePhotoTapped
or selectPickPhotoTapped
works as expected.
I tried a workaround with checking the permissions individually with PermissionsAndroid
from React-Native but it get messy as you can allow one permission and deny the other, launching react-native-image-picker afterwards still requires the 2 permissions in order to proceed.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:13
Top GitHub Comments
FYI, I got around the issue by “overriding” the react-native-image-picker module with a custom static class that keeps the same signature. I made a gist out of it: https://gist.github.com/pvanliefland/92046b17444a8760475e7cc0dae4fec7
If the library author is interested, I can work on a pull request.
@Alexisvt I imported both react-native-image-picker and the gist provided by @pvanliefland and used Platform.OS to handle which one to use