1
  // 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() function call no of amount times selectedPhototap() function and selectedPhotoTap() function insert path to realm 、しかし問題は、最後の画像パスのみを保存することです。関数 selectedPhotoTap でキャプチャしたすべての画像を挿入したい 誰か助けてください

4

1 に答える 1