我的功能提供了一个小图像图标作为可触摸的按钮来上传或拍照,使用"react-native-image-picker": "^3.3.2"。
我收到 error: ,与此GitHub 问题Cannot read property 'launchImageLibrary' of undefined相同,但如您所见,我的代码已经按照他们的指示进行了导入。
这是我的完整代码:
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 = { …Run Code Online (Sandbox Code Playgroud)