KEMBAR78
[Desktop] Initial support for the new context menu API by m-sasha · Pull Request #2196 · JetBrains/compose-multiplatform-core · GitHub
Skip to content

Conversation

@m-sasha
Copy link
Member

@m-sasha m-sasha commented Jun 25, 2025

There are still several subtasks remaining, but this provides basic support for the new context menu API on the desktop.

I don't think we should enable this by default until the subtasks have been completed.

Testing

Tested manually.
Note that you need to set ComposeFoundationFlags.isNewContextMenuEnabled = true to use this.

This should be tested by QA

Release Notes

Features - Desktop

  • Basic support for new context menu API

@m-sasha m-sasha requested review from mazunin-v-jb and terrakok June 25, 2025 12:47

/** A [TextContextMenuComponent] separator in a text context menu. */
object TextContextMenuSeparator : TextContextMenuComponent(TextContextMenuSeparator)
object TextContextMenuSeparator : TextContextMenuComponent(Any())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid changing commonMain here? Do you already have AOSP CL with this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do explicit cherry pick then

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would unnecessarily take more time.
It'll just be resolved with no conflicts (or identical code in both branches) in the next merge, which will definitely happen before release.

onKeyEvent = {
if (it.type == KeyEventType.KeyDown) {
when (it.key.nativeKeyCode) {
java.awt.event.KeyEvent.VK_DOWN -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have common/compose wrappers for these code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not new code. I'd rather not touch it in this PR.

* @param leadingIcon Icon that precedes the label in the context menu.
* @param onClick Action to perform upon the item being clicked/pressed.
*/
fun TextContextMenuBuilderScope.item(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's popup/canvas based, why it's desktop-only? Are we sure that it will be popup/canvas based long term?
I mean defining leadingIcon as composable assumes some implementation details and expectations

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's popup/canvas based, why it's desktop-only?

I'm doing the desktop part and I don't know the capabilities on other platforms. If it turns out we can move this to skikoMain, I will be in favor of that.

Are we sure that it will be popup/canvas based long term?
I mean defining leadingIcon as composable assumes some implementation details and expectations

I don't see why we shouldn't support a composable leading icon on the desktop.
In fact, I plan to add another extension which allows the entire item to be composable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need this code in desktop browsers. there are no differences between desktop and desktop browsers

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't put it in skikoMain unless it's also supported by ios. And I don't think we have a desktopWeb source set.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I don't think we have a desktopWeb source set

And we shouldn't! Anther reminder that compilation target != platform

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory "desktop" logic should be in common - Chrome OS (desktop) uses androidMain sourceset

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For logic, that's correct. But this is API. We can't put this in common because it's not supported on android or ios.

@terrakok
Copy link
Member

Could we have the Desktop context menu UI code in the skiko source set? Because we need the same logic for desktop browsers

@m-sasha
Copy link
Member Author

m-sasha commented Jun 26, 2025

I'm not sure how to share code between desktop and web.
Internal code we can put in skikoMain, but for public API it's a problem.

@m-sasha m-sasha force-pushed the m-sasha/desktop-new-context-menu-api branch from b693dc5 to 50e30f9 Compare June 26, 2025 21:32
@m-sasha
Copy link
Member Author

m-sasha commented Jun 29, 2025

@terrakok @MatkovIvan
I moved what made sense to skikoMain.

}

public final class androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope_desktopKt {
public static final fun item (Landroidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope;Ljava/lang/Object;Ljava/lang/String;ZLkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;)V
Copy link
Member

@MatkovIvan MatkovIvan Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that it's a final, desktop/jvm-only shape?

We can't put this in common because it's not supported on android or ios.

What exactly is not supported? Does it really depend on a "compilation target" but not on capabilities of underlaying platform ui toolkit or device type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well. I don't think that it's a question. I'm sure that we should NOT introduce any public API for specific compilation targets at foundation level

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that it's a final, desktop/jvm-only shape?

Do you want me to mark it at experimental? Corresponding function in androidMain is not experimental.

What exactly is not supported?

A composable leadingIcon.

Does it really depend on a "compilation target" but not on capabilities of underlaying platform ui toolkit or device type?

I don't understand the question, but what difference does it make? If on any platform we will not be able to support this API, then we can't have it in the corresponding compilation target.

Well. I don't think that it's a question. I'm sure that we should NOT introduce any public API for specific compilation targets at foundation level

I'm just replicating what Android does. See https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/foundation/foundation/src/androidMain/kotlin/androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope.android.kt;l=38?q=TextContextMenuBuilderScope.item&sq=&ss=androidx%2Fplatform%2Fframeworks%2Fsupport

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If on any platform we will not be able to support this API, then we can't have it in the corresponding compilation target.

It's not always the case

I'm just replicating what Android does

Android is always a special case in AOSP

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well. I don't think that it's a question. I'm sure that we should NOT introduce any public API for specific compilation targets at foundation level

We also have this. For example, desktop-only LocalTextContextMenu.

Copy link
Member Author

@m-sasha m-sasha Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not always the case

What happens when a developer uses this API and then runs the app on a platform that doesn't support it?

Android is always a special case in AOSP

We can't live in a world where we are not allowed to do the things Android is allowed. Especially when Android does the reference implementation...

TextContextMenuBuilderScope.addComponent is internal. So we can't put this extension function in ui.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked to Ivan, agreed that we should consult with the web and iOS implementors, and if they're ok, we can move this function to skikoMain.
Implementations which don't support composables can just ignore the leading icon, but we will need to document it in the kdoc of the function.

@m-sasha m-sasha force-pushed the m-sasha/desktop-new-context-menu-api branch 3 times, most recently from 9e0fd27 to 7346f5c Compare June 30, 2025 11:41
Copy link
Member

@MatkovIvan MatkovIvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as not-final-shape

@m-sasha m-sasha force-pushed the m-sasha/desktop-new-context-menu-api branch from 7346f5c to 02815d3 Compare July 3, 2025 13:19
@m-sasha m-sasha force-pushed the m-sasha/desktop-new-context-menu-api branch from 02815d3 to 419c686 Compare July 3, 2025 14:09
@m-sasha m-sasha force-pushed the m-sasha/desktop-new-context-menu-api branch from 419c686 to de65e08 Compare July 3, 2025 14:13
@m-sasha m-sasha merged commit a7e3fbf into jb-main Jul 4, 2025
10 checks passed
@m-sasha m-sasha deleted the m-sasha/desktop-new-context-menu-api branch July 4, 2025 08:59
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.

5 participants