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(percent = 20)) },
            end =
                PolygonShape.star(
                    numPoints = 6,
                    innerRadiusRatio = 0.6f,
                    outerRounding = CornerRounding(percent = 20),
                ),
            progress = { progress },
        )
    }
    Box(
        Modifier.size(96.dp).clip(shape).background(Color(0xFF4CAF50)).clickable {
            selected = !selected
        }
    )
}

Content updated: