Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Update usage of Pages.
Browse files Browse the repository at this point in the history
Change-Id: I5a9421041d497c83a12585ab429f847e441e4c92
  • Loading branch information
arriolac committed Dec 20, 2023
1 parent 0a325c3 commit 76fe346
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ enum class SunflowerPage(
fun HomeScreen(
modifier: Modifier = Modifier,
onPlantClick: (Plant) -> Unit = {},
viewModel: PlantListViewModel = hiltViewModel()
viewModel: PlantListViewModel = hiltViewModel(),
pages: Array<SunflowerPage> = SunflowerPage.values()
) {
val pagerState = rememberPagerState()
val pagerState = rememberPagerState(pageCount = { pages.size })
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()

Scaffold(
Expand All @@ -89,6 +90,7 @@ fun HomeScreen(
HomePagerScreen(
onPlantClick = onPlantClick,
pagerState = pagerState,
pages = pages,
Modifier.padding(top = contentPadding.calculateTopPadding())
)
}
Expand All @@ -99,8 +101,8 @@ fun HomeScreen(
fun HomePagerScreen(
onPlantClick: (Plant) -> Unit,
pagerState: PagerState,
pages: Array<SunflowerPage>,
modifier: Modifier = Modifier,
pages: Array<SunflowerPage> = SunflowerPage.values()
) {
Column(modifier) {
val coroutineScope = rememberCoroutineScope()
Expand Down Expand Up @@ -129,7 +131,6 @@ fun HomePagerScreen(
// Pages
HorizontalPager(
modifier = Modifier.background(MaterialTheme.colorScheme.background),
pageCount = pages.size,
state = pagerState,
verticalAlignment = Alignment.Top
) { index ->
Expand Down Expand Up @@ -200,9 +201,11 @@ private fun HomeTopAppBar(
@Composable
private fun HomeScreenPreview() {
SunflowerTheme {
val pages = SunflowerPage.values()
HomePagerScreen(
onPlantClick = {},
pagerState = PagerState(),
pagerState = rememberPagerState(pageCount = { pages.size }),
pages = pages
)
}
}

0 comments on commit 76fe346

Please sign in to comment.