Skip to content

Fix: add Cancel button to photo picker on macOS when Photos library is empty#509

Open
stakeswky wants to merge 1 commit intokeepassium:masterfrom
stakeswky:fix/photo-picker-empty-library-dismiss
Open

Fix: add Cancel button to photo picker on macOS when Photos library is empty#509
stakeswky wants to merge 1 commit intokeepassium:masterfrom
stakeswky:fix/photo-picker-empty-library-dismiss

Conversation

@stakeswky
Copy link

Problem

Fixes #507.

When the macOS Photos library is empty, PHPickerViewController renders with no close/cancel button and ignores Esc/Cmd+Q, leaving the user unable to dismiss the picker without force-quitting KeePassium.

Root cause

On macOS Catalyst, PHPickerViewController normally shows a Cancel button only when there is content to browse. With an empty library it shows a blank sheet with no interactive controls, and the system does not forward keyboard shortcuts to dismiss it.

Fix

After presenting the picker, inject a UIBarButtonItem(.cancel) into picker.navigationItem.leftBarButtonItem inside a #if targetEnvironment(macCatalyst) guard. Tapping it dismisses the picker and calls the completion handler with nil, matching the existing behaviour for a cancelled pick on all other paths.

The change is compile-time gated so it has zero impact on iOS builds.

@CLAassistant
Copy link

CLAassistant commented Feb 22, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@stakeswky
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

…s empty

When the Photos library is empty on macOS (Catalyst), PHPickerViewController
renders no close/cancel button and ignores Esc/Cmd+Q, leaving the user unable
to dismiss the picker without force-quitting the app (issue keepassium#507).

Fix: after presenting the picker, inject a UIBarButtonItem(.cancel) into its
navigationItem.leftBarButtonItem under #if targetEnvironment(macCatalyst).
Tapping it dismisses the picker and calls the completion handler with nil,
matching the existing behaviour for a cancelled pick.

Fixes keepassium#507
@stakeswky stakeswky force-pushed the fix/photo-picker-empty-library-dismiss branch from bb9b293 to c974e79 Compare February 26, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't close icon picker when macOS Photos library is empty

2 participants