Skip to content

Koin integration

Success

To use the koinScreenModel you should first import io.github.hristogochev:vortex-koin (see Setup).

Declare your ScreenModels using the factory component.

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

Call koinScreenModel() or koinNavigatorScreenModel() to get a new instance.

class HomeScreen : Screen {

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

You can find source code for a working example here.