From 6ebc5aa0c2e238b1a1da96cb42080e2d66875dd2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 23 Jan 2023 15:21:47 +0600 Subject: [PATCH] potential fix of state value change in asMutableComposeState --- .../dev/inmo/micro_utils/coroutines/compose/FlowAsState.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsState.kt b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsState.kt index 334c5dcb6ea..b6d6fb12833 100644 --- a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsState.kt +++ b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsState.kt @@ -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 Flow.asMutableComposeState( scope: CoroutineScope ): MutableState { val state = mutableStateOf(initial) - subscribeSafelyWithoutExceptions(scope) { state.value = it } + subscribeSafelyWithoutExceptions(scope) { doInUI { state.value = it } } return state }