Skip to content

Commit

Permalink
Update PHPicker.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzukihashi committed May 18, 2024
1 parent 743dbaf commit 9895157
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Sources/ImagePickerSwiftUI/PHPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public struct PHPicker: UIViewControllerRepresentable {

public func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
Task {
if results.isEmpty {
parent.isPresented = false
return
}

for result in results {
do {
if let image = try await loadImage(result: result) {
Expand All @@ -59,12 +64,14 @@ public struct PHPicker: UIViewControllerRepresentable {
if let videoURL = try await loadVideo(result: result) {
parent.videoURLs.append(videoURL)
}

if results.last == result {
parent.isPresented = false
}
} catch {
print(error.localizedDescription)
}
}

parent.isPresented = false
}
}

Expand Down

0 comments on commit 9895157

Please sign in to comment.