Skip to content

Instantly share code, notes, and snippets.

Avatar

Lachlan McKee LachlanMcKee

View GitHub Profile
@LachlanMcKee
LachlanMcKee / JetpackNavigationHiltApp.kt
Created Jun 3, 2021
Scalable Jetpack Compose Navigation - With Library - JetpackNavigationHiltApp
View JetpackNavigationHiltApp.kt
// Potentially defined within the app module
@Composable
fun JetpackNavigationHiltApp() {
val navController = rememberNavController()
val context = LocalContext.current
// The start destination would still need to be known at this point.
NavHost(navController, startDestination = "feature1") {
hiltNavGraphNavigationFactories(context).addNavigation(this, navController)
}
@LachlanMcKee
LachlanMcKee / GoogleJetpackNavigationExample.kt
Created Jun 3, 2021
Jetpack Compose Navigation Google example
View GoogleJetpackNavigationExample.kt
NavHost(navController, startDestination = "profile") {
composable("profile") { Profile(...) }
composable("friendslist") { FriendsList(...) }
...
}
@LachlanMcKee
LachlanMcKee / Feature1ComposeNavigationFactory.kt
Last active Jun 3, 2021
Scalable Jetpack Compose Navigation - With Library - Feature1ComposeNavigationFactory
View Feature1ComposeNavigationFactory.kt
// Defined within the feature module
@HiltComposeNavigationFactory
internal class Feature1ComposeNavigationFactory @Inject constructor() : ComposeNavigationFactory {
override fun create(builder: NavGraphBuilder, navController: NavHostController) {
builder.composable(
route = "feature1",
content = {
Feature1(
navController = navController
)
@LachlanMcKee
LachlanMcKee / ExampleActivity.kt
Last active Jun 3, 2021
Scalable Jetpack Compose Navigation
View ExampleActivity.kt
// An example of a set of factories being used to construct a NavHost.
// Potentially defined within the app module
@AndroidEntryPoint
class ExampleActivity: AppCompatActivity {
@Inject
lateinit var composeNavigationFactories: @JvmSuppressWildcards Set<ComposeNavigationFactory>
@Composable
fun JetpackNavigationHiltApp() {
val navController = rememberNavController()