From 658ed1cd1ae3047562483c708f7d3ac787fae5e9 Mon Sep 17 00:00:00 2001 From: stakeswky Date: Fri, 27 Feb 2026 04:23:00 +0800 Subject: [PATCH] Fix: allow dismissing photo picker on macOS when Photos library is empty (#507) On Mac Catalyst, PHPickerViewController defaults to isModalInPresentation = true, which prevents dismissal via Escape or clicking outside the sheet. When the Photos library is empty, the picker shows no cancel button, trapping the user. Set isModalInPresentation = false on Mac Catalyst so the sheet can always be dismissed interactively. Also fix swapped extension conformance labels (PHPickerViewControllerDelegate and UIAdaptivePresentationControllerDelegate were on the wrong extensions). --- KeePassium/util/photo-picker/GalleryPhotoPicker.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/KeePassium/util/photo-picker/GalleryPhotoPicker.swift b/KeePassium/util/photo-picker/GalleryPhotoPicker.swift index 89ed8be33..5a4792eb0 100644 --- a/KeePassium/util/photo-picker/GalleryPhotoPicker.swift +++ b/KeePassium/util/photo-picker/GalleryPhotoPicker.swift @@ -24,6 +24,9 @@ final class GalleryPhotoPicker: PhotoPicker { picker.delegate = self picker.presentationController?.delegate = self + #if targetEnvironment(macCatalyst) + picker.isModalInPresentation = false + #endif } override internal func _pickImageInternal() { @@ -44,7 +47,7 @@ final class GalleryPhotoPicker: PhotoPicker { } } -extension GalleryPhotoPicker: UIAdaptivePresentationControllerDelegate { +extension GalleryPhotoPicker: PHPickerViewControllerDelegate { func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { guard let result = results.first, result.itemProvider.canLoadObject(ofClass: UIImage.self) @@ -98,7 +101,7 @@ extension GalleryPhotoPicker: UIAdaptivePresentationControllerDelegate { } } -extension GalleryPhotoPicker: PHPickerViewControllerDelegate { +extension GalleryPhotoPicker: UIAdaptivePresentationControllerDelegate { func presentationControllerDidDismiss(_ presentationController: UIPresentationController) { _completion?(.success(nil)) }