SUBSCRIBE NOW![avatar]()
I always learn something just by skimming it that makes me want to bookmark the issue now and dig deeper later

SUBSCRIBE NOW![avatar]()
Keep up the good work with the newsletter 💪 I really enjoy it

SUBSCRIBE NOW![avatar]()
Dispatch is a must read for Android devs today and my go-to for keeping up with all things Jetpack Compose

SUBSCRIBE NOW![avatar]()
Dispatch has been my go-to resource as it's packed with useful information while being fun at the same time

SUBSCRIBE NOW![avatar]()
The content is light, fun, and still useful. I especially appreciate the small tips that are in each issue

SUBSCRIBE NOW![avatar]()
I truly love this newsletter ❤️🔥 Spot on content and I know there's a lot of effort that goes behind it

SUBSCRIBE NOW![avatar]()
Thanks for taking the time and energy to do it so well

JetpackCompose.app's Newsletter![avatar]()
I always learn something just by skimming it that makes me want to bookmark the issue now and dig deeper later

JetpackCompose.app's Newsletter![avatar]()
Keep up the good work with the newsletter 💪 I really enjoy it

JetpackCompose.app's Newsletter![avatar]()
Dispatch is a must read for Android devs today and my go-to for keeping up with all things Jetpack Compose

JetpackCompose.app's Newsletter![avatar]()
Dispatch has been my go-to resource as it's packed with useful information while being fun at the same time

JetpackCompose.app's Newsletter![avatar]()
The content is light, fun, and still useful. I especially appreciate the small tips that are in each issue

JetpackCompose.app's Newsletter![avatar]()
I truly love this newsletter ❤️🔥 Spot on content and I know there's a lot of effort that goes behind it

JetpackCompose.app's Newsletter![avatar]()
Thanks for taking the time and energy to do it so well

Rating Bar
Author: Angelo Rüggeber
A simple star rating bar component implemented using Compose. I made some modifications to suit my need before I tested it on my device.
import androidx.compose.foundation.layout.Row | |
import androidx.compose.material.Icon | |
import androidx.compose.material.icons.Icons | |
import androidx.compose.material.icons.outlined.Star | |
import androidx.compose.material.icons.outlined.StarHalf | |
import androidx.compose.material.icons.outlined.StarOutline | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.tooling.preview.Preview | |
import kotlin.math.ceil | |
import kotlin.math.floor | |
@Composable | |
fun RatingBar( | |
modifier: Modifier = Modifier, | |
rating: Double = 0.0, | |
stars: Int = 5, | |
starsColor: Color = Color.Yellow, | |
) { | |
val filledStars = floor(rating).toInt() | |
val unfilledStars = (stars - ceil(rating)).toInt() | |
val halfStar = !(rating.rem(1).equals(0.0)) | |
Row(modifier = modifier) { | |
repeat(filledStars) { | |
Icon(imageVector = Icons.Outlined.Star, contentDescription = null, tint = starsColor) | |
} | |
if (halfStar) { | |
Icon( | |
imageVector = Icons.Outlined.StarHalf, | |
contentDescription = null, | |
tint = starsColor | |
) | |
} | |
repeat(unfilledStars) { | |
Icon( | |
imageVector = Icons.Outlined.StarOutline, | |
contentDescription = null, | |
tint = starsColor | |
) | |
} | |
} | |
} | |
@Preview | |
@Composable | |
fun RatingPreview() { | |
RatingBar(rating = 2.5) | |
} | |
@Preview | |
@Composable | |
fun TenStarsRatingPreview() { | |
RatingBar(stars = 10, rating = 8.5) | |
} | |
@Preview | |
@Composable | |
fun RatingPreviewFull() { | |
RatingBar(rating = 5.0) | |
} | |
@Preview | |
@Composable | |
fun RatingPreviewWorst() { | |
RatingBar(rating = 1.0) | |
} | |
@Preview | |
@Composable | |
fun RatingPreviewDisabled() { | |
RatingBar(rating = 0.0, starsColor = Color.Gray) | |
} |
Have a project you'd like to submit? Fill this form, will ya!
If you like this snippet, you might also like:
Maker OS is an all-in-one productivity system for developers
I built Maker OS to track, manage & organize my life. Now you can do it too!