Function

FlexConfig

Combine two FlexConfig objects together.

FlexConfigCombineSample

@Sampled
@Composable
fun FlexConfigCombineSample() {
    // Shared design system item style tokens
    val SharedItemDefaults = FlexConfig {
        shrink(1f)
        basis(FlexBasis.Auto)
    }

    // Individual special-case item overrides
    val GrowPriority = FlexConfig { grow(2f) }
    val CenterAlignmentOverride = FlexConfig { alignSelf(FlexAlignSelf.Center) }

    // Construct optimized configurations via combination APIs
    val FlexibleHeroItem = SharedItemDefaults then GrowPriority then CenterAlignmentOverride
    val StandardFlexibleItem = FlexConfig(SharedItemDefaults, GrowPriority)

    // An empty call returns the identity element cleanly
    val EmptyFlexExtension = FlexConfig()

    FlexBox(modifier = Modifier.fillMaxWidth().height(120.dp)) {
        // Applies premium combined config with extensions
        Box(
            Modifier.height(60.dp)
                .background(Color.Cyan)
                .flex(FlexibleHeroItem then EmptyFlexExtension)
        )
        Box(Modifier.height(60.dp).background(Color.Yellow).flex(StandardFlexibleItem))
    }
}
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: