11package com.getcode.view.main.currency
22
3+ import androidx.compose.animation.core.animateDpAsState
34import androidx.compose.foundation.Image
45import androidx.compose.foundation.background
56import androidx.compose.foundation.layout.Box
@@ -43,7 +44,10 @@ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
4344import androidx.compose.ui.res.painterResource
4445import androidx.compose.ui.res.stringResource
4546import androidx.compose.ui.text.input.TextFieldValue
47+ import androidx.compose.ui.unit.Dp
48+ import androidx.compose.ui.unit.DpSize
4649import androidx.compose.ui.unit.dp
50+ import androidx.compose.ui.unit.isUnspecified
4751import androidx.compose.ui.unit.sp
4852import androidx.lifecycle.Lifecycle
4953import com.getcode.R
@@ -58,6 +62,9 @@ import com.getcode.ui.utils.RepeatOnLifecycle
5862import com.getcode.ui.utils.rememberedClickable
5963import com.getcode.ui.components.CodeCircularProgressIndicator
6064import com.getcode.ui.components.SwipeableView
65+ import com.getcode.ui.utils.addIf
66+ import com.getcode.ui.utils.keyboardAsState
67+ import com.getcode.ui.utils.measured
6168import com.getcode.view.main.giveKin.CurrencyListItem
6269import kotlinx.coroutines.delay
6370import kotlinx.coroutines.flow.distinctUntilChanged
@@ -87,20 +94,7 @@ fun CurrencySelectionSheet(
8794 }
8895 }
8996
90- RepeatOnLifecycle (targetState = Lifecycle .State .RESUMED ) {
91- viewModel.eventFlow
92- .filterIsInstance<CurrencyViewModel .Event .OnSelectedCurrencyChanged >()
93- .filter { it.fromUser }
94- .map { it.currency }
95- .distinctUntilChanged()
96- .onEach {
97- composeScope.launch {
98- keyboardController?.hide()
99- delay(500 )
100- navigator.popWithResult(it)
101- }
102- }.launchIn(this )
103- }
97+ val keyboard by keyboardAsState()
10498
10599 Column (
106100 modifier = Modifier .imePadding()
@@ -205,9 +199,25 @@ fun CurrencySelectionSheet(
205199 }
206200
207201 is CurrencyListItem .RegionCurrencyItem -> {
202+ var isSwipedAway by remember(listItem) {
203+ mutableStateOf(false )
204+ }
205+
206+ var height by remember {
207+ mutableStateOf(0 .dp)
208+ }
209+
210+ val animatedHeight by animateDpAsState(targetValue = if (! isSwipedAway) height else 0 .dp)
211+
208212 SwipeableView (
213+ modifier = Modifier .measured {
214+ if (height == 0 .dp) {
215+ height = it.height
216+ }
217+ }.addIf(height != 0 .dp) { Modifier .height(animatedHeight) },
209218 isSwipeEnabled = listItem.isRecent,
210219 leftSwiped = {
220+ isSwipedAway = true
211221 viewModel.dispatchEvent(
212222 CurrencyViewModel .Event .OnRecentCurrencyRemoved (
213223 listItem.currency
@@ -224,6 +234,13 @@ fun CurrencySelectionSheet(
224234 state.selectedCurrencyCode.orEmpty() == currencyCode,
225235 isDisabled,
226236 ) {
237+ composeScope.launch {
238+ if (keyboard) {
239+ keyboardController?.hide()
240+ delay(500 )
241+ }
242+ navigator.popWithResult(listItem.currency)
243+ }
227244 viewModel.dispatchEvent(
228245 CurrencyViewModel .Event .OnSelectedCurrencyChanged (
229246 listItem.currency
0 commit comments