I am using react-native ImagePicker
to select photos and then save it in AWS S3
. Every thing works fine but I have one problem.
Problem:
I select 3 images
using ImagePicker
and I am loading an activity indicator
when images are uplaoding. I want to turn off the activity indicator
when all 3 images are added to my array
.
But I don't know how to check if all 3 images are added to the array.
This is my code:
ImagePicker.openPicker({
multiple: true,
maxFiles: 3
}).then(response => {
...
let image = {
uri: response.uri,
width: newWidth,
height: newHeight,
name: _fileName,
type: 'image/png'
}
const config = {
bucket: 'bucket',
region: 'ap-northeast-2',
accessKey: 'mykey',
secretKey: 'secretkey',
successActionStatus: 201
}
RNS3.put(image, config)
.then(responseFromS3 => {
this.setState({
imageUrl: [...this.state.imageUrl, responseFromS3.body.postResponse.location]
},
//Every time when image is added the call back below is called. Which is what I don't want.
//I want the call back to be called when all three images are added the the array.
()=> {this.setState({activityIndicator:false})
//I want to change the status of my activityIndicator to false when all 3 images are added to the array.
//However, this.setState({activityIndicator:false}) is called when one Image is added the to array.
})
})
}).catch((err) => {
console.log(err);
})
})
}).catch(err => {
this.setState({loadingImageGifVisible:false})
})
}