Function

toPolygonShape

Converts a RoundedCornerShape to a PolygonShape.

RoundedCornerShapeToPolygonShapeSample

@Sampled
@Composable
fun RoundedCornerShapeToPolygonShapeSample() {
    // Converting a corner-based shape to a PolygonShape lets it morph with any other polygon
    // shape; here a rounded rectangle relaxes into a circle.
    var expanded by remember { mutableStateOf(false) }
    val progress by animateFloatAsState(if (expanded) 1f else 0f)
    val shape = remember {
        MorphPolygonShape(
            start = RoundedCornerShape(12.dp).toPolygonShape(),
            end = PolygonShape.circle(),
            progress = { progress },
        )
    }
    Box(
        Modifier.size(96.dp).clip(shape).background(Color(0xFF03A9F4)).clickable {
            expanded = !expanded
        }
    )
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: