Skip to content

Commit

Permalink
fix: Ensure selected news source is visible among the initial visible…
Browse files Browse the repository at this point in the history
… sources in the viewport (#66)
  • Loading branch information
rob729 authored Jan 22, 2024
1 parent f603bc9 commit 2db38d7
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
Expand All @@ -29,6 +31,11 @@ fun NewsSourceBottomSheetContent(
val newsSourceList = Constants.newsSourceUiDataLists
val screenWidthDp = LocalConfiguration.current.screenWidthDp
val itemWidth = (screenWidthDp - (ITEM_SPACING * VISIBLE_CARDS)).div(VISIBLE_CARDS)
val rowState = rememberLazyListState()

LaunchedEffect(currentSelectedNewsSource, newsSourceList) {
rowState.scrollToItem(newsSourceList.indexOfFirst { it.domain == currentSelectedNewsSource })
}

Box(
modifier = Modifier.navigationBarsPadding(),
Expand All @@ -38,7 +45,8 @@ fun NewsSourceBottomSheetContent(
LazyRow(
modifier = Modifier
.testTag("news_source_list"),
horizontalArrangement = Arrangement.spacedBy(ITEM_SPACING.dp)
horizontalArrangement = Arrangement.spacedBy(ITEM_SPACING.dp),
state = rowState
) {
items(Constants.newsSourceUiDataLists.size,
{ index: Int -> newsSourceList[index].domain }) { index ->
Expand Down

0 comments on commit 2db38d7

Please sign in to comment.