Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIKitBackend support for Menu #106

Open
bbrk24 opened this issue Feb 21, 2025 · 1 comment · May be fixed by #118
Open

UIKitBackend support for Menu #106

bbrk24 opened this issue Feb 21, 2025 · 1 comment · May be fixed by #118

Comments

@bbrk24
Copy link
Contributor

bbrk24 commented Feb 21, 2025

The current methods on AppBackend for creating and updating menus are incompatible with how UIMenu works.

There are two ways to display a context menu in UIKit:

  1. Create the UIMenu object in advance and attach it to a UIButton.
  2. Use a UIContextMenuInteraction, which listens for a 3D Touch, long press, right-click, etc depending on the device. When it detects the appropriate form of interaction, it asks its delegate for a UIContextMenuConfiguration object, whose initializer takes a callback that returns UIMenu. It sounds convoluted, but it lets you defer creation of the UIMenu object until it's actually displayed. The problem lies in the particular form of interaction it requires.

The former is closer to how Menu actually works:

backend.updateButton(
widget,
label: label,
action: {
let menu = backend.createPopoverMenu()
children.menu = menu
backend.updatePopoverMenu(
menu,
content: content,
environment: environment
)
backend.showPopoverMenu(menu, at: SIMD2(0, size.y + 2), relativeTo: widget) {
children.menu = nil
}
},
environment: environment
)

However, UIKitBackend can't implement showPopoverMenu to accommodate this exact code. It would have to know that the button is being used for a context menu rather than an arbitrary action, and associate the menu with the button.

@stackotter
Copy link
Owner

I agree with your conclusion; AppBackend's popover API should be updated to attach pop overs to buttons rather than displaying them at specific pixel positions relative to a given widget at the point when they need to appear. If this causes issues for some of the existing backends, it may be that we have to provide two alternative APIs for backends to use when providing Menu support (backends would have to specify which one they want consumers to use, and Menu would have to have a separate implementation for each).

@bbrk24 bbrk24 linked a pull request Mar 19, 2025 that will close this issue
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 a pull request may close this issue.

2 participants