Skip to content

Instantly share code, notes, and snippets.

@pardom
Created April 15, 2020 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pardom/6e23b0c3f0e3c0debcdb213bf02a9093 to your computer and use it in GitHub Desktop.
Save pardom/6e23b0c3f0e3c0debcdb213bf02a9093 to your computer and use it in GitHub Desktop.
Compose PlaceholderText
@Composable
fun PlaceholderText(
text: String,
color: Color = Color.LightGray,
shape: Shape = RoundedCornerShape(2.dp),
modifier: Modifier = Modifier.None,
style: TextStyle = currentTextStyle(),
softWrap: Boolean = true,
overflow: TextOverflow = TextOverflow.Clip,
maxLines: Int = Int.MAX_VALUE,
onTextLayout: (TextLayoutResult) -> Unit = {}
) {
Text(
text,
modifier = modifier + Modifier.drawBackground(color = color, shape = shape),
style = style.copy(color = color),
softWrap = softWrap,
overflow = overflow,
maxLines = maxLines,
onTextLayout = onTextLayout
)
}
@Composable
fun PlaceholderText(
text: AnnotatedString,
color: Color = Color.LightGray,
shape: Shape = RoundedCornerShape(2.dp),
modifier: Modifier = Modifier.None,
style: TextStyle = currentTextStyle(),
softWrap: Boolean = true,
overflow: TextOverflow = TextOverflow.Clip,
maxLines: Int = Int.MAX_VALUE,
onTextLayout: (TextLayoutResult) -> Unit = {}
) {
Text(
text,
modifier = modifier + Modifier.drawBackground(color = color, shape = shape),
style = style.copy(color = color),
softWrap = softWrap,
overflow = overflow,
maxLines = maxLines,
onTextLayout = onTextLayout
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment