Skip to content

Commit bcf828a

Browse files
committed
style: animation polish
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 12ab06e commit bcf828a

3 files changed

Lines changed: 48 additions & 14 deletions

File tree

apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/MessengerScreen.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.flipcash.app.messenger.internal.screens
22

33
import androidx.compose.animation.AnimatedContent
4+
import androidx.compose.animation.AnimatedVisibility
45
import androidx.compose.animation.core.animateFloatAsState
6+
import androidx.compose.animation.expandHorizontally
57
import androidx.compose.animation.fadeIn
68
import androidx.compose.animation.fadeOut
9+
import androidx.compose.animation.shrinkHorizontally
710
import androidx.compose.animation.slideInVertically
811
import androidx.compose.animation.slideOutVertically
912
import androidx.compose.animation.togetherWith
@@ -216,12 +219,17 @@ private fun UserControlBottomBar(
216219
buttonState = ButtonState.Filled,
217220
text = stringResource(R.string.action_sendCash),
218221
) { dispatch(ChatViewModel.Event.OnSendCash) }
219-
if (state.hasPayment) {
222+
AnimatedVisibility(
223+
visible = state.hasPayment,
224+
modifier = Modifier.weight(1f),
225+
enter = expandHorizontally(expandFrom = Alignment.Start) + fadeIn(),
226+
exit = shrinkHorizontally(shrinkTowards = Alignment.Start) + fadeOut(),
227+
) {
220228
val material = HazeMaterials.ultraThin(
221229
containerColor = CodeTheme.colors.background
222230
)
223231
CodeButton(
224-
modifier = Modifier.weight(1f)
232+
modifier = Modifier
225233
.hazeEffect(hazeState) {
226234
blurEffect {
227235
style = material

apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/components/MessageList.kt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.flipcash.app.messenger.internal.screens.components
22

3+
import androidx.compose.animation.AnimatedContent
34
import androidx.compose.animation.core.animateFloatAsState
5+
import androidx.compose.animation.fadeIn
6+
import androidx.compose.animation.fadeOut
7+
import androidx.compose.animation.togetherWith
48
import androidx.compose.foundation.layout.Arrangement
59
import androidx.compose.foundation.layout.Box
610
import androidx.compose.foundation.layout.Column
@@ -125,7 +129,11 @@ internal fun MessageList(
125129
val item = messages[index] ?: return@items
126130
val bottomSpacing = bottomSpacingFor(index, item, messages, separatorConfig)
127131

128-
Box(modifier = Modifier.padding(bottom = bottomSpacing)) {
132+
Box(
133+
modifier = Modifier
134+
.padding(bottom = bottomSpacing)
135+
.animateItem(),
136+
) {
129137
when (item) {
130138
is ChatListItem.DateSeparator -> DateSeparatorRow(item.label)
131139
is ChatListItem.ContentBubble -> {
@@ -296,15 +304,21 @@ private fun shouldShowReceiptLabel(
296304

297305
@Composable
298306
private fun ReceiptLabel(status: ReceiptStatus, modifier: Modifier = Modifier) {
299-
val text = when (status) {
300-
ReceiptStatus.SENT -> "Delivered"
301-
ReceiptStatus.READ -> "Read"
302-
else -> return
303-
}
304-
Text(
305-
text = text,
306-
style = CodeTheme.typography.caption,
307-
color = CodeTheme.colors.textSecondary,
307+
AnimatedContent(
308+
targetState = status,
308309
modifier = modifier.padding(top = CodeTheme.dimens.grid.x1),
309-
)
310+
transitionSpec = { fadeIn() togetherWith fadeOut() },
311+
label = "receiptStatus",
312+
) { animatedStatus ->
313+
val text = when (animatedStatus) {
314+
ReceiptStatus.SENT -> "Delivered"
315+
ReceiptStatus.READ -> "Read"
316+
else -> return@AnimatedContent
317+
}
318+
Text(
319+
text = text,
320+
style = CodeTheme.typography.caption,
321+
color = CodeTheme.colors.textSecondary,
322+
)
323+
}
310324
}

apps/flipcash/shared/amount-entry/src/main/kotlin/com/flipcash/shared/amountentry/AmountEntryDelegate.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import kotlinx.coroutines.flow.SharingStarted
1313
import kotlinx.coroutines.flow.StateFlow
1414
import kotlinx.coroutines.flow.asStateFlow
1515
import kotlinx.coroutines.flow.combine
16+
import kotlinx.coroutines.flow.filterNotNull
1617
import kotlinx.coroutines.flow.launchIn
1718
import kotlinx.coroutines.flow.onEach
19+
import kotlinx.coroutines.flow.scan
1820
import kotlinx.coroutines.flow.stateIn
1921
import kotlinx.coroutines.flow.update
2022
import kotlin.math.roundToInt
@@ -80,7 +82,17 @@ class AmountEntryDelegate(
8082
loadingState = loading,
8183
),
8284
)
83-
}.stateIn(
85+
}.scan(null as AmountEntryConfig?) { prev, current ->
86+
// Freeze hint and confirm state while send is in progress;
87+
// only the action's loadingState is allowed to update.
88+
val loading = current.action.loadingState
89+
if (prev != null && (loading.loading || loading.success)) {
90+
prev.copy(action = current.action)
91+
} else {
92+
current
93+
}
94+
}.filterNotNull()
95+
.stateIn(
8496
scope,
8597
SharingStarted.WhileSubscribed(5000),
8698
AmountEntryConfig(

0 commit comments

Comments
 (0)