JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.3k stars 1.11k forks source link

Consider deprecation of `TooltipArea` in favor of `BasicTooltipBox` when it is no longer experimental #4275

Open igordmn opened 4 months ago

igordmn commented 4 months ago

And move all necessary functionality there.

There should be only one non-experimental way to show tooltips.

    @OptIn(ExperimentalFoundationApi::class)
    @Composable
    fun Content() {
        BasicTooltipBox(
            positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
            tooltip = {
                androidx.compose.material3.Text("Add to favorites")
            },
            state = rememberBasicTooltipState()
        ) {
            IconButton(
                onClick = { /* Icon button's click event */ }
            ) {
                androidx.compose.material3.Icon(
                    imageVector = Icons.Filled.Favorite,
                    contentDescription = "Localized Description"
                )
            }
        }
    }

Check also, how TooltipBox works. One of the known issues - it has isPersistent = false by default, which works bad on desktop.

m-sasha commented 4 months ago

Investigated BasicTooltipBox a bit. It doesn't seem suitable for desktop needs.

✅ I'm not sure what isPersistent does as it doesn't seem to have an effect on the desktop. Tooltips disappear immediately when the mouse cursor leaves the box. ❌ Tooltips appear immediately, without delay, when the mouse pointer is moved into the box. ❌ The positionProvider argument isn't documented properly. The user is left to guess where he could obtain a useful implementation (rememberComponentRectPositionProvider is one) ❌ There's no positionProvider implementation equivalent to TooltipPlacement.CursorPoint. rememberCursorPositionProvider remembers the position of the mouse pointer at the time of invocation.

m-sasha commented 4 months ago

The same comments apply to TooltipBox (which is also only available in material3).

MatkovIvan commented 4 months ago

Related: #4321

m-sasha commented 4 months ago

I see there's TooltipDefaults.rememberPlainTooltipPositionProvider which only positions the tooltip above the box.

igordmn commented 4 months ago

TooltipArea was designed for desktopMain and works well, but having 2 similar available API's doing one thing isn't good from the user perspective. We need to merge functionality with BasicTooltipBox (or with something else that will be instead of it)