refactor: Add lazy list state to sections for automatic scrolling to top

This commit is contained in:
2026-04-22 18:31:57 +02:00
parent 7f83bb181b
commit 3ae1425eba
3 changed files with 30 additions and 3 deletions

View File

@@ -6,7 +6,9 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import hu.bbara.purefin.core.ui.model.MediaUiModel
@@ -20,6 +22,12 @@ fun ContinueWatchingSection(
) {
if (items.isEmpty()) return
val listState = rememberLazyListState()
LaunchedEffect(items) {
listState.scrollToItem(index = 0)
}
Column(
verticalArrangement = Arrangement.spacedBy(4.dp),
modifier = modifier
@@ -28,7 +36,8 @@ fun ContinueWatchingSection(
LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
state = listState
) {
items(items = items, key = { item -> item.id }) { item ->
ContinueWatchingCard(

View File

@@ -6,7 +6,9 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import hu.bbara.purefin.core.ui.model.MediaUiModel
@@ -23,6 +25,12 @@ fun LibraryPosterSection(
) {
if (items.isEmpty()) return
val listState = rememberLazyListState()
LaunchedEffect(items) {
listState.scrollToItem(index = 0)
}
Column(
verticalArrangement = Arrangement.spacedBy(4.dp),
modifier = modifier
@@ -35,7 +43,8 @@ fun LibraryPosterSection(
LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(14.dp),
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
state = listState
) {
items(items = items, key = { item -> item.id }) { item ->
HomeBrowseCard(

View File

@@ -6,7 +6,9 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import hu.bbara.purefin.core.ui.model.MediaUiModel
@@ -20,6 +22,12 @@ fun NextUpSection(
) {
if (items.isEmpty()) return
val listState = rememberLazyListState()
LaunchedEffect(items) {
listState.scrollToItem(index = 0)
}
Column(
verticalArrangement = Arrangement.spacedBy(4.dp),
modifier = modifier
@@ -28,7 +36,8 @@ fun NextUpSection(
LazyRow(
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(14.dp),
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
state = listState
) {
items(items = items, key = { item -> item.id }) { item ->
NextUpCard(