React Native Image Picker
![Gitter chat](https://badges.gitter.im/Join%20Chat.svg)
A React Native module that allows you to use native UI to select a photo/video from the device library or directly from the camera, like so:
iOS | Android |
---|
![iOS](https://github.com/react-community/react-native-image-picker/blob/master/images/ios-image.png) | ![Android](https://github.com/react-community/react-native-image-picker/blob/master/images/android-image.png) |
Before you open an issue
This library started as a basic bridge of the native iOS image picker, and I want to keep it that way. As such, functionality beyond what the native UIImagePickerController
supports will not be supported here. Multiple image selection, more control over the crop tool, and landscape support are things missing from the native iOS functionality - not issues with my library. If you need these things, react-native-image-crop-picker might be a better choice for you.
Getting Started
yarn add tm-react-native-image-picker
react-native link tm-react-native-image-picker
You will also need to add UsageDescription
on iOS and some permissions on Android, refer to the Install doc.
Usage
import ImagePicker from 'tm-react-native-image-picker';
const options = {
title: 'Select Avatar',
customButtons: [{ name: 'fb', title: 'Choose Photo from Facebook' }],
storageOptions: {
skipBackup: true,
path: 'images',
},
};
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };
this.setState({
avatarSource: source,
});
}
});
Then later, if you want to display this image in your render() method:
<Image source={this.state.avatarSource} style={styles.uploadAvatar} />
Directly Launching the Camera or Image Library
To Launch the Camera or Image Library directly (skipping the alert dialog) you can
do the following:
ImagePicker.launchCamera(options, (response) => {
});
ImagePicker.launchImageLibrary(options, (response) => {
});
Notes
On iOS, don't assume that the absolute uri returned will persist. See #107
For more, read the API Reference.
####Taimei
add manual delete image api:delLocalImage();
License
MIT