Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Created March 17, 2024 03:47
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/8285b6ad71f320e7635dd13961c2519e to your computer and use it in GitHub Desktop.
Save KatieBarnett/8285b6ad71f320e7635dd13961c2519e to your computer and use it in GitHub Desktop.
Dashed line
@Composable
fun DashedLine(color: Color, modifier: Modifier = Modifier) {
val density = LocalDensity.current
with(density) {
val dashOnInterval = (LINE_WIDTH * 4).toPx()
val dashOffInterval = (LINE_WIDTH * 4).toPx()
val pathEffect = PathEffect.dashPathEffect(
intervals = floatArrayOf(dashOnInterval, dashOffInterval),
phase = 0f
)
Canvas(modifier) {
drawLine(
color = color,
start = Offset(0f, 0f),
end = Offset(size.width, 0f),
strokeWidth = LINE_WIDTH.toPx(),
cap = StrokeCap.Round,
pathEffect = pathEffect,
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment