Skip to content

Commit 402ecb4

Browse files
committed
feat:TOP-107 shakingCard 애니메이션 적용
1 parent f467a4c commit 402ecb4

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

feature/tohot/src/main/java/tht/feature/tohot/component/card/ToHotCard.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fun ToHotCard(
4747
isHoldCard: Boolean,
4848
isShakingCard: Boolean,
4949
onFallingAnimationFinish: () -> Unit = { },
50+
onTicChanged: (Float) -> Unit = { },
5051
onTimerEnd: () -> Unit = { },
5152
userCardClick: () -> Unit = { },
5253
onLikeClick: () -> Unit = { },
@@ -106,6 +107,7 @@ fun ToHotCard(
106107
duration = remember(timer) {
107108
timer.duration.toLong(DurationUnit.MILLISECONDS)
108109
},
110+
onTicChanged = onTicChanged,
109111
onEnd = onTimerEnd
110112
)
111113
}

feature/tohot/src/main/java/tht/feature/tohot/component/progress/ToHotAnimateTimeProgressContainer.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fun ToHotAnimateTimeProgressContainer(
3232
duration: Long,
3333
enable: Boolean,
3434
onEnd: () -> Unit,
35+
onTicChanged: (Float) -> Unit,
3536
modifier: Modifier = Modifier,
3637
initialDelay: Long = 0L,
3738
completionDelay: Long = 0L
@@ -56,12 +57,14 @@ fun ToHotAnimateTimeProgressContainer(
5657
duration = duration,
5758
onTicChanged = {
5859
coroutineScope.launch {
59-
if (completionDelay > 0) {
60-
progressState = false
61-
}
62-
delay(completionDelay)
6360
if (it <= destinationSec) {
61+
if (completionDelay > 0) {
62+
progressState = false
63+
}
64+
delay(completionDelay)
6465
onEnd()
66+
} else {
67+
onTicChanged(it)
6568
}
6669
}
6770
}
@@ -84,14 +87,15 @@ private fun ToHotAnimateTimeProgressContainerInternal(
8487
Color(0xFFF93A2E)
8588
),
8689
progressBackgroundColor: Color = colorResource(id = tht.core.ui.R.color.black_353535),
87-
onTicChanged: (Float) -> Unit = { },
88-
completionDelayMillis: Long = 0L
90+
onTicChanged: (Float) -> Unit = { }
8991
) {
92+
val progressAnimatable = remember { Animatable(1f) }
9093
var currentSec by remember { mutableIntStateOf(maxTimeSec) }
9194
val destinationProgress = destinationSec / maxTimeSec.toFloat()
9295
var color by remember(progressColor) {
9396
mutableStateOf(progressColor.firstOrNull() ?: Color.Yellow)
9497
}
98+
9599
LaunchedEffect(currentSec) {
96100
for (i in progressColor.indices) {
97101
// currentSec로 하면 색상 변경이 좀 늦어져서, 1초 뒤 변경될 progress 기준으로 계산
@@ -109,8 +113,8 @@ private fun ToHotAnimateTimeProgressContainerInternal(
109113
label = "animateProgressColor"
110114
)
111115

112-
val progressAnimatable = remember { Animatable(1f) }
113116
LaunchedEffect(key1 = destinationSec, key2 = enable) {
117+
var prevTic = 0
114118
if (enable) {
115119
// 현재 progressValue -> 0.0 까지 필요한 destination 계산
116120
val progressDuration = duration * (progressAnimatable.value / 1f)
@@ -122,9 +126,11 @@ private fun ToHotAnimateTimeProgressContainerInternal(
122126
)
123127
) {
124128
currentSec = ceil((this.value * maxTimeSec)).toInt()
129+
if (prevTic != currentSec) {
130+
prevTic = currentSec
131+
onTicChanged(prevTic.toFloat())
132+
}
125133
}
126-
delay(completionDelayMillis)
127-
onTicChanged((progressAnimatable.value * maxTimeSec))
128134
}
129135
}
130136

@@ -160,6 +166,7 @@ private fun ToHotAnimateTimeProgressContainerPreview() {
160166
enable = true,
161167
onEnd = {},
162168
duration = 1000,
163-
maxTimer = 5
169+
maxTimer = 5,
170+
onTicChanged = {}
164171
)
165172
}

feature/tohot/src/main/java/tht/feature/tohot/tohot/route/ToHotRoute.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ internal fun ToHotRoute(
225225
alarmClickListener = toHotViewModel::alarmClickEvent,
226226
pageChanged = toHotViewModel::userChangeEvent,
227227
onTimerEnd = toHotViewModel::onTimerEnd,
228+
onTicChanged = toHotViewModel::onTicChanged,
228229
loadFinishListener = toHotViewModel::userCardLoadFinishEvent,
229230
onLikeClick = toHotViewModel::userHeartEvent,
230231
onUnLikeClick = toHotViewModel::userDislikeEvent,

feature/tohot/src/main/java/tht/feature/tohot/tohot/screen/ToHotScreen.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ internal fun ToHotScreen(
5151
alarmClickListener: () -> Unit = { },
5252
pageChanged: (Int) -> Unit,
5353
onTimerEnd: (Int) -> Unit,
54+
onTicChanged: (Float, Int) -> Unit,
5455
onLikeClick: (Int) -> Unit = { },
5556
onUnLikeClick: (Int) -> Unit = { },
5657
onReportMenuClick: () -> Unit = { },
@@ -117,6 +118,7 @@ internal fun ToHotScreen(
117118
onFallingAnimationFinish = { onFallingAnimationFinish(idx) },
118119
userCardClick = { },
119120
onReportMenuClick = onReportMenuClick,
121+
onTicChanged = { onTicChanged(it, idx) },
120122
onTimerEnd = { onTimerEnd(idx) },
121123
onLikeClick = { onLikeClick(idx) },
122124
onUnLikeClick = { onUnLikeClick(idx) },
@@ -178,6 +180,7 @@ fun ToHotScreenPreview() {
178180
alarmClickListener = { },
179181
pageChanged = { },
180182
onTimerEnd = { },
183+
onTicChanged = { _, _ -> },
181184
loadFinishListener = { _, _, _ -> },
182185
onLikeClick = { },
183186
onUnLikeClick = { },

feature/tohot/src/main/java/tht/feature/tohot/tohot/viewmodel/ToHotViewModel.kt

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -487,24 +487,19 @@ class ToHotViewModel @Inject constructor(
487487
tryScrollToNext(userIdx)
488488
}
489489

490-
/**
491-
* timer tic 이 변경될 때 호출
492-
* - timer 가 0이면 다음 유저 스크롤
493-
* - timer 가 0이 아니면 timer 를 1 감소
494-
*/
495-
fun ticChangeEvent(tic: Float, userIdx: Int) = with(store.state.value) {
490+
fun onTicChanged(tic: Float, userIdx: Int) = with(store.state.value) {
496491
Log.d("Timer", "ticChangeEvent => $tic from $userIdx => enableTimerIdx[$enableTimerIdx]")
497-
if (userIdx != enableTimerIdx) return@with
492+
if (userIdx != enableTimerIdx) return
493+
if (userIdx !in userList.list.indices) return
498494
if (tic <= 0) {
499-
tryScrollToNext(userIdx)
495+
onTimerEnd(userIdx)
500496
return
501497
}
502-
if (userIdx !in userList.list.indices) return
503-
intent {
504-
reduce {
505-
it.copy(
506-
shakingCard = tic <= SHAKING_ANIMATION_START_TIC
507-
)
498+
if (tic <= SHAKING_ANIMATION_START_TIC) {
499+
intent {
500+
reduce {
501+
it.copy(shakingCard = true)
502+
}
508503
}
509504
}
510505
}

0 commit comments

Comments
 (0)