-
-
Save KaustubhPatange/1c061aa304ff91330f78b227d8fb43c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Create ViewModels & destinations | |
class SecondViewModel : ViewModel() { ... } | |
class FirstScreen : AndroidScreen() { | |
@Composable override fun Content() = FirstScreenContent() | |
} | |
class SecondScreen(private val name: String) : AndroidScreen() { | |
@Composable override fun Content() = SecondScreenContent() | |
} | |
// 2. Setup Navigation, | |
@Composable | |
fun MainScreen() { | |
Navigator(FirstScreen()) | |
} | |
// Content for First Screen | |
@Composable | |
fun FirstScreenContent() { | |
val navigator = LocalNavigator.currentOrThrow | |
Button(onClick = { | |
navigator.push(SecondScreen(name = "Test")) // <-- Navigating to Second screen | |
}) { | |
// ... | |
} | |
} | |
// Content for Second Screen | |
@Composable | |
fun SecondScreenContent() { | |
val vm = getViewModel<DemoViewModel>() // <-- Support ViewModels injected through Hilt | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment