Skip to content

fix: keep open menus from closing on background updates - #4501

Merged
marinofaggiana merged 2 commits into
masterfrom
fix/menu-dismiss-4500
Nov 27, 2026
Merged

marinofaggiana merged 2 commits into
masterfrom
fix/menu-dismiss-4500

Conversation

@marinofaggiana

@marinofaggiana marinofaggiana commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Open menus (the "…" on files, the (+), the account switcher, the overflow menu, share and Trash menus) no longer close by themselves when a transfer, sync or capability update refreshes the screen.

Closes #4500

Why

An external event closed an open menu in two ways:

  1. The button that owns the menu was destroyed: reloadData() recreated the cell with the "…" button.
  2. The menu was replaced while open: button.menu = newMenu on every refresh (the (+) menu, the account switcher), and additionalOverflowItems reassigned on every data reload.

The previous mitigation only covered the file list. It paused the reload debouncer from a tap-gesture observer and resumed it from a global touch monitor (NCApplication / UserInteractionMonitor in main.swift), not from the actual menu lifecycle.

What changed

  • NCMenuButton (new): a UIButton that tracks its menu through the public UIControl hooks contextMenuInteraction(_:willDisplayMenuFor:animator:) and contextMenuInteraction(_:willEndFor:animator:). If menu is assigned while the menu is open, the new menu is applied after it closes.
  • NCMenuPresentationMonitor (new): counts open menus app-wide, posts show/hide notifications and offers performWhenNoMenuVisible(for:_:) for screens without a debouncer. While a menu is open it keeps only the last pending update of each screen.
  • File list: NCCollectionViewCommon pauses debouncerReloadData while any menu is open. Long-press menus on files and recommendations are reported too.
  • Buttons switched to NCMenuButton: "…" on list, grid and recommendation cells, (+), account switcher, Trash cells, share link/user cells, comment cells and profile avatars.
  • Trash and share panel: data updates and reloads wait until no menu is open, then run once with the latest data.
  • Overflow menu: installed once per navigation item; it reads the latest options when opened.
  • Removed: NCApplication, UserInteractionMonitor, the tap-gesture observers, onMenuIntent and the serInteractionMonitor notification. main.swift is gone and AppDelegate uses @main.

Not covered yet: notifications, Activity avatars, viewer and album bar-button menus, Media long-press, SwiftUI Menus.

How to test

  1. Start a long upload or sync so the file list keeps refreshing.
  2. Open and keep open for a few seconds: the "…" menu of a file (list and grid), a long-press menu, the (+), the account menu and the overflow menu. None should close by itself, and the list should refresh after you close it.
  3. Open Trash and immediately open the "…" of an item while the list is loading. Same check.
  4. As the owner of a share, open the share panel and immediately open the "…" of a link or user share while shares load. Pick "Delete share": the list updates once the menu has closed.
  5. Pick an action from each menu and check it still works.

Unit tests for the monitor: Tests/NextcloudUnitTests/NCMenuPresentationMonitorTests.swift.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI
Notes for reviewers
  • NCMenuButton releases its "open" state in didMoveToWindow when removed from the window, so the monitor cannot stay stuck on "open" if a button disappears with its menu.
  • syncReloadDataWithOpenMenus() re-checks the monitor after each pause/resume hop to the debouncer actor, so a quick open/close cannot leave reloads paused.
  • AccountSwitcherButton (local class in NCFilesNavigationController) was replaced by NCMenuButton.onMenuWillShow.
  • Not built or run by the assistant; the author verifies build, tests and behaviour on a live instance.

🤖 Generated with Claude Code

Menus closed by themselves when a transfer, sync or capability update
refreshed the screen: a reload recreated the button that owns the menu,
or code replaced the button's menu while it was open. The previous
mitigation only covered the file list and relied on a global touch
monitor and tap-gesture observers instead of the real menu lifecycle.

NCMenuButton now tracks its own menu through the UIControl context-menu
hooks and applies a replaced menu only after the menu closes.
NCMenuPresentationMonitor counts open menus app-wide, so the file list,
Trash and the share panel can hold back their reloads until the user
has closed the menu. The navigation overflow menu is installed once and
reads the latest options when opened, instead of being replaced on every
reload. The custom UIApplication subclass is no longer needed, so the
app starts through @main on AppDelegate.

Fixes #4500

Assisted-by: Claude Code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
While a menu was open, every update for Trash or the share panel was
queued and all of them ran when the menu closed, reloading the same
screen several times in a row. Each update reads the latest data when it
runs, so only the last one per screen is needed.

The reload at the start of the Trash listing is skipped while a menu is
open instead of queued: the listing always ends with a full reload, and
a queued plain reload would have replaced that data update.

Assisted-by: Claude Code:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Marino Faggiana <marino.faggiana@nextcloud.com>
@marinofaggiana
marinofaggiana merged commit 190f286 into master Nov 27, 2026
6 checks passed
@marinofaggiana
marinofaggiana deleted the fix/menu-dismiss-4500 branch November 27, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Menus close by themselves when a background event refreshes the UI

1 participant