Don't report an empty media selection as a successful pick

Both PhotoLibraryPicker and DocumentPicker reported failures via .error
but still emitted .selectedMediaAtURLs([]) when every selected item
failed to load or export (e.g. an iCloud photo that isn't downloaded, or
a document that fails the security-scoped temp copy) - an empty "success"
that consumers had to defend against. Skip that emission in both, and
report .error for PhotoLibraryPicker's previously silent
missing-content-type case so the user gets feedback.
This commit is contained in:
Stefan Ceriu
2026-06-22 14:20:58 +03:00
parent 101fc7573b
commit 1e7a9a5ae5
2 changed files with 13 additions and 0 deletions
@@ -90,6 +90,11 @@ struct DocumentPicker: UIViewControllerRepresentable {
}
}
guard !selectedURLs.isEmpty else {
// Every picked document failed to copy; each failure was already surfaced via .error.
return
}
documentPicker.callback(.selectedMediaAtURLs(selectedURLs))
}
}
@@ -104,6 +104,11 @@ struct PhotoLibraryPicker: UIViewControllerRepresentable {
return selectedURLs.compactMap { $0 }
}
guard !selectedURLs.isEmpty else {
// Every selected item failed to load; each failure was already surfaced via .error.
return
}
photoLibraryPicker.callback(.selectedMediaAtURLs(selectedURLs))
}
}
@@ -114,6 +119,9 @@ struct PhotoLibraryPicker: UIViewControllerRepresentable {
let provider = result.itemProvider
guard let contentType = provider.preferredContentType else {
Task { @MainActor in
photoLibraryPicker.callback(.error(.failedLoadingFileRepresentation(nil)))
}
return nil
}