Skip to content

Instantly share code, notes, and snippets.

View LachlanMcKee's full-sized avatar

Lachlan McKee LachlanMcKee

View GitHub Profile
@LachlanMcKee
LachlanMcKee / GoogleJetpackNavigationExample.kt
Created June 3, 2021 10:07
Jetpack Compose Navigation Google example
NavHost(navController, startDestination = "profile") {
composable("profile") { Profile(...) }
composable("friendslist") { FriendsList(...) }
...
}
@LachlanMcKee
LachlanMcKee / ExampleActivity.kt
Last active June 3, 2021 10:21
Scalable Jetpack Compose Navigation
// 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()
@LachlanMcKee
LachlanMcKee / Feature1ComposeNavigationFactory.kt
Last active June 3, 2021 10:24
Scalable Jetpack Compose Navigation - With Library - Feature1ComposeNavigationFactory
// 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 / JetpackNavigationHiltApp.kt
Created June 3, 2021 10:25
Scalable Jetpack Compose Navigation - With Library - JetpackNavigationHiltApp
// 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)
}