Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created Jul 30, 2021
Embed
What would you like to do?
@Composable
fun Social() {
val dividerId = "inlineDividerId"
val text = buildAnnotatedString {
// LinkedIn
append(AnnotatedString("LinkedIn ", spanStyle = SpanStyle(Color.Blue)))
// Divider
appendInlineContent(dividerId, "[divider]")
// Twitter
append(AnnotatedString(" Twitter ", spanStyle = SpanStyle(Color.Blue)))
// Divider
appendInlineContent(dividerId, "[divider]")
// Portfolio
append(AnnotatedString(" Portfolio", spanStyle = SpanStyle(Color.Blue)))
}
val inlineDividerContent = mapOf(
Pair(
// This tells the [CoreText] to replace the placeholder string "[divider]" by
// the composable given in the [InlineTextContent] object.
dividerId,
InlineTextContent(
// Placeholder tells text layout the expected size and vertical alignment of
// children composable.
Placeholder(
width = 0.15.em,
height = 0.90.em,
placeholderVerticalAlign = PlaceholderVerticalAlign.TextCenter
)
) {
Box(
modifier = Modifier
.rotate(15f)
.fillMaxSize()
.clip(RectangleShape)
.background(Color.DarkGray)
)
}
)
)
BasicText(text = text, inlineContent = inlineDividerContent, style = TextStyle(fontSize = 17.sp))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment