-
-
Notifications
You must be signed in to change notification settings - Fork 0
Description
This feedback is a feature request for SwiftUI on macOS.
I would like to have an API for the Menu that delays the evaluation and generation of the content until the moment it is actually displayed.
Background
SwiftUI’s Menu is used also to display view controls like pop-up buttons. However, in such cases, its content is evaluated at the moment the button itself appears, although it’s not required until the menu is actually opened. Additionally, since the menu content isn’t re-evaluated when opened, if the content is dynamically generated, there could be a discrepancy between the actual state and the displayed state depending on the timing.
Considering these points, I’d like to delay generating the menu content until the moment it’s actually opened.
Use case
I am implementing a pop-up button with a menu similar to the Finder's “Open with” feature.
Determining the menu list incurs a cost because it requires scanning all applications on the machine and checking each one to see if it supports the target document type.
Since this pop-up menu is rarely opened, I want to defer this cost until it's really necessary.
Additionally, currently, if a new application is installed after the view containing the pop-up button is displayed, that application won't appear in the list even if it supports the target document.
Additional context
I’ve already asked on the Apple Developer Forum if there was an API to achieve this behavior, but I didn't receive any response.
Therefore, I'm assuming that no such API currently exists and am submitting this as request.
So, please post a reply if there is an appropriate API or way already exists.
https://developer.apple.com/forums/thread/802719
Environment
- macOS: Version 26.2 Beta (25C5031i)
- Xcode: Version 26.1 (17B54)