Cards
Cardsanimated

Heart Rate Pulse

Live ECG-style pulse line scrolls beneath a beating heart and BPM value.

72 BPM

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 HeartPulseCard() {
  val t = rememberInfiniteTransition(label = "ecg")
  val phase by t.animateFloat(
    0f, 1f,
    infiniteRepeatable(tween(1800, easing = LinearEasing)),
    label = "phase"
  )
  val beat by t.animateFloat(
    1f, 1.25f,
    infiniteRepeatable(
      tween(500), repeatMode = RepeatMode.Reverse
    ), label = "beat"
  )
  ElevatedCard(Modifier.fillMaxWidth()) {
    Column(Modifier.padding(20.dp)) {
      Row(verticalAlignment = Alignment.CenterVertically) {
        Box(Modifier.graphicsLayer {
          scaleX = beat; scaleY = beat
        }) {
          Canvas(Modifier.size(22.dp)) {
            drawCircle(Color(0xFFFF3B30))
          }
        }
        Spacer(Modifier.width(10.dp))
        Text(
          "72 BPM",
          style = MaterialTheme.typography.headlineSmall
        )
      }
      Spacer(Modifier.height(14.dp))
      Canvas(Modifier.fillMaxWidth().height(60.dp)) {
        val w = size.width; val h = size.height
        val path = Path()
        val n = 60
        for (i in 0..n) {
          val x = w * i / n
          val p = (i / n.toFloat() + phase) * 6f
          val spike =
            if ((p % 1f) in 0.45f..0.55f) -h * 0.4f
            else 0f
          val y = h / 2 + spike +
            sin(p * 3.14f) * h * 0.05f
          if (i == 0) path.moveTo(x, y)
          else path.lineTo(x, y)
        }
        drawPath(
          path, Color(0xFFFF3B30),
          style = Stroke(3f, cap = StrokeCap.Round)
        )
      }
    }
  }
}