Created
December 12, 2022 17:11
-
-
Save ykws/02ce930081ffd869c7650d283eb8c385 to your computer and use it in GitHub Desktop.
Jetpack Compose Text mixed a suffix and an ellipsis
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
@Composable | |
fun MixedSuffixAndEllipsisText( | |
text: String, | |
suffix: String, | |
) { | |
Row(modifier = Modifier.padding(all = 10.dp) | |
) { | |
Text( | |
text = text, | |
maxLines = 1, | |
overflow = TextOverflow.Ellipsis, | |
modifier = Modifier.weight(1f, false), | |
) | |
Text( | |
text = suffix, | |
maxLines = 1, | |
) | |
} | |
} | |
@Preview(showBackground = true, backgroundColor = 0xffffffff, widthDp = 240) | |
@Composable | |
private fun ShortTextPreview() { | |
MixedSuffixAndEllipsisText( | |
text = "0123456789".repeat(1), | |
suffix = "suffix", | |
) | |
} | |
@Preview(showBackground = true, backgroundColor = 0xffffffff, widthDp = 240) | |
@Composable | |
private fun LongTextPreview() { | |
MixedSuffixAndEllipsisText( | |
text = "0123456789".repeat(3), | |
suffix = "suffix", | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Previews