Updated on 2026-08-14
This commit is contained in:
parent
2e7c487c46
commit
af29fec09f
4 changed files with 22 additions and 1 deletions
|
|
@ -442,6 +442,16 @@ internal class WalletModel @Inject constructor(
|
|||
// Should not show scroll animation if WalletScreen isn't in the background.
|
||||
if (screenLifecycleProvider.isBackgroundState.value) {
|
||||
onConsume()
|
||||
stateHolder.update(
|
||||
ScrollToWalletTransformer(
|
||||
prevIndex = prevIndex,
|
||||
newIndex = newIndex,
|
||||
currentStateProvider = Provider(action = stateHolder::value),
|
||||
withScrollAnimation = false,
|
||||
stateUpdater = { newState -> stateHolder.update { newState } },
|
||||
onConsume = {},
|
||||
),
|
||||
)
|
||||
} else {
|
||||
stateHolder.update(
|
||||
ScrollToWalletTransformer(
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ internal sealed class WalletEvent {
|
|||
/** Change wallet with animation. Using [prevIndex] and [newIndex] to calculate offset */
|
||||
data class ChangeWallet(val prevIndex: Int, val newIndex: Int) : WalletEvent()
|
||||
|
||||
data class ChangeWalletWithoutScroll(val newIndex: Int) : WalletEvent()
|
||||
|
||||
data class ShowError(val text: TextReference) : WalletEvent()
|
||||
|
||||
data class ShowAlert(val state: WalletAlertState) : WalletEvent()
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ internal class ScrollToWalletTransformer(
|
|||
private val prevIndex: Int,
|
||||
private val newIndex: Int,
|
||||
private val currentStateProvider: Provider<WalletScreenState>,
|
||||
private val withScrollAnimation: Boolean = true,
|
||||
private val stateUpdater: (WalletScreenState) -> Unit,
|
||||
private val onConsume: () -> Unit = {},
|
||||
) : WalletScreenStateTransformer {
|
||||
|
|
@ -17,7 +18,11 @@ internal class ScrollToWalletTransformer(
|
|||
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
||||
return prevState.copy(
|
||||
event = triggeredEvent(
|
||||
data = WalletEvent.ChangeWallet(prevIndex = prevIndex, newIndex = newIndex),
|
||||
data = if (withScrollAnimation) {
|
||||
WalletEvent.ChangeWallet(prevIndex = prevIndex, newIndex = newIndex)
|
||||
} else {
|
||||
WalletEvent.ChangeWalletWithoutScroll(newIndex = newIndex)
|
||||
},
|
||||
onConsume = {
|
||||
stateUpdater(
|
||||
currentStateProvider().copy(event = consumedEvent()),
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ internal fun WalletEventEffect(
|
|||
onAutoScrollSet()
|
||||
walletsListState.animateScrollByIndex(prevIndex = value.prevIndex, newIndex = value.newIndex)
|
||||
}
|
||||
is WalletEvent.ChangeWalletWithoutScroll -> {
|
||||
onAutoScrollSet()
|
||||
walletsListState.scrollToItem(value.newIndex)
|
||||
}
|
||||
is WalletEvent.ShowError -> {
|
||||
snackbarHostState.showSnackbar(message = value.text.resolveReference(resources))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue