如何使用Expo

时间:2019-02-14 20:39:16

标签: reactjs react-native

我有一个项目,需要在其中上传或捕获图像到服务器,因此我将ImagePicker包安装到该项目中,但是当我尝试使用属性showimagepicker时,出现错误“无法读取未定义的属性'showimagepicker' “

我尝试更改后的版本,但不起作用。我目前有:

-Android Studio虚拟设备,我使用Android 8.0创建手机

-“ expo”:“ ^ 32.0.0”,

-“反应”:“ 16.5.0”,

-“ react-native”:“ https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz”,

-“ react-native-image-picker”:“ ^ 0.26.7” BTW“ ^ 0.24.0”。

我尝试修改android-settings.gradle:

包括':react-native-image-picker' project(':react-native-image-picker')。projectDir =新文件(rootProje ct.projectDir,'.. / node_modules / react-native-image-picker / android')

,然后在AndoidManifest.xml中输入:

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

ImagePicker.showImagePicker(options,(response)=> {

   if (response.didCancel) {
      console.log('User cancelled photo picker');

   }
    else if (response.error) {
      console.log('ImagePicker Error: ', response.error);
    }
    else {
          console.log('imagen', response)
         let source = { uri: response.uri, uriOri:response.origURL, data: 
         response.data };

         let item = {
            data:response.data,
            test:'test123',
            source: source
          }

         var {cantImg} = this.state
         if(this.state.avatarSource1 == null){
            this.setState({avatarSource1: source})
            cantImg++
            console.log(cantImg)
          }else if(this.state.avatarSource2 == null)
          {
            this.setState({ avatarSource2: source })
            cantImg++
            console.log(cantImg)
           }else if(this.state.avatarSource3 == null)
          {
            this.setState({ avatarSource3: source })
            cantImg++
            console.log(cantImg)
          }
      this.setState({ cantImg: cantImg })
      this.refs.x.focus()
      const dismissKeyboard = require('dismissKeyboard');
      dismissKeyboard();
      Keyboard.dismiss()

   }

 });

我目前收到错误消息“无法读取未定义的属性'showimagepicker'”

以下是屏幕截图:https://prnt.sc/ml7qi1

2 个答案:

答案 0 :(得分:0)

我“已解决”了这个问题,只需将imagapicker代码从React-Native修改为EXPO Image-Picker,如果您想了解更多信息,请参见文档https://docs.expo.io/versions/latest/sdk/imagepicker/

答案 1 :(得分:0)

我通过更新导入内容对其进行了修复:

import * as ImagePicker from 'react-native-image-picker';

ImagePicker.showImagePicker(options, (response) => {
         // code here
};

对我有用