Skip to content

Instantly share code, notes, and snippets.

@zurche
Created July 27, 2023 13:11
Show Gist options
  • Save zurche/dfee403ce05e29687c95160a2265c103 to your computer and use it in GitHub Desktop.
Save zurche/dfee403ce05e29687c95160a2265c103 to your computer and use it in GitHub Desktop.
@Composable
fun MonthlyCapPreview(monthlyPreview: List<Pair<String, Float>>) {
val maxMonthValue = monthlyPreview.maxBy { it.second }.second //<-- We find the max Float value of our Pair List
Row(
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.Bottom //<--- This is important to align them as required by spec
) {
for (pairPreview in monthlyPreview) {
val columnHeightWeight = pairPreview.second / maxMonthValue //<-- We use it to get a value between 0 and 1
Card(
modifier = Modifier
.weight(1f)
.fillMaxHeight(columnHeightWeight) //<-- Pass it through the modifier to determine Its height
.padding(5.dp)
) {
Text(text = pairPreview.first)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment