Skip to content

Commit 051ec1f

Browse files
committed
Wrap Icon in TopMenuButtonImpl in a TooltipBox to be able to show a tooltip for Toolbar menu items
- On Android, long pressing on a Toolbar menu item should display the menu items' names in a tooltip - The Tooltip's background color is not correct yet in light mode (it uses a dark color for some reason) - Content description is used as the tooltip text
1 parent bd7e3e7 commit 051ec1f

File tree

1 file changed

+24
-12
lines changed
  • ui-components/src/commonMain/kotlin/org/jetbrains/kotlinconf/ui/components

1 file changed

+24
-12
lines changed

ui-components/src/commonMain/kotlin/org/jetbrains/kotlinconf/ui/components/TopMenuButton.kt

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import androidx.compose.foundation.layout.padding
88
import androidx.compose.foundation.layout.size
99
import androidx.compose.foundation.selection.toggleable
1010
import androidx.compose.foundation.shape.CircleShape
11+
import androidx.compose.material3.ExperimentalMaterial3Api
1112
import androidx.compose.material3.Icon
13+
import androidx.compose.material3.PlainTooltip
14+
import androidx.compose.material3.TooltipBox
15+
import androidx.compose.material3.TooltipDefaults
16+
import androidx.compose.material3.rememberTooltipState
1217
import androidx.compose.runtime.Composable
1318
import androidx.compose.runtime.getValue
1419
import androidx.compose.runtime.mutableStateOf
@@ -29,6 +34,7 @@ import org.jetbrains.compose.ui.tooling.preview.Preview
2934
import org.jetbrains.kotlinconf.ui.theme.KotlinConfTheme
3035
import org.jetbrains.kotlinconf.ui.theme.PreviewHelper
3136

37+
@OptIn(ExperimentalMaterial3Api::class)
3238
@Composable
3339
private fun TopMenuButtonImpl(
3440
icon: DrawableResource,
@@ -38,18 +44,24 @@ private fun TopMenuButtonImpl(
3844
iconColor: Color,
3945
modifier: Modifier = Modifier,
4046
) {
41-
Icon(
42-
modifier = modifier
43-
.padding(6.dp)
44-
.size(36.dp)
45-
.clip(CircleShape)
46-
.then(interactionModifier)
47-
.background(backgroundColor)
48-
.padding(6.dp),
49-
painter = painterResource(icon),
50-
contentDescription = contentDescription,
51-
tint = iconColor,
52-
)
47+
TooltipBox(
48+
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
49+
tooltip = { PlainTooltip { Text(contentDescription) } },
50+
state = rememberTooltipState()
51+
) {
52+
Icon(
53+
modifier = modifier
54+
.padding(6.dp)
55+
.size(36.dp)
56+
.clip(CircleShape)
57+
.then(interactionModifier)
58+
.background(backgroundColor)
59+
.padding(6.dp),
60+
painter = painterResource(icon),
61+
contentDescription = contentDescription,
62+
tint = iconColor,
63+
)
64+
}
5365
}
5466

5567
/**

0 commit comments

Comments
 (0)