Repository navigation
fix: keep open menus from closing on background updates - #4501
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
reloadData()recreated the cell with the "…" button.button.menu = newMenuon every refresh (the (+) menu, the account switcher), andadditionalOverflowItemsreassigned 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/UserInteractionMonitorinmain.swift), not from the actual menu lifecycle.What changed
NCMenuButton(new): aUIButtonthat tracks its menu through the publicUIControlhookscontextMenuInteraction(_:willDisplayMenuFor:animator:)andcontextMenuInteraction(_:willEndFor:animator:). Ifmenuis 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 offersperformWhenNoMenuVisible(for:_:)for screens without a debouncer. While a menu is open it keeps only the last pending update of each screen.NCCollectionViewCommonpausesdebouncerReloadDatawhile any menu is open. Long-press menus on files and recommendations are reported too.NCMenuButton: "…" on list, grid and recommendation cells, (+), account switcher, Trash cells, share link/user cells, comment cells and profile avatars.NCApplication,UserInteractionMonitor, the tap-gesture observers,onMenuIntentand theserInteractionMonitornotification.main.swiftis gone andAppDelegateuses@main.Not covered yet: notifications, Activity avatars, viewer and album bar-button menus, Media long-press, SwiftUI
Menus.How to test
Unit tests for the monitor:
Tests/NextcloudUnitTests/NCMenuPresentationMonitorTests.swift.🤖 AI (if applicable)
Notes for reviewers
NCMenuButtonreleases its "open" state indidMoveToWindowwhen 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 inNCFilesNavigationController) was replaced byNCMenuButton.onMenuWillShow.🤖 Generated with Claude Code