Skip to content

Commit

Permalink
fix: order of selected media items was not preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
MikkoKuivanenRS committed Jan 3, 2024
1 parent d4f581f commit ed8dd0e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Source/Pages/Gallery/YPLibraryVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,17 @@ public final class YPLibraryVC: UIViewController, YPPermissionCheckable {
}

// Fill result media items array
var resultMediaItems: [YPMediaItem] = []
var resultMediaItems: [YPMediaItem?] = Array(repeating: nil, count: selectedAssets.count)
let asyncGroup = DispatchGroup()

for asset in selectedAssets {
for (index, asset) in selectedAssets.enumerated() {
asyncGroup.enter()

switch asset.asset.mediaType {
case .image:
self.fetchImageAndCrop(for: asset.asset, withCropRect: asset.cropRect) { image, exifMeta in
let photo = YPMediaPhoto(image: image.resizedImageIfNeeded(), exifMeta: exifMeta, asset: asset.asset)
resultMediaItems.append(YPMediaItem.photo(p: photo))
resultMediaItems[index] = YPMediaItem.photo(p: photo)
asyncGroup.leave()
}

Expand All @@ -492,7 +492,7 @@ public final class YPLibraryVC: UIViewController, YPPermissionCheckable {
if let videoURL = videoURL {
let videoItem = YPMediaVideo(thumbnail: thumbnailFromVideoPath(videoURL),
videoURL: videoURL, asset: asset.asset)
resultMediaItems.append(YPMediaItem.video(v: videoItem))
resultMediaItems[index] = YPMediaItem.video(v: videoItem)
} else {
ypLog("YPLibraryVC -> selectedMedia -> Problems with fetching videoURL.")
}
Expand All @@ -504,7 +504,7 @@ public final class YPLibraryVC: UIViewController, YPPermissionCheckable {
}

asyncGroup.notify(queue: .main) {
multipleItemsCallback(resultMediaItems)
multipleItemsCallback(resultMediaItems.compactMap { $0 })
self.delegate?.libraryViewFinishedLoading()
}
} else {
Expand Down

0 comments on commit ed8dd0e

Please sign in to comment.