Skip to content

Commit

Permalink
Merge pull request #980 from Corvus400/enhancement/simplified_process…
Browse files Browse the repository at this point in the history
…_clickable_link_text

🔧 [ClickableLinkText] Processing has been simplified.
  • Loading branch information
takahirom committed Sep 7, 2024
2 parents f97f1ae + d0a729d commit f6b08f4
Showing 1 changed file with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -105,19 +102,7 @@ fun ClickableLinkText(
findUrlResults = findResults,
)

val layoutResult = remember { mutableStateOf<LayoutCoordinates?>(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)
Expand All @@ -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(
Expand Down

0 comments on commit f6b08f4

Please sign in to comment.