My feature offers a small image icon as a touchable to upload or take a picture, using "react-native-image-picker": "^3.3.2"
.
I'm getting error: Cannot read property 'launchImageLibrary' of undefined
, same as this GitHub issue but as you can see, my code already have the import as they told to.
Here's my full code:
import React from 'react';
import {
StyleSheet,
Image,
TouchableOpacity,
Alert
} from 'react-native';
import { launchImageLibrary } from 'react-native-image-picker';
const ImageUpload: React.FC<any> = ({}) => {
function showMessage() {
Alert.alert("Upload image", "Choose a option", [
{
text: 'Camera',
onPress: () => openCamera(),
},
{
text: 'Gallery',
onPress: () => openLibrary()
},
]);
}
const openLibrary = () => {
const options = {
storageOptions: {
skipBackup: true,
path: 'images',
},
};
launchImageLibrary(options, (response) => {
console.log(response);
});
}
const openCamera = () => {
//ongoing
}
return(
<>
<TouchableOpacity onPress={()=>showMessage()}>
<Image source={require('./picture.png')} style={{ width: 70, height: 70 }}/>
</TouchableOpacity>
</>
);
};
const style = StyleSheet.create({
ImageIcon: {
justifyContent: "center",
alignItems: "center",
}
});
export default ImageUpload;
Also, In VS Code, I have this error when calling launchImageLibrary
:
I have already perfomed a npx pod-install
.