commonMain.io.github.ahmad_hamwi.compose.pagination.PaginatedLazyVerticalGrid.kt Maven / Gradle / Ivy
package io.github.ahmad_hamwi.compose.pagination
import androidx.compose.foundation.gestures.FlingBehavior
import androidx.compose.foundation.gestures.ScrollableDefaults
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
@Composable
fun PaginatedLazyVerticalGrid(
paginationState: PaginationState,
columns: GridCells,
modifier: Modifier = Modifier,
firstPageProgressIndicator: @Composable () -> Unit = {},
newPageProgressIndicator: @Composable () -> Unit = {},
firstPageErrorIndicator: @Composable (e: Exception) -> Unit = {},
newPageErrorIndicator: @Composable (e: Exception) -> Unit = {},
state: LazyGridState = rememberLazyGridState(),
contentPadding: PaddingValues = PaddingValues(0.dp),
reverseLayout: Boolean = false,
verticalArrangement: Arrangement.Vertical =
if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
userScrollEnabled: Boolean = true,
content: LazyGridScope.() -> Unit
) {
PaginatedLazyScrollable(
paginationState,
modifier,
firstPageProgressIndicator,
newPageProgressIndicator,
firstPageErrorIndicator,
newPageErrorIndicator,
state,
) { paginatedItemsHandler ->
LazyVerticalGrid(
columns,
modifier,
state,
contentPadding,
reverseLayout,
verticalArrangement,
horizontalArrangement,
flingBehavior,
userScrollEnabled,
) {
paginatedItemsHandler {
content()
}
}
}
}