Icons
Iconsanimated

Checkbox

A checkbox whose rounded box settles and the tick strokes in when toggled on.

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 AnimatedCheckbox(checked: Boolean, onChange: (Boolean) -> Unit) {
    val p by animateFloatAsState(if (checked) 1f else 0f, spring(stiffness = 400f), label = "chk")
    val color = MaterialTheme.colorScheme.primary
    Canvas(Modifier.size(34.dp).clickable { onChange(!checked) }) {
        drawRoundRect(color.copy(alpha = 0.2f + 0.8f * p), style = if (p < 1f) Stroke(2.5.dp.toPx()) else Fill,
            cornerRadius = CornerRadius(7f), size = size * 0.8f, topLeft = size.center / 5f)
        val tick = Path().apply { moveTo(size.width*0.32f, size.height*0.5f); lineTo(size.width*0.44f, size.height*0.62f); lineTo(size.width*0.66f, size.height*0.38f) }
        val m = PathMeasure().apply { setPath(tick, false) }
        drawPath(Path().also { m.getSegment(0f, m.length * p, it, true) }, MaterialTheme.colorScheme.onPrimary,
            style = Stroke(2.5.dp.toPx(), cap = StrokeCap.Round, join = StrokeJoin.Round))
    }
}