Sliders
Slidersanimated

Rating drag

A star strip you drag across to set a half-step rating value.

3.5

Installation

caveui components are copy-paste Jetpack Compose built entirely on Material 3 — there's no caveui dependency to add. Make sure Material 3 is on your classpath (it ships with the Compose BOM), then copy the Usage snippet below into your project.

kotlin
// build.gradle.kts (module)
dependencies {
    implementation(platform("androidx.compose:compose-bom:2025.06.00"))
    implementation("androidx.compose.material3:material3")
}

Usage

kotlin
@Composable
fun RatingSlider() {
    var rating by remember { mutableStateOf(3.5f) }
    Column {
        Row(
            Modifier.pointerInput(Unit) {
                detectHorizontalDragGestures { change, _ ->
                    val r = (change.position.x / size.width * 5)
                        .coerceIn(0f, 5f)
                    rating = (r * 2).roundToInt() / 2f
                }
            },
        ) {
            repeat(5) { i ->
                val fill = (rating - i).coerceIn(0f, 1f)
                Icon(
                    if (fill >= 1f) Icons.Filled.Star
                    else if (fill > 0f) Icons.AutoMirrored.Filled.StarHalf
                    else Icons.Filled.StarBorder,
                    contentDescription = null,
                    tint = Color(0xFFF59E0B),
                    modifier = Modifier.size(32.dp),
                )
            }
        }
        Text("$rating", style = MaterialTheme.typography.labelMedium)
    }
}