Hello folks! Quick shout out to the team for the l...
# orbit-mvi
s
Hello folks! Quick shout out to the team for the library. We are on a compose re-write in our org for our user facing app and we decided to use Orbit-MVI after much deliberation. We've been loving it so far. Quick questions to the team : 1. Will there be a support for
collectAsStateWithLifecycle
method while consuming state? This was introduced as a part of
androidx.lifecycle:lifecycle-runtime-compose:2.6.0-alpha01
.
collectAsStateWithLifecycle
uses
repeatOnLifecycle
under the hood. Reference : https://medium.com/androiddevelopers/consuming-flows-safely-in-jetpack-compose-cde014d0d5a3
👀 1
o
not a team member, but we also use orbit + compose, so end up with own extension
Copy code
/**
 * Collect [ContainerHost.container]'s state via [collectAsState] but bounded with the [flowWithLifecycle]
 */
@Composable
fun <STATE : Any, SIDE_EFFECT : Any> ContainerHost<STATE, SIDE_EFFECT>.composableState(
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED
): State<STATE> {
    val lifecycleOwner = LocalLifecycleOwner.current
    val lifecycleAwareStateFlow = remember(this, lifecycleOwner) {
        container.stateFlow.flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState)
    }
    return lifecycleAwareStateFlow.collectAsState(currentState)
}
m
Yep, there's nothing stopping you from using these APIs yourself - we expose `Flow`s on the container after all.
We'll probably update our own compose extensions to use this under the hood soon
v
@Oleksii Malovanyi I believe this is already there if you're calling
collectAsState()
https://github.com/orbit-mvi/orbit-mvi/blob/df25e1a2be166e3b1578c28f66322eb04a5624[…]in/kotlin/org/orbitmvi/orbit/compose/ContainerHostExtensions.kt Please correct me if I'm wrong 🙏
o
@Vishnu Ravi yeap, looks so! Probably, we’ve created an our own version before this appears in the repo ¯\_(ツ)_/¯
s
Should have looked into the internals a bit more. But this works. Thanks 🙂 🙏