Layout

Layout is a flexible grid system component that allows you to organize content in a customizable grid format with configurable columns and spacing.

TypeResource
DesignFigma
MobileMobile Storybook
CodeGitlab

Layout Preview

Usage

import id.co.biofarma.binduiandroid.components.layout.Layout
Layout(
    id = "basic-grid",
    items = (1..4).toList(),
    columns = 2
) { item ->
    Box(
        modifier = Modifier
            .aspectRatio(1f)
            .background(PrimitiveColors.InnovationBlue_200),
        contentAlignment = Alignment.Center
    ) {
        Text(
            text = item.toString(),
            color = PrimitiveColors.White
        )
    }
}

Examples

Columns (optional)

Use columns to determine the number of columns in the grid (maximum 4).

Layout Example Columns

Spacing (optional)

Use horizontalSpacing and verticalSpacing to adjust the gap between grid items.

Layout Example Spacing

Props

PropsRequiredDefaultTypeDescription
idfalse""StringA unique identifier for the layout
itemstrue-List<T>List of items to be displayed in the grid
columnsfalse3IntNumber of columns in the grid (max 4)
horizontalSpacingfalse8IntHorizontal space between grid items (in dp)
verticalSpacingfalse8IntVertical space between grid items (in dp)
modifierfalseModifierModifierModifier for the grid container
itemContenttrue-@Composable (T) -> UnitComposable function for item display

Notes

  1. Implementation Details

    • Built using LazyVerticalGrid for efficient rendering and recycling of items
    • Automatically fills the maximum available size with fillMaxSize()
    • Includes a testTag with the provided ID for UI testing purposes
  2. Column Limitations

    • Maximum number of columns is capped at 4 using columns.coerceAtMost(4)
    • If you specify more than 4 columns, it will automatically be adjusted to 4
  3. Spacing

    • Spacing values are in density-independent pixels (dp)
    • Uses Arrangement.spacedBy() for consistent spacing between items
    • Horizontal and vertical spacing can be set independently
  4. Generic Type Support

    • The component is generic (<T>) and can work with any type of data
    • The itemContent lambda allows for custom rendering of each item
  5. Best Practices

    • Provide a meaningful ID when using the component for testing purposes
    • Consider screen size when choosing the number of columns
    • Use consistent spacing values throughout your application
    • Implement proper accessibility features in the itemContent
BIND © Biofarma Innovate Next-level Design .