Function

MorphPolygonShape

Creates a Shape that morphs between start and end as progress moves from 0f to 1f.

MorphPolygonShapeSample

@Sampled
@Composable
fun MorphPolygonShapeSample() {
    // A badge that morphs between a rounded hexagon and a star as it is toggled. No remember
    // keys are needed: the endpoints are constant and the current progress is read through the
    // lambda each time the outline is resolved.
    var selected by remember { mutableStateOf(false) }
    val progress by animateFloatAsState(if (selected) 1f else 0f)
    val shape = remember {
        MorphPolygonShape(
            start =
                PolygonShape {
                    polygon(numVertices = 6, rounding = CornerRounding.fraction(0.2f))
                },
            end =
                PolygonShape.star(
                    numPoints = 6,
                    innerRadiusRatio = 0.6f,
                    outerRounding = CornerRounding.fraction(0.2f),
                ),
            progress = { progress },
        )
    }
    Box(
        Modifier.size(96.dp).clip(shape).background(Color(0xFF4CAF50)).clickable {
            selected = !selected
        }
    )
}
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: