react-native-image-picker
A React Native module that allows you to use the native UIImagePickerController UI to either select a photo from the device library or directly from the camera, like so:
![Screenshot of the UIActionSheet](https://github.com/marcshilling/react-native-image-picker/blob/master/AlertSheetImage.jpg)
Install
npm install react-native-image-picker@latest --save
- In the XCode's "Project navigator", right click on your project's Libraries folder ➜
Add Files to <...>
- Go to
node_modules
➜ react-native-image-picker
➜ select the UIImagePickerManager
folder - Compile and have fun!
Usage
- In your React Native javascript code, bring in the native module:
var UIImagePickerManager = require('NativeModules').UIImagePickerManager;
- Use it like so:
When you want to display the picker:
var options = {
title: 'Select Avatar',
cancelButtonTitle: 'Cancel',
takePhotoButtonTitle: 'Take Photo...',
chooseFromLibraryButtonTitle: 'Choose from Library...',
returnBase64Image: false,
returnIsVertical: false,
quality: 0.2
};
UIImagePickerManager.showImagePicker(options, (type, response) => {
if (type !== 'cancel') {
var source;
if (type === 'data') {
source = {uri: 'data:image/jpeg;base64,' + response, isStatic: true};
} else {
source = {uri: response};
}
this.setState({avatarSource:source});
} else {
console.log('Cancel');
}
});
Then later, if you want to display this image in your render() method:
<Image source={this.state.avatarSource} style={styles.uploadAvatar} />