Skip to content

Commit

Permalink
[FIX/#305] 전환 모션 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
boiledEgg-s committed Dec 12, 2024
1 parent ee68943 commit 3dbc4a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.terning.feature.calendar.calendar

import androidx.compose.animation.core.Transition
import androidx.compose.animation.core.tween
import androidx.compose.animation.core.updateTransition
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutHorizontally
Expand Down Expand Up @@ -78,6 +80,11 @@ private fun CalendarScreen(
) {
val coroutineScope = rememberCoroutineScope()

val calendarListTransition =
updateTransition(!uiState.isListEnabled, label = "calendarListTransition")
val monthWeekTransition =
updateTransition(!uiState.isWeekEnabled, label = "monthWeekTransition")

val pagerState = rememberPagerState(
initialPage = uiState.calendarModel.initialPage,
pageCount = { uiState.calendarModel.pageCount }
Expand Down Expand Up @@ -107,7 +114,10 @@ private fun CalendarScreen(
CalendarTopAppBar(
date = uiState.calendarModel.getYearMonthByPage(pagerState.settledPage),
isListExpanded = uiState.isListEnabled,
onListButtonClicked = onClickListButton,
onListButtonClicked = {
if(!calendarListTransition.isRunning)
onClickListButton()
},
onMonthNavigationButtonClicked = { direction ->
coroutineScope.launch {
pagerState.animateScrollToPage(
Expand All @@ -119,7 +129,7 @@ private fun CalendarScreen(
)

CalendarListTransition(
isCalendarEnabled = !uiState.isListEnabled,
transition = calendarListTransition,
calendarModel = uiState.calendarModel,
pagerState = pagerState,
onNavigateToAnnouncement = navigateToAnnouncement,
Expand All @@ -137,7 +147,7 @@ private fun CalendarScreen(
)

MonthWeekTransition(
isMonthEnabled = !uiState.isWeekEnabled,
transition = monthWeekTransition,
selectedDate = uiState.selectedDate,
calendarModel = uiState.calendarModel,
pagerState = pagerState,
Expand All @@ -155,15 +165,15 @@ private fun CalendarScreen(
/** 달력 <-> 목록 전환 컴포저블 */
@Composable
private fun CalendarListTransition(
isCalendarEnabled: Boolean,
transition: Transition<Boolean>,
calendarModel: TerningCalendarModel,
pagerState: PagerState,
onNavigateToAnnouncement: (Long) -> Unit,
onNavigateUpToCalendar: () -> Unit,
calendarContent: @Composable () -> Unit,
) {
ScreenTransition(
targetState = isCalendarEnabled,
transition = transition,
transitionOne = slideInHorizontally { fullWidth -> -fullWidth } togetherWith
slideOutHorizontally { fullWidth -> fullWidth },
transitionTwo = slideInHorizontally { fullWidth -> fullWidth } togetherWith
Expand All @@ -187,7 +197,7 @@ private fun CalendarListTransition(
/**월간 <-> 주간 전환 컴포저블*/
@Composable
private fun MonthWeekTransition(
isMonthEnabled: Boolean,
transition: Transition<Boolean>,
selectedDate: DayModel,
calendarModel: TerningCalendarModel,
pagerState: PagerState,
Expand All @@ -196,7 +206,7 @@ private fun MonthWeekTransition(
onNavigateUpToMonth: () -> Unit,
) {
ScreenTransition(
targetState = isMonthEnabled,
transition = transition,
transitionOne = slideInVertically { fullHeight -> -fullHeight } togetherWith
slideOutVertically { fullHeight -> fullHeight },
transitionTwo = slideInVertically { fullHeight -> fullHeight } togetherWith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package com.terning.feature.calendar.calendar.component
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.ContentTransform
import androidx.compose.animation.SizeTransform
import androidx.compose.animation.core.Transition
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.terning.feature.calendar.R

/**
* 두 화면 간 전환을 담당하는 컴포넌트
*
* @param targetState 전환할 상태
* @param transition [Transition]
* @param transitionOne 첫번째 화면에서 두번쨰 화면으로 이동할 때 발생할 전환 모션
* @param transitionTwo 두번째 화면에서 첫번째 화면으로 이동할 때 발생할 전환 모션
* @param contentOne 첫번째 화면
Expand All @@ -19,14 +18,13 @@ import com.terning.feature.calendar.R

@Composable
fun ScreenTransition(
targetState: Boolean,
transition: Transition<Boolean>,
transitionOne: ContentTransform,
transitionTwo: ContentTransform,
contentOne: @Composable () -> Unit,
contentTwo: @Composable () -> Unit
) {
AnimatedContent(
targetState = targetState,
transition.AnimatedContent(
transitionSpec = {
if (targetState) {
transitionOne
Expand All @@ -36,7 +34,6 @@ fun ScreenTransition(
sizeTransform = SizeTransform(clip = true)
)
},
label = stringResource(id = R.string.calendar_animation_label)
) { state ->
if (state) {
contentOne.invoke()
Expand Down

0 comments on commit 3dbc4a6

Please sign in to comment.