Created
July 4, 2023 05:26
-
-
Save jsonkile/955456383ddda5e46d26f8445969fe45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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