Created
August 5, 2021 11:16
-
-
Save bmc08gt/a14ac34c13907410bd51e090066d8d34 to your computer and use it in GitHub Desktop.
Lorem Ipsum paragraph generator in Jetpack Compose
This file contains hidden or 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 androidx.compose.material.LocalTextStyle | |
import androidx.compose.material.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.res.stringResource | |
import androidx.compose.ui.text.TextLayoutResult | |
import androidx.compose.ui.text.TextStyle | |
import androidx.compose.ui.text.font.FontFamily | |
import androidx.compose.ui.text.font.FontStyle | |
import androidx.compose.ui.text.font.FontWeight | |
import androidx.compose.ui.text.style.TextAlign | |
import androidx.compose.ui.text.style.TextDecoration | |
import androidx.compose.ui.text.style.TextOverflow | |
import androidx.compose.ui.unit.TextUnit | |
@Composable | |
fun LoremText( | |
modifier: Modifier = Modifier, | |
paragraphs: Int = 1, | |
color: Color = Color.Unspecified, | |
fontSize: TextUnit = TextUnit.Unspecified, | |
fontStyle: FontStyle? = null, | |
fontWeight: FontWeight? = null, | |
fontFamily: FontFamily? = null, | |
letterSpacing: TextUnit = TextUnit.Unspecified, | |
textDecoration: TextDecoration? = null, | |
textAlign: TextAlign? = null, | |
lineHeight: TextUnit = TextUnit.Unspecified, | |
overflow: TextOverflow = TextOverflow.Clip, | |
softWrap: Boolean = true, | |
maxLines: Int = Int.MAX_VALUE, | |
onTextLayout: (TextLayoutResult) -> Unit = {}, | |
style: TextStyle = LocalTextStyle.current | |
) { | |
val text = buildString { | |
for (i in 0 until paragraphs) { | |
append(stringResource(id = R.string.lorem)) | |
append("\n\n") | |
} | |
} | |
Text( | |
modifier = modifier, | |
text = text, | |
color = color, | |
fontSize = fontSize, | |
fontStyle = fontStyle, | |
fontWeight = fontWeight, | |
fontFamily = fontFamily, | |
letterSpacing = letterSpacing, | |
textDecoration = textDecoration, | |
textAlign = textAlign, | |
lineHeight = lineHeight, | |
overflow = overflow, | |
softWrap = softWrap, | |
maxLines = maxLines, | |
onTextLayout = onTextLayout, | |
style = style | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment