Here is how I handled the issue, so maybe works for you case also;
First of all, define necessary variables;
val lazyStackState = rememberLazyListState()
val lazyStackScope = rememberCoroutineScope()
val positionInLayout = SnapPositionInLayout { layoutSize, itemSize, itemIndex ->
// This value tells where to snap on the x axis within the viewport
// Setting it to 0 results in snapping of the first visible item to the left side (or right side if RTL)
0
}
val snappingLayout = remember(lazyStackState) { SnapLayoutInfoProvider(lazyStackState, positionInLayout) }
val snapBehavior = rememberSnapFlingBehavior(snappingLayout)
After that, create a LaunchedEffect to trigger your action in case users swipe up. The thing here is prevent more than one swipes at a time by using scrollToItem(1) logic.
Also, if you are using a shimmer item at the end and load new data when you reach the shimmer item, you may need to use scrollToItem(0) at the end to make it work also when new data arrives.
LaunchedEffect(isSwipedUp) {
if (isSwipedUp) {
lazyStackScope.launch {
if (listData.size > 1) {
lazyStackState.scrollToItem(1)
}
// Your extra logic if you need
if (listData.isEmpty()) {
lazyStackState.scrollToItem(0)
}
}
}
}
Finally, assign isSwipedUp.not() results in userScrollEnabled parameter for LazyColumn
LazyColumn(
modifier = Modifier
.heightIn(1500.dp)
.background(White),
userScrollEnabled = isSwipedUp.not(),
state = lazyStackState,
flingBehavior = snapBehavior,
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp)
) {
items(
items = listData,
key = { currentData -> currentData.id!! },
itemContent = { data ->
val isActiveItem = listData.firstOrNull()?.id == data.id
// Use your content here
}
)
}
Hope it helps