I need to add UI that will let a user thumb over a star rating bar and set a rating. So far, I haven't found a single custom rating bar that does this. There are plenty of non-interactive ones, but I can't use those.
I can't believe this is missing from Jetpack Compose.
Here My RatingBar:
@Composable
fun RatingBar(
rating: Float,
maxRating: Int = 5,
onRatingChanged: (Float) -> Unit
) {
Row {
for (i in 1..maxRating) {
IconButton(onClick = { onRatingChanged(i.toFloat()) }) {
if (i <= rating) Icons.Default.Star else Icons.Default.StarBorder
}
}
}
}
When you call it:
var rating by remember { mutableStateOf(3.5f) }
RatingBar(
rating = rating,
onRatingChanged = { newRating ->
rating = newRating
},
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With