Created
January 17, 2024 12:40
-
-
Save chiragthummar/a48c2ecaf44e775a6660e833e19a4431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.ContentValues.TAG | |
import android.util.Log | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.material3.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Modifier | |
@Composable | |
fun Stack018() { | |
val textToDraw = | |
"Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups" | |
Text(text = textToDraw, | |
modifier = Modifier.fillMaxSize(), | |
onTextLayout = { textLayoutResult -> | |
val lineCount = textLayoutResult.lineCount | |
var lineOffset = 0 | |
for (i in 0 until lineCount ) { | |
val lineEndIndex = textLayoutResult.getLineEnd( | |
lineIndex = i, | |
visibleEnd = true | |
) | |
val lineContent = textToDraw | |
.substring(lineOffset,lineEndIndex) | |
Log.e(TAG,"=== Word Count $i= ${lineContent.split(" ").count()}") | |
lineOffset = lineEndIndex | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment