/gridlayout-compose

Missing non lazy grid layout for Compose Multiplatform.

Primary LanguageKotlinApache License 2.0Apache-2.0

GridLayout for Compose

ci-latest-status maven-central Static Badge

GridLayout for Compose is a library that provides missing non lazy grid layout composables for Compose Multiplatform.

grid-examples

Jetpack Compose doesn't offer non lazy grid layout, there are only lazy grid layout and alternatives (for example, flow layout). But sometimes, we need to use grid layout for less complexity and more intuitive layout code. This library can be simpler solution for small grid UI.

There are benefits of this library:

  • Similar API to LazyGrid: The GridLayout's APIs are designed to provide similar development experience to LazyGrid.
  • Easy to implement adaptive grid: There are "Fixed" and "Adaptive" for grid layout management like LazyGrid. Like LazyGrid, it eliminates dealing with different screen sizes.
  • Simple to use as a part of LazyList: The GridLayout is not lazy layout. It can be simply placed in lazy layouts. If only a portion of the full layout is grid, No need to use LazyGrid with span size for full layout.
  • Efficient for small datasets: LazyGrid has complex logics for large datasets. But when datasets are small, it can be inefficient. The GridLayout is just a simple layout. It can be more efficient for smaller datasets.

Installation

To download this library, add dependency to your gradle:

dependencies {
    implementation("com.cheonjaeung.compose.grid:grid:<version>")
}

After the 2.0.0 version, the group id and package name is changed from io.woong.compose.grid to com.cheonjaeung.compose.grid.

Usage

usage-example

VerticalGrid(
    columns = SimpleGridCells.Fixed(3),
    modifier = Modifier.fillMaxWidth(),
) {
    for ((index, color) in colors.withIndex()) {
        ColorBox(
            modifier = Modifier,
            color = color,
            text = (index + 1).toString(),
        )
    }
}

For more information, please visit documentation site.

Changelog

Please see changelog file.

License

GridLayout for Compose is licensed under Apache License 2.0. See license file for more details.