KEMBAR78
Adopt new context menu API by ASalavei · Pull Request #2214 · JetBrains/compose-multiplatform-core · GitHub
Skip to content

Conversation

@ASalavei
Copy link

@ASalavei ASalavei commented Jul 2, 2025

Support ContextMenuArea for uiKit source set with default set of toolbar items.
Add LocalUIView to public (experimental for now) ui API to properly locate toolbar host view.
Increase the delay before the first toolbar shows the action to mitigate glitches connected with delayed menu item provision.

Fixes https://youtrack.jetbrains.com/issue/CMP-8431/iOS-Adopt-new-context-menu-API
Fixes https://youtrack.jetbrains.com/issue/CMP-7906/iOS-Trackpad.-BTF2.-Sontext-menu-doesnt-appear

Release Notes

Features - iOS

  • Support new context menu API with default menu

@ASalavei ASalavei marked this pull request as ready for review July 3, 2025 05:52
ASalavei added 4 commits July 4, 2025 11:46
# Conflicts:
#	compose/foundation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/text/input/internal/selection/TextFieldSelectionState.desktop.kt
#	compose/foundation/foundation/src/macosMain/kotlin/androidx/compose/foundation/text/input/internal/selection/TextFieldSelectionState.macos.kt
#	compose/foundation/foundation/src/uikitMain/kotlin/androidx/compose/foundation/text/input/internal/selection/TextFieldSelectionState.uikit.kt
ASalavei added 6 commits July 4, 2025 14:36
# Conflicts:
#	compose/foundation/foundation/src/uikitMain/kotlin/androidx/compose/foundation/text/input/internal/selection/TextFieldSelectionState.uikit.kt
@ASalavei ASalavei requested a review from MatkovIvan July 7, 2025 16:23
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 initial implementation, but I guess we'll need to revisit a few parts later:

  • sourceset in foundation during binding extraction
  • LocalUIView + existing controller during view-based entry point design

// menu items, which causes the context menu callout to blink.
// Adding a small delay resolves this issue.
ProvideDefaultPlatformTextContextMenuProviders(
menuDelay = 100.milliseconds,
Copy link
Member

Choose a reason for hiding this comment

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

Why 100? Does it work with 50? Can we use explicit trigger instead of delay?

Copy link
Author

@ASalavei ASalavei Jul 8, 2025

Choose a reason for hiding this comment

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

Yes, we can, but that we'll see glitches in context menu. Experimentally, 50 mills is not enough for some reasons.

}
}

@OptIn(ExperimentalComposeUiApi::class)
Copy link
Member

Choose a reason for hiding this comment

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

Add TODO to remove cross-module experimental API usage

Copy link
Author

Choose a reason for hiding this comment

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

I want to make the LocalUIView me a part of public API to ease platform integration for the developers.
Here will be an issue for that: https://youtrack.jetbrains.com/issue/CMP-8546/Remove-Experimental-flag-from-LocalUIView

@ASalavei ASalavei merged commit f9904c8 into jb-main Jul 8, 2025
11 checks passed
@ASalavei ASalavei deleted the andrei.salavei/support-new-toolbar branch July 8, 2025 17:27
) {
val toolbarProvider = LocalTextContextMenuToolbarProvider.current
val dropdownProvider = LocalTextContextMenuDropdownProvider.current
if (toolbarProvider == null || dropdownProvider == null) {
Copy link
Member

Choose a reason for hiding this comment

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

You need to attach the modifier and include the content even if both existing providers are non-null.

Copy link
Author

Choose a reason for hiding this comment

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

Tnx, will be fixed in the next MR


@OptIn(ExperimentalComposeUiApi::class)
@Composable
private fun ProvideDefaultPlatformTextContextMenuProviders(
Copy link
Member

Choose a reason for hiding this comment

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

We're creating a bit of a mess here.
There's already an expect ProvideDefaultPlatformTextContextMenuProviders function without the menuDelay argument, but we're not calling it here. In fact, it's neither actualized (except for an empty implementation) nor used in the uikit source set. So CommonContextMenuArea can't be used in this source-set.
@terrakok This looks messy. How should we clean it up?

Copy link
Author

Choose a reason for hiding this comment

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

I'll rename those in uikit source set.

Comment on lines +159 to +160
LocalTextContextMenuToolbarProvider provides (toolbarProvider ?: provider),
LocalTextContextMenuDropdownProvider provides (dropdownProvider ?: provider),
Copy link
Member

Choose a reason for hiding this comment

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

You can use providesDefault here instead.

Copy link
Author

Choose a reason for hiding this comment

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

Tnx! Will be fixed in the next MP

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.

4 participants