Skip to content

Commit

Permalink
fix(camera): now we honor users selection order
Browse files Browse the repository at this point in the history
Due to a race condition, pickImages on iOS did not honor the order in which users selected images.
Fixes: ionic-team#1950
  • Loading branch information
l0ll098-at-mmfg committed Dec 5, 2023
1 parent 5fac335 commit c75d27e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions camera/ios/Plugin/CameraPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,12 @@ extension CameraPlugin: PHPickerViewControllerDelegate {
return
}
if multiple {
var images: [ProcessedImage] = []
var images: [ProcessedImage?] = Array(repeating: nil, count: results.count)
var processedCount = 0
for img in results {

for index in results.indices {
let img = results[index]

guard img.itemProvider.canLoadObject(ofClass: UIImage.self) else {
self.call?.reject("Error loading image")
return
Expand All @@ -266,11 +269,11 @@ extension CameraPlugin: PHPickerViewControllerDelegate {
asset = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: nil).firstObject
}
if let processedImage = self?.processedImage(from: image, with: asset?.imageData) {
images.append(processedImage)
images[index] = processedImage
}
processedCount += 1
if processedCount == results.count {
self?.returnImages(images)
self?.returnImages(images.compactMap({ $0 }))
}
} else {
self?.call?.reject("Error loading image")
Expand Down

0 comments on commit c75d27e

Please sign in to comment.