Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Compose - Alternative to PlainTooltipBox (deprecated)

After updating to Compose BOM 2024.02.01, which implements Material 3 v2.0, I realized that I can't use PlainTooltipBox anymore. Instead, I see TooltipBox and BasicTooltipBox (which is implemented by TooltipBox).

For both I need to set a PopupPositionProvider parameter, but I can't find an example anywhere of how to get and use this.

Can you please explain how to implement the new ToolTip?

The old one was so easy to use 😢, but I know these are Experimental APIs and subject to changes.

Thank you!

like image 270
Peter Araujo Avatar asked Oct 15 '25 04:10

Peter Araujo


1 Answers

The PopupPositionProvider is just a simple interface with a single function that defines where the tooltip should be positioned. You can implement that yourself or you can use the default implementation TooltipDefaults.rememberPlainTooltipPositionProvider():

TooltipBox(
    positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
    tooltip = {
        PlainTooltip {
            Text(/* tooltip content */)
        }
    },
    state = rememberTooltipState(),
) {
    // tooltip anchor
}
like image 193
Leviathan Avatar answered Oct 17 '25 17:10

Leviathan