Я относительно новичок в React Native. Я пытаюсь добавить функциональность добавления изображения на страницу и получаю следующую ошибку.
"Ошибка типа: невозможно прочитать свойство 'showImagePicker' с неопределенным значением"
Вот мой код:
import React,{Component} from 'react';
import { StyleSheet, Text, View,Image,TouchableOpacity,Alert } from 'react-native';
import * as ImagePicker from 'react-native-image-picker'
const options={
title: 'Chose an Option',
takePhotoButtonTitle:'Use Camera',
chooseFromLibraryButtonTitle:'Select From Gallery',
}
export default class Upload extends Component {
constructor(props){
super(props);
this.state={
avatarSource: null
}
}
uploadImage=()=>{
//alert('Do not toch me ')
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 {
const source = { uri: response.uri };
// You can also display the image using data:
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
avatarSource: source,
});
}
});
}
render(){
return (
<View style={styles.container}>
<TouchableOpacity style={{backgroundColor:'green',margin:10,padding:30}} onPress={this.uploadImage}>
<Text style={{color:'#fff'}}>
Select Image
</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Я также приложил список моих текущих зависимостей.
"dependencies": {
"@react-native-community/masked-view": "^0.1.6",
"events": "^3.1.0",
"expo": "~37.0.3",
"oracledb": "^4.2.0",
"path": "^0.12.7",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
"react-native-gesture-handler": "^1.6.1",
"react-native-image-picker": "^0.28.0",
"react-native-reanimated": "^1.7.0",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.2.0",
"react-native-web": "^0.12.2",
"react-navigation": "^4.3.7",
"react-navigation-drawer": "^2.4.11",
"react-navigation-stack": "^2.3.11",
"react-navigation-tabs": "^2.8.11",
"stream": "0.0.2",
"util": "^0.12.2"
}
Пожалуйста, дайте мне знать, как решить эту проблему.