Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Created March 17, 2024 04:19
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 KatieBarnett/94f3e6ec3412590770419504dbfbcfe6 to your computer and use it in GitHub Desktop.
Save KatieBarnett/94f3e6ec3412590770419504dbfbcfe6 to your computer and use it in GitHub Desktop.
Dotted lines
@Composable
fun DottedLine(color: Color, modifier: Modifier = Modifier) {
val dotRadius = LINE_WIDTH / 2
val dotSpacing = dotRadius * 2
Canvas(modifier) {
val circle = Path()
circle.addOval(Rect(center = Offset.Zero, radius = dotRadius.toPx()))
val pathEffect = PathEffect.stampedPathEffect(
shape = circle,
advance = dotSpacing.toPx(),
phase = 0f,
style = StampedPathEffectStyle.Translate
)
drawLine(
color = color,
start = Offset(0f, 0f),
end = Offset(size.width, 0f),
pathEffect = pathEffect,
cap = StrokeCap.Round,
strokeWidth = dotRadius.toPx()
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment