Interface

PolygonShapeTransformScope

Transforms a PolygonShape's geometry inside PolygonShape.transform.

TransformedPolygonShapeSample

@Sampled
@Composable
fun TransformedPolygonShapeSample() {
    // A square polygon rotated 45 degrees around its center and scaled into the layout bounds in a
    // single pass so the rotated diamond stays inscribed without clipping.
    val diamond = remember {
        PolygonShape { polygon(numVertices = 4, rounding = CornerRounding.fraction(0.15f)) }
            .apply {
                transform {
                    rotate(degrees = 45f)
                    scaleToFit(contentScale = ContentScale.Fit)
                }
            }
    }
    Box(Modifier.size(96.dp).clip(diamond).background(Color(0xFFE91E63)))
}

RuntimeTransformedPolygonShapeSample

@Sampled
@Composable
fun RuntimeTransformedPolygonShapeSample() {
    // Creates an unrotated badge shape and an independent rotated copy using copy() + transform {}.
    val badge = remember {
        PolygonShape.star(
            numPoints = 8,
            innerRadiusRatio = 0.75f,
            outerRounding = CornerRounding.fraction(0.4f),
        )
    }
    val selectedBadge =
        remember(badge) { badge.copy().apply { transform { rotate(degrees = 22.5f) } } }
    var selected by remember { mutableStateOf(false) }
    val shape = if (selected) selectedBadge else badge
    Box(
        Modifier.size(96.dp).clip(shape).background(Color(0xFF00695C)).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: