Skip to content

Commit

Permalink
[REFACTOR] #44 - HomeScreen에서 달력의 특정 날짜 클릭 시, 해당 날짜로 카드가 이동하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
aurora32s committed Apr 28, 2023
1 parent 5398202 commit 1e1600c
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions feature/home/src/main/java/com/feature/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
Expand All @@ -15,6 +16,7 @@ import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
Expand All @@ -29,6 +31,7 @@ import com.core.designsystem.components.HarooButton
import com.core.designsystem.components.HarooDashLine
import com.core.designsystem.components.HarooDivider
import com.core.designsystem.components.calendar.Calendar
import com.core.designsystem.modifiers.noRippleClickable
import com.core.designsystem.modifiers.pagerHingeTransition
import com.core.designsystem.util.getString
import com.core.model.feature.PostUiModel
Expand All @@ -37,6 +40,8 @@ import com.core.ui.date.DateWithImage
import com.core.ui.date.RowMonthAndName
import com.core.ui.manager.SnackbarManager
import com.core.ui.post.SimplePostItem
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import java.time.LocalDate
import java.time.YearMonth

Expand Down Expand Up @@ -153,14 +158,17 @@ fun MonthlyList(
* 각 월별 Component
*/
@Composable
@OptIn(ExperimentalFoundationApi::class)
fun MonthlyContainer(
date: YearMonth,
modifier: Modifier = Modifier,
posts: List<PostUiModel>,
coroutine: CoroutineScope = rememberCoroutineScope(),
onClickPost: (LocalDate) -> Unit,
onClickMonth: (YearMonth) -> Unit,
onRemovePost: (PostUiModel) -> Unit
) {
val pagerState = rememberPagerState()
val groupedPosts = remember(posts) { posts.associateBy { it.date } }
Column(modifier = modifier.fillMaxWidth()) {
Column(
Expand All @@ -171,9 +179,18 @@ fun MonthlyContainer(
modifier = Modifier.padding(vertical = componentVerticalSpacer),
date = date
)
MonthlyCalendar(date = date, posts = groupedPosts)
MonthlyCalendar(
date = date,
posts = groupedPosts,
onClickPost = {
coroutine.launch {
pagerState.animateScrollToPage(page = it.dayOfMonth - 1)
}
}
)
HarooDashLine()
DailyContainer(
pagerState = pagerState,
date = date, posts = groupedPosts,
onClickPost = onClickPost,
onRemovePost = onRemovePost
Expand All @@ -192,15 +209,18 @@ fun MonthlyCalendar(
modifier: Modifier = Modifier,
verticalSpace: Dp = 10.dp,
horizontalSpace: Dp = 4.dp,
posts: Map<LocalDate, PostUiModel>
posts: Map<LocalDate, PostUiModel>,
onClickPost: (LocalDate) -> Unit
) {
Calendar(
modifier = modifier.padding(vertical = componentVerticalSpacer),
space = verticalSpace,
currentMonth = date,
dayContent = {
DateWithImage(
modifier = Modifier.padding(horizontal = horizontalSpace),
modifier = Modifier
.padding(horizontal = horizontalSpace)
.noRippleClickable { onClickPost(it.date) },
state = it,
image = posts[it.date]?.images?.firstOrNull()
)
Expand All @@ -214,13 +234,13 @@ fun MonthlyCalendar(
@Composable
@OptIn(ExperimentalFoundationApi::class)
fun DailyContainer(
pagerState: PagerState,
date: YearMonth,
modifier: Modifier = Modifier,
posts: Map<LocalDate, PostUiModel>,
onClickPost: (LocalDate) -> Unit,
onRemovePost: (PostUiModel) -> Unit
) {
val pagerState = rememberPagerState()
val dateCount = remember(date) { date.lengthOfMonth() }
HorizontalPager(
modifier = modifier.padding(vertical = componentVerticalSpacer),
Expand Down

0 comments on commit 1e1600c

Please sign in to comment.