From 4d6a9a7ec856d18c527ded29f49225094419e3f0 Mon Sep 17 00:00:00 2001 From: Artem Chepurnyi Date: Sun, 29 Dec 2024 11:58:28 +0200 Subject: [PATCH] fix: Add empty Tooltip implementation for Android platform --- .../keyguard/ui/tooltip/Tooltip.android.kt | 20 +++++++ .../artemchep/keyguard/ui/tooltip/Tooltip.kt | 51 +--------------- .../keyguard/ui/tooltip/Tooltip.desktop.kt | 60 +++++++++++++++++++ 3 files changed, 82 insertions(+), 49 deletions(-) create mode 100644 common/src/androidMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.android.kt create mode 100644 common/src/desktopMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.desktop.kt diff --git a/common/src/androidMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.android.kt b/common/src/androidMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.android.kt new file mode 100644 index 00000000..b13496e8 --- /dev/null +++ b/common/src/androidMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.android.kt @@ -0,0 +1,20 @@ +package com.artemchep.keyguard.ui.tooltip + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxScope +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +@Composable +actual fun Tooltip( + modifier: Modifier, + valueOrNull: T?, + tooltip: @Composable BoxScope.(T) -> Unit, + content: @Composable () -> Unit, +) { + Box( + modifier = modifier, + ) { + content() + } +} diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.kt index e1cc2200..adcf652a 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.kt @@ -1,60 +1,13 @@ package com.artemchep.keyguard.ui.tooltip -import androidx.compose.foundation.TooltipArea -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxScope -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.widthIn -import androidx.compose.material3.LocalContentColor -import androidx.compose.material3.LocalTextStyle -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.contentColorFor import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp -import com.artemchep.keyguard.ui.surface.LocalSurfaceColor -import com.artemchep.keyguard.ui.theme.Dimens -import com.artemchep.keyguard.ui.theme.verticalPaddingHalf @Composable -fun Tooltip( +expect fun Tooltip( modifier: Modifier = Modifier, valueOrNull: T?, tooltip: @Composable BoxScope.(T) -> Unit, content: @Composable () -> Unit, -) { - TooltipArea( - modifier = modifier, - tooltip = { - if (valueOrNull != null) { - val backgroundColor = MaterialTheme.colorScheme.surfaceVariant - val contentColor = contentColorFor(backgroundColor) - Box( - modifier = Modifier - .background( - color = backgroundColor, - shape = MaterialTheme.shapes.medium, - ) - .padding( - horizontal = Dimens.horizontalPadding, - vertical = Dimens.verticalPaddingHalf, - ) - .widthIn( - max = 320.dp, - ), - ) { - CompositionLocalProvider( - LocalSurfaceColor provides backgroundColor, - LocalContentColor provides contentColor, - LocalTextStyle provides MaterialTheme.typography.bodyMedium, - ) { - tooltip(valueOrNull) - } - } - } - }, - content = content, - ) -} +) diff --git a/common/src/desktopMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.desktop.kt b/common/src/desktopMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.desktop.kt new file mode 100644 index 00000000..5a1041e4 --- /dev/null +++ b/common/src/desktopMain/kotlin/com/artemchep/keyguard/ui/tooltip/Tooltip.desktop.kt @@ -0,0 +1,60 @@ +package com.artemchep.keyguard.ui.tooltip + +import androidx.compose.foundation.TooltipArea +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxScope +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.widthIn +import androidx.compose.material3.LocalContentColor +import androidx.compose.material3.LocalTextStyle +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.contentColorFor +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.artemchep.keyguard.ui.surface.LocalSurfaceColor +import com.artemchep.keyguard.ui.theme.Dimens +import com.artemchep.keyguard.ui.theme.verticalPaddingHalf + +@Composable +actual fun Tooltip( + modifier: Modifier, + valueOrNull: T?, + tooltip: @Composable BoxScope.(T) -> Unit, + content: @Composable () -> Unit, +) { + TooltipArea( + modifier = modifier, + tooltip = { + if (valueOrNull != null) { + val backgroundColor = MaterialTheme.colorScheme.surfaceVariant + val contentColor = contentColorFor(backgroundColor) + Box( + modifier = Modifier + .background( + color = backgroundColor, + shape = MaterialTheme.shapes.medium, + ) + .padding( + horizontal = Dimens.horizontalPadding, + vertical = Dimens.verticalPaddingHalf, + ) + .widthIn( + max = 320.dp, + ), + ) { + CompositionLocalProvider( + LocalSurfaceColor provides backgroundColor, + LocalContentColor provides contentColor, + LocalTextStyle provides MaterialTheme.typography.bodyMedium, + ) { + tooltip(valueOrNull) + } + } + } + }, + content = content, + ) +}