Full work with hilt example here
First you need to add additional dependency in your android gradle file
implementation("io.github.alexgladkov:odyssey-android:1.3.61") // For android classes
All you need is just use another setup in your activity.
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val configuration = OdysseyConfiguration(this)
setHiltNavigation(configuration) {
generateGraph()
}
}
}
}
And use hiltScreen instead of screen
private fun RootComposeBuilder.generateGraph(): RootComposeBuilder {
hiltScreen(name = "one") {
HiltScreenOne()
}
hiltScreen(name = "two") {
HiltScreenTwo()
}
return this
}
Then just use hiltViewModel function as usual inside your composable function
@Composable
fun HiltScreenOne() {
val viewModel: ViewModelOne = hiltViewModel()
val rootController = LocalRootController.current
TextButton(
onClick = {
rootController.push("two")
}
) {
Text("Push")
}
NumberLabel(viewModel.randomLifecycleValue)
}