diff --git a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/component/ClickableLinkText.kt b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/component/ClickableLinkText.kt index ce77ffc82..739a6664b 100644 --- a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/component/ClickableLinkText.kt +++ b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/component/ClickableLinkText.kt @@ -7,14 +7,11 @@ import androidx.compose.foundation.text.ClickableText import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.layout.LayoutCoordinates -import androidx.compose.ui.layout.onGloballyPositioned -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.TextStyle @@ -105,19 +102,7 @@ fun ClickableLinkText( findUrlResults = findResults, ) - val layoutResult = remember { mutableStateOf(null) } - - val density = LocalDensity.current - - val isOverflowing by remember { - derivedStateOf { - val actualHeight = layoutResult.value?.size?.height?.toFloat() ?: 0f - val expectedHeight = with(density) { - style.fontSize.toPx() + style.lineHeight.toPx() * (maxLines - 1) - } - actualHeight > expectedHeight - } - } + var isOverflowing by remember { mutableStateOf(false) } LaunchedEffect(isOverflowing) { onOverflow(isOverflowing) @@ -127,14 +112,14 @@ fun ClickableLinkText( modifier = modifier .animateContentSize( animationSpec = tween(ClickableTextExpandAnimateDurationMillis, easing = EaseInQuart), - ) - .onGloballyPositioned { coordinates -> - layoutResult.value = coordinates - }, + ), text = annotatedString, style = style, overflow = overflow, maxLines = maxLines, + onTextLayout = { textLayoutResult -> + isOverflowing = textLayoutResult.hasVisualOverflow + }, onClick = { offset -> findResults.forEach { matchResult -> annotatedString.getStringAnnotations(