Skip to content

Commit f2afc77

Browse files
committed
feat(add-new-user): fix event flow
1 parent 9fa4d9d commit f2afc77

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

core-ui/src/main/java/com/hoc/flowmvi/core_ui/rememberFlowWithLifecycle.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package com.hoc.flowmvi.core_ui
22

33
import androidx.compose.runtime.Composable
44
import androidx.compose.runtime.LaunchedEffect
5+
import androidx.compose.runtime.getValue
56
import androidx.compose.runtime.remember
7+
import androidx.compose.runtime.rememberUpdatedState
68
import androidx.compose.ui.platform.LocalLifecycleOwner
79
import androidx.lifecycle.Lifecycle
810
import androidx.lifecycle.flowWithLifecycle
@@ -33,10 +35,12 @@ fun <T> Flow<T>.collectInLaunchedEffectWithLifecycle(
3335
collector: suspend CoroutineScope.(T) -> Unit
3436
) {
3537
val flow = this
38+
val currentCollector by rememberUpdatedState(collector)
39+
3640
LaunchedEffect(flow, lifecycle, minActiveState, *keys) {
3741
withContext(Dispatchers.Main.immediate) {
3842
lifecycle.repeatOnLifecycle(minActiveState) {
39-
flow.collect { collector(it) }
43+
flow.collect { currentCollector(it) }
4044
}
4145
}
4246
}

mvi/mvi-base/src/main/java/com/hoc/flowmvi/mvi_base/AbstractMviViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class AbstractMviViewModel<I : MviIntent, S : MviViewState, E : MviSing
4545
private val eventChannel = Channel<E>(Channel.UNLIMITED)
4646
private val intentMutableFlow = MutableSharedFlow<I>(extraBufferCapacity = Int.MAX_VALUE)
4747

48-
final override val singleEvent: Flow<E> get() = eventChannel.receiveAsFlow()
48+
final override val singleEvent: Flow<E> = eventChannel.receiveAsFlow()
4949

5050
@MainThread
5151
final override suspend fun processIntent(intent: I) {

0 commit comments

Comments
 (0)