-
Notifications
You must be signed in to change notification settings - Fork 102
[Desktop] Initial support for the new context menu API #2196
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
Conversation
|
|
||
| /** A [TextContextMenuComponent] separator in a text context menu. */ | ||
| object TextContextMenuSeparator : TextContextMenuComponent(TextContextMenuSeparator) | ||
| object TextContextMenuSeparator : TextContextMenuComponent(Any()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's taken from upstream: https://android-review.git.corp.google.com/c/platform/frameworks/support/+/3651634
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 -> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
Could we have the Desktop context menu UI code in the skiko source set? Because we need the same logic for desktop browsers |
|
I'm not sure how to share code between desktop and web. |
b693dc5 to
50e30f9
Compare
|
@terrakok @MatkovIvan |
...on/foundation/src/desktopMain/kotlin/androidx/compose/foundation/text/ContextMenu.desktop.kt
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
9e0fd27 to
7346f5c
Compare
There was a problem hiding this 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
.../androidx/compose/foundation/text/contextmenu/builder/TextContextMenuBuilderScope.desktop.kt
Outdated
Show resolved
Hide resolved
7346f5c to
02815d3
Compare
02815d3 to
419c686
Compare
419c686 to
de65e08
Compare
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 = trueto use this.This should be tested by QA
Release Notes
Features - Desktop