JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.38k stars 1.18k forks source link

TextLayoutResult#isLineEllipsized always returns false #3074

Closed fornewid closed 2 months ago

fornewid commented 1 year ago

Describe the bug Currently I'm working on ReadMoreTextView library to support Compose Multiplatform. (https://github.com/webtoon/ReadMoreTextView/pull/60)

But I have an issue on Text composables. When TextLayoutResult is received through onTextLayout of CoreText, TextLayoutResult#isLineEllipsized always returns false.

Please let me know, if I should report this bug in the Jetpack Compose tracker.

Affected platforms Select one of the platforms below:

Versions

To Reproduce Steps and/or the code snippet to reproduce the behavior:

BasicText(
    text = currentText,
    modifier = Modifier,
    style = style,
    onTextLayout = { result ->
        result.isLineEllipsized(lineIndex = 3) // always returns false
    },
    overflow = TextOverflow.Ellipsis,
    maxLines = 3,
)

Expected behavior If currentText exceeds maxLines and currentText is ellipsized, result.isLineEllipsized() should return true.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

eymar commented 1 year ago

Reproduced:

@Composable
@Preview
fun App() {
    var currentText: String by remember { mutableStateOf("") }

    Column {
        BasicText(
            text = currentText,
            modifier = Modifier.width(100.dp),
            onTextLayout = { result ->
                val lastLine = result.lineCount - 1
                val isEllipsized = result.isLineEllipsized(lineIndex = lastLine) // always returns false
                println("isEllipsized($lastLine) = $isEllipsized")
            },
            overflow = TextOverflow.Ellipsis,
            maxLines = 3,
        )

        TextField(currentText, onValueChange = { currentText = it })
    }
}
Screenshot 2023-04-19 at 11 54 46
AntonButov commented 11 months ago

@fornewid

Please let me know, if I should report this bug in the

Hi, I found problem in:

androidx.compose.ui.text.SkiaParagraph.skiko.kt

override fun isLineEllipsized(lineIndex: Int) = false

This class responses for desktop realisation. Obviosly, the result, which you wait always returns false. You should report about the bug.

fornewid commented 11 months ago

@AntonButov Yes, that's right.

However, only the android library is published in Jetpack Compose. So I thought the SkiaParagraph.skiko.kt code should be modified in compose-multiplatform-core project.

Did I think wrong?

AntonButov commented 11 months ago

compose-multiplatform-core is fork of JetPack Compose. Yes, it's really strange why the desktop implementation placed in Android's Jatpack and called AndroidX. But I am sure that AndroidParagraph.android.kt::isLineEllipsized works when launching the Android application. Work good. The desktop application uses SkiaParagraph.skiko.kt::isLineEllipsized. Work bad. Both of these classes resolve interface. Perhaps androidx is not being renamed becouse not to break compatibility.

okushnikov commented 3 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.