Tristan
02/20/2021, 10:47 PMRating(4.3F, 5)
Is there anything wrong with what I have done? Will I have performances issue? 😮 Thanks for your help.
@Composable
fun Rating(score: Float, maxScore: Int, modifier: Modifier = Modifier, tint: Color = Color.Yellow) {
val shape = remember(score) {
val rate = score - score.toInt()
GenericShape { size ->
lineTo(size.width * rate, 0f)
lineTo(size.width * rate, size.height)
lineTo(0f, size.height)
}
}
val icon = vectorResource(id = R.drawable.ic_star)
Row(modifier = modifier) {
for (i in 0 until maxScore) {
if (i + 1 < score) {
Icon(
imageVector = icon,
tint = tint,
)
} else if (i < score) {
Box {
Icon(
imageVector = icon,
)
Icon(
imageVector = icon,
tint = tint,
modifier = Modifier.clip(shape),
)
}
} else {
Icon(
imageVector = icon,
)
}
}
}
}