Skip to content

Commit

Permalink
Set the outside risk region to alpha 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Agarwal committed Jan 16, 2025
1 parent a10267b commit 0a1755c
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ fun RiskProgressBar(

val indicatorColor = Color(0xFF2F363D)

Box(
BoxWithConstraints(
modifier = Modifier
.fillMaxWidth()
.height(14.dp)
Expand All @@ -191,18 +191,40 @@ fun RiskProgressBar(
},
contentAlignment = Alignment.Center,
) {
val totalSegments = riskColors.size
val segmentWidthPx = constraints.maxWidth.toFloat() / totalSegments

Row(
modifier = Modifier
.fillMaxWidth()
.height(4.dp)
.clip(RoundedCornerShape(50))
) {
riskColors.forEach { color ->
riskColors.forEachIndexed { index, color ->
val segmentStartPx = index * segmentWidthPx
val segmentEndPx = (index + 1) * segmentWidthPx

Box(
modifier = Modifier
.weight(1f)
.fillMaxHeight()
.background(color),
.drawWithContent {
drawRect(color.copy(alpha = 0.5f))

val visibleStart = maxOf(segmentStartPx, startOffset)
val visibleEnd = minOf(segmentEndPx, endOffset)

if (visibleStart < visibleEnd) {
drawRect(
color = color.copy(alpha = 1.0f),
topLeft = Offset(x = visibleStart - segmentStartPx, y = 0f),
size = Size(
width = visibleEnd - visibleStart,
height = size.height
)
)
}
}
)
}
}
Expand Down

0 comments on commit 0a1755c

Please sign in to comment.