【问题标题】:I Want to capture multiple images using react-native-image-picker我想使用 react-native-image-picker 捕获多个图像
【发布时间】:2018-10-25 04:54:56
【问题描述】:
  // 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 捕获的所有图像 请任何人帮助我

【问题讨论】:

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


    【解决方案1】:

    react-native-image-picker 不支持多个图像选择、裁剪工具和对原生 iOS 功能的横向支持 - 库没有问题。如果您需要这些东西,react-native-image-crop-picker 可能是您更好的选择。

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

    【讨论】:

    • Android 不支持 maxFile 功能
    • @ShoebSiddique 我认为没有一个 react-native 库支持在 android 上一次最多选择多张照片。你仍然可以使用这个库,并且只使用从数组返回的前 x 个图像。
    猜你喜欢
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-29
    • 2016-12-08
    • 2019-07-16
    • 2020-09-16
    相关资源
    最近更新 更多