简体   繁体   English

使用图像选择器反应原生开放画廊

[英]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.

相关问题 反应本机图像选择器 - React Native Image Picker 反应原生:图像正在使用 expo-image-picker 上传,但不使用 react-native-image-picker 上传 - react native : image is uploading using expo-image-picker but not uploading using react-native-image-picker React-native-image-picker 相机未打开 - React-native-image-picker camera doesn't open 为什么在 android 中不允许? 使用 react-native-image-picker - Why does not permitted in android ? using react-native-image-picker 使用 react-native-image-picker 在 react-native 中上传图像 - Uploading an image in react-native using react-native-image-picker 使用 react-native-image-picker 将图像从 React Native 上传到带有预签名 url 的 Amazon S3 - Upload Image from React Native using react-native-image-picker to Amazon S3 with presigned url 反应本机图像选择器无法显示图像 - React Native Image Picker Unable To Display Image 使用带有钩子的 React Native Picker - using react native picker with hooks React Native 如何以编程方式打开 react-native-dropdown-picker - React Native how to open react-native-dropdown-picker programmatically react-native-image-picker 中的 launchCamera() 安装在设备上时不会打开任何东西 - launchCamera() in react-native-image-picker doesn't open anything when installed on a device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM