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
}
)
}