Workaround rating icon
This commit is contained in:
1 parent
27cf341fef
commit
a4328c5111
1 file changed
+40
-2
@@ -8,6 +8,7 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.StarHalf
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.filled.StarOutline
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
@@ -20,7 +21,7 @@ import kotlin.math.roundToInt
|
||||
private val colorYellow800 = Color(0xfff9a825)
|
||||
|
||||
@Composable
|
||||
fun MetaRatingWidget(rating: Float, ratingSize: Dp, ratingInterval: Dp, modifier: Modifier = Modifier) {
|
||||
fun MetaRatingWidgetReuse(rating: Float, ratingSize: Dp, ratingInterval: Dp, modifier: Modifier = Modifier) {
|
||||
val r = (rating * 2).roundToInt().coerceIn(0, 10)
|
||||
val fullStar = r / 2
|
||||
val halfStar = r % 2
|
||||
@@ -56,9 +57,46 @@ fun MetaRatingWidget(rating: Float, ratingSize: Dp, ratingInterval: Dp, modifier
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MetaRatingWidget(rating: Float, ratingSize: Dp, ratingInterval: Dp, modifier: Modifier = Modifier) {
|
||||
val r = (rating * 2).roundToInt().coerceIn(0, 10)
|
||||
val fullStar = r / 2
|
||||
val halfStar = r % 2
|
||||
val outlineStar = 5 - fullStar - halfStar
|
||||
Row(modifier = modifier) {
|
||||
repeat(fullStar) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Star,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(ratingSize),
|
||||
tint = colorYellow800,
|
||||
)
|
||||
Spacer(modifier = Modifier.width(ratingInterval))
|
||||
}
|
||||
repeat(halfStar) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Default.StarHalf,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(ratingSize),
|
||||
tint = colorYellow800,
|
||||
)
|
||||
Spacer(modifier = Modifier.width(ratingInterval))
|
||||
}
|
||||
repeat(outlineStar) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.StarOutline,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(ratingSize),
|
||||
tint = colorYellow800,
|
||||
)
|
||||
Spacer(modifier = Modifier.width(ratingInterval))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun GalleryListCardRating(rating: Float, modifier: Modifier = Modifier) {
|
||||
MetaRatingWidget(
|
||||
MetaRatingWidgetReuse(
|
||||
rating = rating,
|
||||
ratingSize = dimensionResource(id = R.dimen.rating_size),
|
||||
ratingInterval = dimensionResource(id = R.dimen.rating_interval),
|
||||
|
||||
Reference in new issue
Block a user