Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use stateIn operator inside ScreenModel #14

Closed
xinkev opened this issue Oct 5, 2021 · 1 comment
Closed

Cannot use stateIn operator inside ScreenModel #14

xinkev opened this issue Oct 5, 2021 · 1 comment

Comments

@xinkev
Copy link

xinkev commented Oct 5, 2021

Using stateIn operator inside ScreenModel using built-in coroutineScope cause a crash with java.lang.IllegalStateException: ScreenModel not found. However, this exception doesn't happen if self-created Coroutine scope is used.
Example code,

class TestScreen : Screen {
    @Composable
    override fun Content() {
        val sm = rememberScreenModel { TestScreenModel() }
        val msg by sm.msg.collectAsState()
        Text(msg)
    }
}

class TestScreenModel : ScreenModel {
    val msg = msgFlow.stateIn(coroutineScope, SharingStarted.Lazily, "")
}

val msgFlow = listOf("Hello", "world!").asFlow()
@adrielcafe
Copy link
Owner

Fixed in 1.0.0-beta12. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants