-
Notifications
You must be signed in to change notification settings - Fork 1
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
[REFACTOR/#246] 달력 로직 대폭 수정 #248
Changes from all commits
5c7cfc3
d8461df
7bf4b6c
b0eb875
c966343
fe4e5ab
b5652ee
f872256
0655243
6475ede
9fb6115
6bad0fd
4b6db8f
d0c05a3
05c6f89
f40f734
0636231
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.terning.feature.calendar.calendar | ||
|
||
import androidx.compose.animation.core.tween | ||
import androidx.compose.animation.slideInHorizontally | ||
import androidx.compose.animation.slideInVertically | ||
import androidx.compose.animation.slideOutHorizontally | ||
|
@@ -8,11 +9,10 @@ import androidx.compose.animation.togetherWith | |
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.rememberLazyListState | ||
import androidx.compose.foundation.pager.rememberPagerState | ||
import androidx.compose.material3.HorizontalDivider | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
|
@@ -27,12 +27,13 @@ import com.terning.core.designsystem.theme.Grey200 | |
import com.terning.core.designsystem.theme.White | ||
import com.terning.feature.calendar.calendar.component.ScreenTransition | ||
import com.terning.feature.calendar.calendar.component.WeekDaysHeader | ||
import com.terning.feature.calendar.calendar.model.CalendarModel.Companion.getLocalDateByPage | ||
import com.terning.feature.calendar.calendar.model.CalendarModel.Companion.getYearMonthByPage | ||
import com.terning.feature.calendar.calendar.model.CalendarUiState | ||
import com.terning.feature.calendar.calendar.model.LocalPagerState | ||
import com.terning.feature.calendar.list.CalendarListRoute | ||
import com.terning.feature.calendar.month.CalendarMonthRoute | ||
import com.terning.feature.calendar.week.CalendarWeekRoute | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.launch | ||
import java.time.LocalDate | ||
|
||
|
@@ -49,119 +50,119 @@ fun CalendarRoute( | |
modifier = modifier, | ||
uiState = uiState, | ||
navigateToAnnouncement = navigateToAnnouncement, | ||
onClickNewDate = viewModel::onSelectNewDate, | ||
updateSelectedDate = viewModel::updateSelectedDate, | ||
updatePage = viewModel::updatePage, | ||
disableListVisibility = { viewModel.updateListVisibility(false) }, | ||
disableWeekVisibility = { viewModel.updateSelectedDate(uiState.selectedDate) }, | ||
onClickListButton = { | ||
viewModel.updateListVisibility(!uiState.isListEnabled) | ||
if (uiState.isWeekEnabled) { | ||
viewModel.updateWeekVisibility(false) | ||
} | ||
} | ||
disableWeekVisibility = { viewModel.updateWeekVisibility(false) }, | ||
onClickListButton = { viewModel.updateListVisibility(!uiState.isListEnabled) } | ||
) | ||
} | ||
|
||
@Composable | ||
private fun CalendarScreen( | ||
uiState: CalendarUiState, | ||
navigateToAnnouncement: (Long) -> Unit, | ||
onClickNewDate: (LocalDate) -> Unit, | ||
updateSelectedDate: (LocalDate) -> Unit, | ||
disableListVisibility: () -> Unit, | ||
disableWeekVisibility: () -> Unit, | ||
updatePage: (Int) -> Unit, | ||
onClickListButton: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val coroutineScope = rememberCoroutineScope() | ||
|
||
val listState = rememberLazyListState( | ||
initialFirstVisibleItemIndex = uiState.calendarModel.initialPage | ||
val pagerState = rememberPagerState( | ||
initialPage = uiState.calendarModel.initialPage, | ||
pageCount = { uiState.calendarModel.pageCount } | ||
) | ||
|
||
LaunchedEffect(key1 = listState) { | ||
snapshotFlow { listState.firstVisibleItemIndex } | ||
.distinctUntilChanged() | ||
.collect { | ||
updatePage(listState.firstVisibleItemIndex) | ||
LaunchedEffect(key1 = pagerState, key2 = uiState.selectedDate) { | ||
snapshotFlow { pagerState.currentPage } | ||
.collect { current -> | ||
val date = getLocalDateByPage(current) | ||
val newDate = LocalDate.of(date.year, date.month, uiState.selectedDate.dayOfMonth) | ||
updateSelectedDate(newDate) | ||
} | ||
} | ||
|
||
Column( | ||
modifier = modifier, | ||
){ | ||
CalendarTopAppBar( | ||
date = getYearMonthByPage(uiState.currentPage), | ||
isListExpanded = uiState.isListEnabled, | ||
isWeekExpanded = uiState.isWeekEnabled, | ||
onListButtonClicked = onClickListButton, | ||
onMonthNavigationButtonClicked = { direction -> | ||
coroutineScope.launch { | ||
listState.animateScrollToItem( | ||
index = listState.firstVisibleItemIndex + direction, | ||
) | ||
CompositionLocalProvider( | ||
LocalPagerState provides pagerState | ||
Comment on lines
+88
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 우와,..이것뭐예요....헐 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 특정 컴포저블의 하위 컴포저블에서 변수를 전역으로 사용할 수 있게끔 해주는 CompositionLocal입니다! |
||
) { | ||
Column( | ||
modifier = modifier, | ||
) { | ||
CalendarTopAppBar( | ||
date = getYearMonthByPage(pagerState.settledPage), | ||
isListExpanded = uiState.isListEnabled, | ||
onListButtonClicked = onClickListButton, | ||
onMonthNavigationButtonClicked = { direction -> | ||
coroutineScope.launch { | ||
pagerState.animateScrollToPage( | ||
page = pagerState.settledPage + direction, | ||
animationSpec = tween(500) | ||
) | ||
} | ||
} | ||
} | ||
) | ||
ScreenTransition( | ||
targetState = !uiState.isListEnabled, | ||
transitionOne = slideInHorizontally { fullWidth -> -fullWidth } togetherWith | ||
slideOutHorizontally { fullWidth -> fullWidth }, | ||
transitionTwo = slideInHorizontally { fullWidth -> fullWidth } togetherWith | ||
slideOutHorizontally { fullWidth -> -fullWidth }, | ||
contentOne = { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
) { | ||
WeekDaysHeader() | ||
) | ||
ScreenTransition( | ||
targetState = !uiState.isListEnabled, | ||
transitionOne = slideInHorizontally { fullWidth -> -fullWidth } togetherWith | ||
slideOutHorizontally { fullWidth -> fullWidth }, | ||
transitionTwo = slideInHorizontally { fullWidth -> fullWidth } togetherWith | ||
slideOutHorizontally { fullWidth -> -fullWidth }, | ||
contentOne = { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
) { | ||
WeekDaysHeader() | ||
|
||
HorizontalDivider( | ||
thickness = 1.dp, | ||
color = Grey200 | ||
) | ||
HorizontalDivider( | ||
thickness = 1.dp, | ||
color = Grey200 | ||
) | ||
|
||
ScreenTransition( | ||
targetState = !uiState.isWeekEnabled, | ||
transitionOne = slideInVertically { fullHeight -> -fullHeight } togetherWith | ||
slideOutVertically { fullHeight -> fullHeight }, | ||
transitionTwo = slideInVertically { fullHeight -> fullHeight } togetherWith | ||
slideOutVertically { fullHeight -> -fullHeight }, | ||
contentOne = { | ||
CalendarMonthRoute( | ||
listState = listState, | ||
pages = uiState.calendarModel.pageCount, | ||
selectedDate = uiState.selectedDate, | ||
updateSelectedDate = updateSelectedDate, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(White), | ||
) | ||
}, | ||
contentTwo = { | ||
CalendarWeekRoute( | ||
calendarUiState = uiState, | ||
modifier = Modifier | ||
.fillMaxSize(), | ||
navigateUp = disableWeekVisibility, | ||
navigateToAnnouncement = navigateToAnnouncement, | ||
updateSelectedDate = updateSelectedDate | ||
) | ||
} | ||
ScreenTransition( | ||
targetState = !uiState.isWeekEnabled, | ||
transitionOne = slideInVertically { fullHeight -> -fullHeight } togetherWith | ||
slideOutVertically { fullHeight -> fullHeight }, | ||
transitionTwo = slideInVertically { fullHeight -> fullHeight } togetherWith | ||
slideOutVertically { fullHeight -> -fullHeight }, | ||
contentOne = { | ||
CalendarMonthRoute( | ||
selectedDate = uiState.selectedDate, | ||
updateSelectedDate = { newDate -> | ||
if(!pagerState.isScrollInProgress) | ||
onClickNewDate(newDate) | ||
}, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(White), | ||
) | ||
}, | ||
contentTwo = { | ||
CalendarWeekRoute( | ||
calendarUiState = uiState, | ||
modifier = Modifier | ||
.fillMaxSize(), | ||
navigateUp = disableWeekVisibility, | ||
navigateToAnnouncement = navigateToAnnouncement, | ||
updateSelectedDate = onClickNewDate | ||
) | ||
} | ||
) | ||
} | ||
}, | ||
contentTwo = { | ||
CalendarListRoute( | ||
navigateToAnnouncement = navigateToAnnouncement, | ||
navigateUp = disableListVisibility, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
) | ||
} | ||
}, | ||
contentTwo = { | ||
CalendarListRoute( | ||
listState = listState, | ||
pages = uiState.calendarModel.pageCount, | ||
navigateToAnnouncement = navigateToAnnouncement, | ||
navigateUp = disableListVisibility, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
) | ||
}, | ||
) | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
package com.terning.feature.calendar.calendar.model | ||
|
||
import androidx.compose.foundation.pager.PagerState | ||
import androidx.compose.runtime.compositionLocalOf | ||
import java.time.LocalDate | ||
|
||
data class CalendarUiState( | ||
val selectedDate: LocalDate = LocalDate.now(), | ||
val calendarModel: CalendarModel = CalendarModel(), | ||
val currentPage: Int = 0, | ||
val isListEnabled: Boolean = false, | ||
val isWeekEnabled: Boolean = false | ||
) | ||
|
||
val LocalPagerState = compositionLocalOf<PagerState> { | ||
error("No PagerState provided") | ||
} | ||
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 부분 하드코딩하신 이유가 따로 있으신가용?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UI적으로 필요한 부분이 아니라 그냥 하드코딩으로 넣어놨습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UI 관련이 아니군요 딱콩 ㅎ ㅅ ㅎ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pagerState.... 신기방기...