javascript - 我想使用react-native-image-picker捕获多个图像

标签 javascript react-native react-native-image-picker

  // add no of images equal to Qty

handleQuantity(qty) {
    this.setState({ qty: qty })
    for (let i = 0; i < qty; i++) {
        this.selectPhotoTapped(i)
    }

}



selectPhotoTapped(count) {
    const options = {
        quality: 1.0,
        maxWidth: 500,
        maxHeight: 500,
        storageOptions: {
            skipBackup: true
        }
    };

    ImagePicker.launchCamera(options, (response) => {
        console.log(response);
        if (response.didCancel) {
            console.log('User cancelled photo picker');
        }
        else if (response.error) {
            console.log('ImagePicker Error: ', response.error);
        }
        else {
            //let source = { uri: response.uri };
            // this.setState({
            //     ImageSourceArr: [...this.state.ImageSourceArr, source]
            // });
            Realm.open(databaseOptions).then(realm => {
                realm.write(() => {
                    realm.create(Images_SCHEMA, {
                        id: count,
                        path: response.uri
                    });

                    // this.setState({ size: realm.objects(Images_SCHEMA).length });
                    const res = realm.objects(Images_SCHEMA)
                    let res2 = JSON.parse(JSON.stringify(res))
                    for (let key in res2) {
                        this.setState({
                            ImageSourceArr: [...this.state.ImageSourceArr, res2[key].path],
                            size: realm.objects(Images_SCHEMA).length
                        });
                    }
                });
            });

        }

    });

}

handleQuantity() 函数调用数量次数乘以 selectedPhototap() 函数 和 selectedPhotoTap() 函数将路径插入领域,但问题是它只存储最后一个图像路径,我想插入由函数 selectedPhotoTap 捕获的所有图像 请任何人帮助我

最佳答案

react-native-image-picker does not support for multiple image selection, crop tool, and landscape support for native iOS functionality - not issues with the library. If you need these things, react-native-image-crop-picker might be a better choice for you.

https://github.com/ivpusic/react-native-image-crop-picker

关于javascript - 我想使用react-native-image-picker捕获多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52981582/

相关文章:

javascript - req.body.object 未定义

react-native - 将 Ignite 与 create-react-native-app 结合使用

android - 全局应用内通知

react-native-image-picker 减少文件的大小和质量

javascript - Angular 循环

javascript - `onChangeText={(text) => this.setState({text})` 是如何工作的?

javascript - 如果选中单选按钮则隐藏内容

react-native - React Native - 使用 Moment.js 自定义日期格式

React-native-image-picker 在捕获图像时重新加载整个应用程序