【问题标题】:undefined is not a function (near '...ImagePicker.showImagePicker...')undefined 不是函数(在'...ImagePicker.showImagePicker...'附近)
【发布时间】:2021-06-10 07:46:30
【问题描述】:

enter image description here 我已经成功安装了 react-native-image-picker,对于一个全新的 react native 应用程序,将其链接并通过 info.plist 文件授予正确的权限以访问相机、照片等...

当尝试 openGallery() 时,我收到以下警告并且没有图像库打开: TypeError;undefined is not a function ('...ImagePicker.showImagePicker...'附近)

imagePickerHandler = () => {
ImagePicker.showImagePicker(options, 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 {
    Crop.openCropper({
      path: response.uri,
      includeBase64: true,
      width: 800,
      height: 340,
      cropperStatusBarColor: theme.colors.gary1,
      cropperActiveWidgetColor: theme.colors.primary,
      cropperToolbarColor: theme.colors.black,
      cropperToolbarWidgetColor: theme.colors.white,
    }).then(image => {
      this.setState({
        image: image.data,
        image_extension:
          image.path.split('.')[image.path.split('.').length - 1],
      });
    });
  }
});

};

在此处输入代码

【问题讨论】:

  • 错误具体告诉你错误发生在哪一行。您没有在代码块中提供行号,所以请准确告诉我们哪个函数调用失败。

标签: javascript react-native


【解决方案1】:

尝试进行命名导出

https://github.com/react-native-image-picker/react-native-image-picker/issues/1528

import {launchImageLibrary} from 'react-native-image-picker' fixed it

【讨论】:

  • 我使用 import * as ImagePicker from 'react-native-image-picker';从 'react-native-image-crop-picker' 导入 * 作为作物;我还是有这个问题
【解决方案2】:

错误来自Crop.openCropper 改成Crop.openPicker

Crop.openPicker({
      path: response.uri,
      includeBase64: true,
      width: 800,
      height: 340,
      cropping: true,
      cropperStatusBarColor: theme.colors.gary1,
      cropperActiveWidgetColor: theme.colors.primary,
      cropperToolbarColor: theme.colors.black,
      cropperToolbarWidgetColor: theme.colors.white,
    })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 2015-10-29
    相关资源
    最近更新 更多