Skip to content

Instantly share code, notes, and snippets.

@ykws
Created December 12, 2022 17:11
Show Gist options
  • Save ykws/02ce930081ffd869c7650d283eb8c385 to your computer and use it in GitHub Desktop.
Save ykws/02ce930081ffd869c7650d283eb8c385 to your computer and use it in GitHub Desktop.
Jetpack Compose Text mixed a suffix and an ellipsis
@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",
)
}
@ykws
Copy link
Author

ykws commented Dec 12, 2022

Previews

スクリーンショット 2022-12-13 2 12 45

@ykws
Copy link
Author

ykws commented Dec 13, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment