[英]react native open gallery using image picker
//I was not able to open the gallery by using the react native image picker
import React, { useState } from 'react'
import { launchCamera, launchImageLibrary } from 'react-native-image-picker'
import * as ImagePicker from 'react-native-image-picker'
import { StyleSheet,Text,View,TouchableOpacity,Dimensions,Pressable,} from 'react-native'
import { TextInput } from 'react-native-gesture-handler'
const WIDTH = Dimensions.get('window').width
const HEIGHT_Modal = 250
const UploadModal = ({ changeModalVis }) => {
const [response, setResponse] = useState(null)
console.log('res', response)
const closeModal = (bool, data) => {
changeModalVis(bool)
}
const options = {
title: 'Select Image',
type: 'library',
options: {
selectionLimit: 1,
mediaType: 'photo',
includeBase64: false,
},
}
const openGallery = () => {
ImagePicker.launchImageLibrary(options, setResponse)
}
//render..................................................... //使成为............................................... ……
return (
<TouchableOpacity disabled={true} style={styles.container}>
<View style={styles.modal}>
<View style={styles.textView}>
<Text
style={{
fontSize: 13,
padding: 10,
fontWeight: 'bold',
color: '#9b9e9e',
}}
>
Choose an option
</Text>
<TouchableOpacity style={styles.pressableUpperBody}>
<Text style={styles.text} onPress={openGallery}> <------error on press
Photos
</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.pressableUpperBody}>
<Text style={styles.text}>Capture Image</Text>
</TouchableOpacity>
</View>
<View style={styles.pressableUpperBody}>
<TouchableOpacity
style={styles.pressable}
onPress={() => closeModal(false, 'cancel')}
>
<Text style={styles.text}>Cancel</Text>
</TouchableOpacity>
</View>
</View>
</TouchableOpacity>
)
}
export default UploadModal导出默认 UploadModal
//getting the following error when I press on photos onPress
[Unhandled promise rejection: TypeError: null is not an object (evaluating '_reactNative.NativeModules.ImagePickerManager.launchImageLibrary')]
........................................................................................................................................................................................................ ..................................................... ..................................................... ..................................................... .....................................................
Did you make sure to clean your app and build again, you usually have to do that after installing a library that relies on native modules.您是否确保清理您的应用程序并重新构建,您通常必须在安装依赖本机模块的库后执行此操作。
Basically you'll have to do stuff like cd ios && pod install
cd android &&./gradlew clean
close your bundler and build/run your app again, sometimes you might wanna clear the cache too.基本上你必须做
cd ios && pod install
cd android &&./gradlew clean
关闭你的捆绑器并再次构建/运行你的应用程序,有时你可能也想清除缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.