Disclosures
Disclosuresanimated

Read more

A clamped paragraph that expands past a fade with a read more toggle.

The trail climbs through old-growth cedar before opening onto a ridge with views across the whole valley, switchbacks easing the final push to the summit cairn.

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 ReadMore(text: String, minimizedLines: Int = 3) {
    var expanded by remember { mutableStateOf(false) }
    Column {
        Box {
            Text(
                text,
                maxLines = if (expanded) Int.MAX_VALUE else minimizedLines,
                overflow = TextOverflow.Ellipsis,
                style = MaterialTheme.typography.bodyMedium,
                modifier = Modifier.animateContentSize(),
            )
            if (!expanded) {
                Box(
                    Modifier
                        .align(Alignment.BottomCenter)
                        .fillMaxWidth()
                        .height(24.dp)
                        .background(
                            Brush.verticalGradient(
                                listOf(Color.Transparent,
                                    MaterialTheme.colorScheme.surface),
                            ),
                        ),
                )
            }
        }
        TextButton(onClick = { expanded = !expanded }) {
            Text(if (expanded) "Read less" else "Read more")
        }
    }
}