potential fix of state value change in asMutableComposeState

This commit is contained in:
InsanusMokrassar 2023-01-23 15:21:47 +06:00
parent 8a6b4bb49e
commit 6ebc5aa0c2

View File

@ -1,6 +1,7 @@
package dev.inmo.micro_utils.coroutines.compose
import androidx.compose.runtime.*
import dev.inmo.micro_utils.coroutines.doInUI
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
@ -11,7 +12,7 @@ fun <T> Flow<T>.asMutableComposeState(
scope: CoroutineScope
): MutableState<T> {
val state = mutableStateOf(initial)
subscribeSafelyWithoutExceptions(scope) { state.value = it }
subscribeSafelyWithoutExceptions(scope) { doInUI { state.value = it } }
return state
}