This Compose book is reviewed by Googlers Check it out →

opticalCentering

Common

Modifier in Material 3 Compose

[Modifier] that centers the content depending on the shape provided. It will increase or decrease the start padding to better center the content depending on the corner radii of the provided shape. This is meant to be used with asymmetric shapes, the modifier will not do anything to the content if the shape provided is symmetric.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.material3:material3:1.4.0-alpha02")
}

Overloads

@ExperimentalMaterial3ExpressiveApi
fun Modifier.opticalCentering(shape: CornerBasedShape, basePadding: PaddingValues)

Parameters

namedescription
shapethe [CornerBasedShape] that the content should be adjusted to so that the content is more centered within the shape.
basePaddingthe initial content padding that would have been applied to the content before correcting for the corner radii of the shape.
by @alexstyl