From 9895157231f047340ca248158290b0bc5b9d9cbd Mon Sep 17 00:00:00 2001 From: Ryo Tsuzukihashi Date: Sun, 19 May 2024 03:42:11 +0900 Subject: [PATCH] Update PHPicker.swift --- Sources/ImagePickerSwiftUI/PHPicker.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/ImagePickerSwiftUI/PHPicker.swift b/Sources/ImagePickerSwiftUI/PHPicker.swift index 9498f0b..884c554 100644 --- a/Sources/ImagePickerSwiftUI/PHPicker.swift +++ b/Sources/ImagePickerSwiftUI/PHPicker.swift @@ -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) { @@ -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 } }