react-native-image-picker
Advanced tools
Comparing version 0.7.1 to 0.8.0
@@ -22,29 +22,31 @@ import React from 'react-native'; | ||
avatarTapped() { | ||
// Specify any or all of these keys | ||
const options = { | ||
title: 'Select Avatar', | ||
title: 'Select Photo', | ||
cancelButtonTitle: 'Cancel', | ||
takePhotoButtonTitle: 'Take Photo...', | ||
takePhotoButtonHidden: false, | ||
chooseFromLibraryButtonTitle: 'Choose from Library...', | ||
chooseFromLibraryButtonHidden: false, | ||
returnBase64Image: false, | ||
returnIsVertical: false, | ||
quality: 0.2 | ||
quality: 0.2, | ||
storageOptions: { | ||
skipBackup: true | ||
} | ||
}; | ||
UIImagePickerManager.showImagePicker(options, (responseType, response) => { | ||
console.log(`Response Type = ${responseType}`); | ||
UIImagePickerManager.showImagePicker(options, (didCancel, response) => { | ||
console.log('Response = ', response); | ||
if (responseType !== 'cancel') { | ||
let source; | ||
if (responseType === 'data') { // New photo taken OR passed returnBase64Image true - response is the 64 bit encoded image data string | ||
source = {uri: 'data:image/jpeg;base64,' + response, isStatic: true}; | ||
} else { // Selected from library - response is the URI to the local file asset | ||
source = {uri: response.replace('file://', ''), isStatic: true}; | ||
if (didCancel) { | ||
console.log('User cancelled image picker'); | ||
} | ||
else { | ||
if (response.customButton) { | ||
console.log('User tapped custom button: ', response.customButton); | ||
} | ||
else { | ||
//const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true}; | ||
const source = {uri: response.uri.replace('file://', ''), isStatic: true}; | ||
this.setState({ | ||
avatarSource: source | ||
}); | ||
this.setState({ | ||
avatarSource: source | ||
}); | ||
} | ||
} | ||
@@ -51,0 +53,0 @@ }); |
@@ -9,4 +9,4 @@ { | ||
"dependencies": { | ||
"react-native": "^0.11.0" | ||
"react-native": "^0.12.0" | ||
} | ||
} |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"description": "A React Native module that allows you to use the native UIImagePickerController UI to select a photo from the device library or directly from the camera.", | ||
@@ -10,0 +10,0 @@ "author": "Marc Shilling (marcshilling)", |
@@ -27,8 +27,6 @@ # react-native-image-picker | ||
var options = { | ||
title: 'Select Avatar', | ||
title: 'Select Avatar', // specify null or empty string to remove the title | ||
cancelButtonTitle: 'Cancel', | ||
takePhotoButtonTitle: 'Take Photo...', | ||
takePhotoButtonHidden: false, | ||
chooseFromLibraryButtonTitle: 'Choose from Library...', | ||
chooseFromLibraryButtonHidden: false, | ||
takePhotoButtonTitle: 'Take Photo...', // specify null or empty string to remove this button | ||
chooseFromLibraryButtonTitle: 'Choose from Library...', // specify null or empty string to remove this button | ||
customButtons: { | ||
@@ -39,26 +37,35 @@ 'Choose Photo from Facebook': 'fb', // [Button Text] : [String returned upon selection] | ||
maxHeight: 100, | ||
returnBase64Image: false, | ||
returnIsVertical: false, | ||
quality: 0.2, | ||
allowsEditing: false // Built in iOS functionality to resize/reposition the image | ||
allowsEditing: false, // Built in iOS functionality to resize/reposition the image | ||
storageOptions: { // if this key is provided, the image will get saved in the documents directory (rather than a temporary directory) | ||
skipBackup: true, // image will NOT be backed up to icloud | ||
path: 'images' // will save image at /Documents/images rather than the root | ||
} | ||
}; | ||
// The first arg will be the options object for customization, the second is | ||
// your callback which sends string: responseType, string: response. | ||
// responseType will be either 'cancel', 'data', 'uri', or one of your custom button values | ||
UIImagePickerManager.showImagePicker(options, (responseType, response) => { | ||
console.log(`Response Type = ${responseType}`); | ||
// your callback which sends bool: didCancel, object: response. | ||
// | ||
// response.data is the base64 encoded image data | ||
// response.uri is the uri to the local file asset on the device | ||
// response.isVertical will be true if the image is vertically oriented | ||
UIImagePickerManager.showImagePicker(options, (didCancel, response) => { | ||
console.log('Response = ', response); | ||
if (responseType !== 'cancel') { | ||
let source; | ||
if (responseType === 'data') { // New photo taken OR passed returnBase64Image true - response is the 64 bit encoded image data string | ||
source = {uri: 'data:image/jpeg;base64,' + response, isStatic: true}; | ||
if (didCancel) { | ||
console.log('User cancelled image picker'); | ||
} | ||
else { | ||
if (response.customButton) { | ||
console.log('User tapped custom button: ', response.customButton); | ||
} | ||
else if (responseType === 'uri') { // Selected from library - response is the URI to the local file asset | ||
source = {uri: response.replace('file://', ''), isStatic: true}; | ||
else { | ||
// You can display the image using either: | ||
const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true}; | ||
const source = {uri: response.uri.replace('file://', ''), isStatic: true}; | ||
this.setState({ | ||
avatarSource: source | ||
}); | ||
} | ||
this.setState({ | ||
avatarSource: source | ||
}); | ||
} | ||
@@ -71,1 +78,17 @@ }); | ||
``` | ||
### Directly Launching the Camera or Image Library | ||
To Launch the Camera or Image Library directly (skipping the alert dialog) you can | ||
do the following: | ||
```javascript | ||
// Launch Camera: | ||
UIImagePickerManager.launchCamera(options, (didCancel, response) => { | ||
// Same code as in above section! | ||
}); | ||
// Open Image Library: | ||
UIImagePickerManager.launchImageLibrary(options, (didCancel, response) => { | ||
// Same code as in above section! | ||
}); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
650565
21
0
117
92