Skip to content

Commit d1547d0

Browse files
authored
Merge pull request #100 from code-payments/chore/grabbed-bill-aniamtion
feat: tweak bill grabbed animation to match iOS
2 parents 21e3e39 + f3eb47e commit d1547d0

3 files changed

Lines changed: 33 additions & 13 deletions

File tree

app/src/main/java/com/getcode/util/AnimationUtils.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,41 @@ package com.getcode.util
22

33
import androidx.compose.animation.*
44
import androidx.compose.animation.core.*
5-
import androidx.navigation.NavBackStackEntry
65

76

87
object AnimationUtils {
98
const val animationTime = 350
109

1110

12-
val animationBillEnter = slideInVertically(
11+
val animationBillEnterGive = slideInVertically(
1312
initialOffsetY = { it },
1413
animationSpec = spring(
1514
dampingRatio = 0.6f,
1615
stiffness = 400f
1716
)
1817
)
1918

20-
val animationBillEnterSpring = scaleIn(
19+
val animationBillEnterGrabbed = scaleIn(
2120
animationSpec = spring(
2221
dampingRatio = Spring.DampingRatioMediumBouncy,
2322
stiffness = 1500f
2423
),
2524
initialScale = 0.5f
2625
)
2726

28-
val animationBillExit = slideOutVertically(
27+
val animationBillExitReturned = slideOutVertically(
2928
targetOffsetY = { it },
3029
animationSpec = tween(
3130
durationMillis = 600,
3231
easing = FastOutSlowInEasing
3332
)
3433
)
34+
35+
val animationBillExitGrabbed = fadeOut(tween(durationMillis = 400)) + scaleOut(
36+
animationSpec = spring(
37+
dampingRatio = 0.4f,
38+
stiffness = 400f
39+
),
40+
targetScale = 1.1f
41+
)
3542
}

app/src/main/java/com/getcode/view/main/home/HomeScan.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.getcode.view.main.home
22

33
import android.Manifest
44
import android.app.Activity
5-
import android.content.Context
65
import android.content.Intent
76
import androidx.compose.animation.AnimatedContent
87
import androidx.compose.animation.AnimatedVisibility
@@ -68,7 +67,6 @@ import com.getcode.navigation.screens.GiveKinModal
6867
import com.getcode.theme.Brand
6968
import com.getcode.theme.CodeTheme
7069
import com.getcode.util.AnimationUtils
71-
import com.getcode.util.ChromeTabsUtils
7270
import com.getcode.util.addIf
7371
import com.getcode.util.flagResId
7472
import com.getcode.util.formatted
@@ -401,7 +399,7 @@ private fun BillContainer(
401399
val showManagementOptions by remember(updatedState.billState) {
402400
derivedStateOf {
403401
billDismissState.targetValue == DismissValue.Default &&
404-
updatedState.billState.bill != null &&
402+
updatedState.billState.valuation != null &&
405403
!updatedState.billState.hideBillButtons
406404
}
407405
}
@@ -420,13 +418,13 @@ private fun BillContainer(
420418
bill = updatedState.billState.bill,
421419
transitionSpec = {
422420
if (updatedState.presentationStyle is PresentationStyle.Slide) {
423-
AnimationUtils.animationBillEnter
421+
AnimationUtils.animationBillEnterGive
424422
} else {
425-
AnimationUtils.animationBillEnterSpring
423+
AnimationUtils.animationBillEnterGrabbed
426424
} togetherWith if (updatedState.presentationStyle is PresentationStyle.Slide) {
427-
AnimationUtils.animationBillExit
425+
AnimationUtils.animationBillExitReturned
428426
} else {
429-
fadeOut()
427+
AnimationUtils.animationBillExitGrabbed
430428
}
431429
}
432430
)

app/src/main/java/com/getcode/view/main/home/HomeViewModel.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ class HomeViewModel @Inject constructor(
351351
amount = bill.amount,
352352
didReceive = bill.didReceive
353353
),
354+
valuation = Valuation(bill.amount),
354355
showToast = bill.didReceive
355356
)
356357
)
@@ -385,12 +386,26 @@ class HomeViewModel @Inject constructor(
385386
presentationStyle = style,
386387
billState = it.billState.copy(
387388
bill = null,
388-
valuation = null,
389-
hideBillButtons = false,
390389
)
391390
)
392391
}
393392

393+
viewModelScope.launch {
394+
if (shown) {
395+
delay(300)
396+
}
397+
withContext(Dispatchers.Main) {
398+
uiFlow.update {
399+
it.copy(
400+
billState = it.billState.copy(
401+
valuation = null,
402+
hideBillButtons = false
403+
)
404+
)
405+
}
406+
}
407+
}
408+
394409
viewModelScope.launch {
395410
if (shown) {
396411
delay(5.seconds.inWholeMilliseconds)

0 commit comments

Comments
 (0)