fix: Add empty Tooltip implementation for Android platform

This commit is contained in:
Artem Chepurnyi 2024-12-29 11:58:28 +02:00
parent bb979cb52d
commit 4d6a9a7ec8
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
3 changed files with 82 additions and 49 deletions

View File

@ -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 <T : Any> Tooltip(
modifier: Modifier,
valueOrNull: T?,
tooltip: @Composable BoxScope.(T) -> Unit,
content: @Composable () -> Unit,
) {
Box(
modifier = modifier,
) {
content()
}
}

View File

@ -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 <T : Any> Tooltip(
expect fun <T : Any> 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,
)
}
)

View File

@ -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 <T : Any> 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,
)
}