From f9fb034330d6e5c4f0cf9232649aa9a548e9e443 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Thu, 16 Nov 2023 21:01:12 +0700 Subject: [PATCH] Migrate deprecated tooltip components (#10141) --- .../kanade/presentation/components/AppBar.kt | 51 ++++++++++++++----- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/components/AppBar.kt b/app/src/main/java/eu/kanade/presentation/components/AppBar.kt index 98ded7540b..a8db1790f5 100644 --- a/app/src/main/java/eu/kanade/presentation/components/AppBar.kt +++ b/app/src/main/java/eu/kanade/presentation/components/AppBar.kt @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.material.TextFieldDefaults import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.outlined.ArrowBack import androidx.compose.material.icons.outlined.Close @@ -19,11 +18,15 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.PlainTooltipBox +import androidx.compose.material3.PlainTooltip import androidx.compose.material3.Text +import androidx.compose.material3.TextFieldDefaults +import androidx.compose.material3.TooltipBox +import androidx.compose.material3.TooltipDefaults import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarScrollBehavior +import androidx.compose.material3.rememberTooltipState import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable import androidx.compose.runtime.derivedStateOf @@ -186,13 +189,18 @@ fun AppBarActions( var showMenu by remember { mutableStateOf(false) } actions.filterIsInstance().map { - PlainTooltipBox( - tooltip = { Text(it.title) }, + TooltipBox( + positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(), + tooltip = { + PlainTooltip { + Text(it.title) + } + }, + state = rememberTooltipState(), ) { IconButton( onClick = it.onClick, enabled = it.enabled, - modifier = Modifier.tooltipTrigger(), ) { Icon( imageVector = it.icon, @@ -205,12 +213,17 @@ fun AppBarActions( val overflowActions = actions.filterIsInstance() if (overflowActions.isNotEmpty()) { - PlainTooltipBox( - tooltip = { Text(stringResource(R.string.abc_action_menu_overflow_description)) }, + TooltipBox( + positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(), + tooltip = { + PlainTooltip { + Text(stringResource(R.string.abc_action_menu_overflow_description)) + } + }, + state = rememberTooltipState(), ) { IconButton( onClick = { showMenu = !showMenu }, - modifier = Modifier.tooltipTrigger(), ) { Icon( Icons.Outlined.MoreVert, @@ -324,12 +337,17 @@ fun SearchToolbar( if (!searchEnabled) { // Don't show search action } else if (searchQuery == null) { - PlainTooltipBox( - tooltip = { Text(stringResource(R.string.action_search)) }, + TooltipBox( + positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(), + tooltip = { + PlainTooltip { + Text(stringResource(R.string.action_search)) + } + }, + state = rememberTooltipState(), ) { IconButton( onClick = onClick, - modifier = Modifier.tooltipTrigger(), ) { Icon( Icons.Outlined.Search, @@ -338,15 +356,20 @@ fun SearchToolbar( } } } else if (searchQuery.isNotEmpty()) { - PlainTooltipBox( - tooltip = { Text(stringResource(R.string.action_reset)) }, + TooltipBox( + positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(), + tooltip = { + PlainTooltip { + Text(stringResource(R.string.action_reset)) + } + }, + state = rememberTooltipState(), ) { IconButton( onClick = { onClick() focusRequester.requestFocus() }, - modifier = Modifier.tooltipTrigger(), ) { Icon( Icons.Outlined.Close,