devDebajo / staggered_lazy_column

Simple implementation of StaggeredLazyColumn with Jetpack Compose
Apache License 2.0
4 stars 0 forks source link

StaggeredLazyColumn

Simple implementation of StaggeredLazyColumn with Jetpack Compose

Used LazyLayout from Jetpack Compose 1.2.1

Screenshot

Install

In project level build.gradle add jitpack.io repository:

repositories {
    maven { url 'https://jitpack.io' }
}

Then add it to module level build.gradle:

implementation 'com.github.devDebajo:staggered_lazy_column:{latest_version}'

Usage

val state: State by viewModel.state.collectAsState() // State should be Stable or Immutable
StaggeredLazyColumn(
    modifier = Modifier.fillMaxSize(),
    columns = StaggeredLazyColumnCells.Adaptive(100.dp, maxColumns = 5),
    horizontalSpacing = 8.dp,
    verticalSpacing = 6.dp,
    contentPadding = PaddingValues(16.dp),
) {
    items(
        count = state.items.size,
        key = { state.items[it].id },
        contentType = { "my_type" },
    ) { index ->
        Text(state.items[index].name)
    }
}

For get more scrolling performance your state should be @Stable type\ More info about stable types and skipping recompositions when input haven't changed here

Roadmap

License

Copyright (C) 2022 debajo

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.