javascript - react-native:如何检查是否所有图像都添加到数组中
问题描述
我正在使用 react-nativeImagePicker
选择照片,然后将其保存在AWS S3
. 每件事都很好,但我有一个问题。
问题:
我选择3 images
使用ImagePicker
,我正在加载activity indicator
图像上传的时间。我想关掉activity indicator
所有的3 images are added to my array
。
但我不知道如何检查是否所有 3 个图像都添加到数组中。
这是我的代码:
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})
})
}
解决方案
推荐阅读
- sqlite - SQLite 按 dd:mm 排序
- bash - 在 MacOS 和 Linux 上运行不同的 Shell 脚本
- javascript - Admin-on-rest 是否提供日期范围选择器
- sql-server - 按列选择每个组中不同的项目
- android - 从 Google Play 下载后首次启动应用程序崩溃 (ExceptionInInitializerError)
- spring-boot - 带有客户端证书的 RestTemplate
- c# - 当前上下文中不存在“InitializeComponent”
- angular - 角度地理定位 - 显示某个位置,而不是我当前的位置
- angular - Angular 2+ 在数组中的单个对象上异步执行 setTimeOut
- wpf - XAML:样式 ControlTemplate 故事板动画不会播放,但触发被击中