在React Native CameraRoll上调用getPhotos函数时,是否有最佳方法可以同时获取多少张照片?
CameraRoll.getPhotos({
first: 10000,
assetType: 'Photos',
})
我希望通过创建一个while循环来获取用户设备上的每张照片,直到我拥有每张照片。最好一次获取更多,即10,000以上,并通过while循环进行更少的迭代,或者我应该进行较小的调用以一次获得100,1000等照片?
我的完整代码块:
async fetchAllImages() {
let morePhotosToFetch = true;
let photosAfter = '';
let photos = [];
while(morePhotosToFetch) {
let response = await this.fetchImages(photosAfter);
morePhotosToFetch = response.morePhotosToFetch;
photosAfter = response.photosAfter;
photos = [...photos, ...response.assets];
}
return photos;
}
async fetchImages(photosAfter) {
let { edges, page_info } = await CameraRoll.getPhotos({
/** SHOULD I FETCH SMALLER BATCHES HERE? */
first: 10000,
after: photosAfter === '' ? undefined : photosAfter,
assetType: 'Photos',
})
return {
assets: edges,
morePhotosToFetch: page_info.has_next_page,
photosAfter: page_info.end_cursor,
}
}