Skip to content

Instantly share code, notes, and snippets.

@jsonkile
Created July 4, 2023 05:26
Show Gist options
  • Save jsonkile/955456383ddda5e46d26f8445969fe45 to your computer and use it in GitHub Desktop.
Save jsonkile/955456383ddda5e46d26f8445969fe45 to your computer and use it in GitHub Desktop.
@Composable
fun DashedProgressIndicator(
modifier: Modifier = Modifier,
progress: Int = 3,
totalNumberOfBars: Int = 12
) {
Canvas(modifier = modifier) {
val barArea = size.width / totalNumberOfBars
val barLength = barArea - 10.dp.toPx()
var nextBarStartPosition = 0F
for (i in 0..totalNumberOfBars) {
val barStartPosition = nextBarStartPosition + 5.dp.toPx()
val barEndPosition = barStartPosition + barLength
val start = Offset(x = barStartPosition, y = size.height / 2)
val end = Offset(x = barEndPosition, y = size.height / 2)
drawLine(
cap = StrokeCap.Round,
color = if (i < progress) Color.LightGray else Color.LightGray.copy(alpha = .5F),
start = start,
end = end,
strokeWidth = 13F
)
nextBarStartPosition = barEndPosition + 5.dp.toPx()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment