Skip to content

Instantly share code, notes, and snippets.

@m4kvn
Last active December 28, 2023 21:12
Show Gist options
  • Select an option

  • Save m4kvn/b3993e9f2a4539ed3c391a93956abfd1 to your computer and use it in GitHub Desktop.

Select an option

Save m4kvn/b3993e9f2a4539ed3c391a93956abfd1 to your computer and use it in GitHub Desktop.
@Composable
fun OutlinedText(
text: String,
modifier: Modifier = Modifier,
textStyle: TextStyle = TextStyle.Default,
stroke: Stroke = Stroke(),
strokeColor: Color = Color.Transparent,
) {
var textLayoutResult: TextLayoutResult? by remember {
mutableStateOf(null)
}
Text(
text = text,
style = textStyle,
onTextLayout = {
textLayoutResult = it
},
modifier = modifier
.drawBehind {
textLayoutResult?.let {
drawText(
textLayoutResult = it,
drawStyle = stroke,
color = strokeColor,
)
}
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment