首页 > 解决方案 > 使用从“react-native-image-crop-picker”导入 ImagePicker 时出错;

问题描述

我正在尝试打开用户的画廊,以便他/她可以选择图像,并且我为此目的使用 react-native-image-crop-picker 模块,但我收到此错误:TypeError: null is not an object (evaluating ' _reactNativeImageCropPicker.default.openPicker')我使用这个来自https://github.com/ivpusic/react-native-image-crop-picker

import React from "react";
import { View, Text, StyleSheet, TextInput, NativeModules } from "react-native";
import ActionButton from "react-native-action-button";
import Icon from "react-native-vector-icons/Ionicons";
import ImagePicker from "react-native-image-crop-picker";

const ChooseImg = () => {
  ImagePicker.openPicker({
    width: 300,
    height: 400,
    cropping: false,
  }).then((image) => {
    console.log(image);
  });
};

export default function AddPost() {
  const PostBtn = () => {
    return (
      <>
        <View style={styles.container}>
          <TextInput
            style={styles.PostInputStyle}
            placeholder="What's on your mind?"
          />
        </View>
        <ActionButton buttonColor="#7b68ee">
          <ActionButton.Item
            buttonColor="#9b59b6"
            title="Camera"
            onPress={() => console.log("Camera tapped!")}
          >
            <Icon name="camera-outline" style={styles.actionButtonIcon} />
          </ActionButton.Item>
          <ActionButton.Item
            buttonColor="#3498db"
            title="Choose pictures"
            onPress={() => {
              console.log("Choose pictures tapped!");
              ChooseImg();
            }}
          >
            <Icon name="md-images-outline" style={styles.actionButtonIcon} />
          </ActionButton.Item>
        </ActionButton>
      </>
    );
  };

  return (
    <>
      <PostBtn />
    </>
  );
}

const styles = StyleSheet.create({
  container: {
    display: "flex",
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#f4f5f7",
  },
  PostInputStyle: {
    fontSize: 25,
    marginTop: 60,
    fontWeight: "bold",
  },
});

标签: javascriptreact-nativereact-native-android

解决方案


推荐阅读