Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Last active March 17, 2024 04:09
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/6091ee21283b58d736d958b5ab830c38 to your computer and use it in GitHub Desktop.
Save KatieBarnett/6091ee21283b58d736d958b5ab830c38 to your computer and use it in GitHub Desktop.
Multi Dashed Line
@Composable
fun MultiDashedLine(color: Color, modifier: Modifier = Modifier) {
val density = LocalDensity.current
with(density) {
val dashOnInterval1 = (LINE_WIDTH * 4).toPx()
val dashOffInterval1 = (LINE_WIDTH * 2).toPx()
val dashOnInterval2 = (LINE_WIDTH / 4).toPx()
val dashOffInterval2 = (LINE_WIDTH * 2).toPx()
val pathEffect =
PathEffect.dashPathEffect(
intervals = floatArrayOf(dashOnInterval1, dashOffInterval1, dashOnInterval2, dashOffInterval2),
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