Skip to content

Kodein integration

Success

To use the rememberScreenModel you should first import cafe.adriel.voyager:voyager-kodein (see Setup).

Declare your ScreenModels using the bindProvider bind.

val homeModule = DI.Module(name = "home") {
    bindProvider { HomeScreenModel() } 
}

Call rememberScreenModel() to get a new instance.

class HomeScreen : Screen {

    @Composable
    override fun Content() {
        val screenModel = rememberScreenModel<HomeScreenModel>()
        // ...
    }
}

Sample

Info

Sample code here.

class HomeScreen : Screen {

    @Composable
    override fun Content() {
        val navigator = LocalNavigator.currentOrThrow
        val screenModel = navigator.rememberNavigatorScreenModel<HomeScreenModel>()
        // ...
    }
}