Skip to content

Koin integration

Success

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

Warning

Since 1.1.0-alpha04 we have rename the getScreenModel to koinScreenModel, this is a change to follow Koin Compose naming schema. The previous getScreenModel is deprecated and will be removed on 1.1.0

Declare your ScreenModels using the factory component.

val homeModule = module {
    factory { HomeScreenModel() } 
}

Call getScreenModel() to get a new instance.

class HomeScreen : Screen {

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

Sample

Info

Sample code here.

class HomeScreen : Screen {

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