Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEEK7] 7차 필수과제 구현 #14

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app/src/main/java/org/sopt/and/presentation/ui/home/HomeRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package org.sopt.and.presentation.ui.home

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand All @@ -15,19 +17,24 @@ fun HomeRoute(
homeViewModel: HomeViewModel = hiltViewModel()
) {
val homeState by homeViewModel.uiState.collectAsStateWithLifecycle()
val pagerState = rememberPagerState(pageCount = { homeState.bannerImgList.size })

LaunchedEffect(Unit) {
homeViewModel.setHomeImgList()
}

LaunchedEffect(pagerState) {
snapshotFlow { pagerState.currentPage }.collect { page ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snapshotFlow는 혹시 사용하신 이유가 있나요??

homeViewModel.setCurrentBannerPage(page)
}
}

HomeScreen(
modifier = Modifier
.padding(paddingValues),
bannerImgList = homeState.bannerImgList,
numPages = homeState.bannerImgList.size.toString(),
onCurrentPageChanged = { page ->
homeViewModel.setCurrentBannerPage(page)
},
pagerState = pagerState,
editorRecommendedImgList = homeState.editorRecommendedList,
todayTopRankingImgList = homeState.todayTopRankingList
)
Expand Down
15 changes: 4 additions & 11 deletions app/src/main/java/org/sopt/and/presentation/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -33,8 +33,8 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.sopt.and.R
import org.sopt.and.presentation.ui.home.component.TextWithNavigateButton
import org.sopt.and.presentation.ui.home.component.HomeAsyncImage
import org.sopt.and.presentation.ui.home.component.TextWithNavigateButton
import org.sopt.and.ui.theme.ANDANDROIDTheme
import org.sopt.and.ui.theme.Gray100
import org.sopt.and.ui.theme.GrayBlack
Expand All @@ -44,26 +44,20 @@ import org.sopt.and.ui.theme.White
fun HomeScreen(
bannerImgList: List<String>,
numPages: String,
onCurrentPageChanged: (Int) -> Unit,
editorRecommendedImgList: List<String>,
todayTopRankingImgList: List<String>,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
pagerState: PagerState = rememberPagerState(pageCount = { 0 }),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HomeScreen에서 rememberPagerState는 어떻게 사용되는건가요??

) {
Column(
modifier = modifier
.fillMaxSize()
.background(GrayBlack)
.verticalScroll(rememberScrollState())
) {
val pagerState = rememberPagerState(pageCount = { bannerImgList.size })
val horizontalContentPadding =
((LocalConfiguration.current).screenWidthDp * (1F - 0.85F) / 2).dp

// TODO PagerState 자체를 인자로 받고 아래 LaunchedEffect를 HomeRoute로 옮기기
LaunchedEffect(pagerState.currentPage) {
onCurrentPageChanged(pagerState.currentPage)
}

HorizontalPager(
state = pagerState,
contentPadding = PaddingValues(horizontal = horizontalContentPadding),
Expand Down Expand Up @@ -214,7 +208,6 @@ fun HomePreview() {
HomeScreen(
bannerImgList = listOf(""),
numPages = "6",
onCurrentPageChanged = { },
editorRecommendedImgList = listOf(""),
todayTopRankingImgList = listOf("")
)
Expand Down