-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from nimblehq/feature/352-set-up-nav-graph-an…
…d-navigation-logic [#352] [Sample] 1/2: Setup the nav graph and navigation logic
- Loading branch information
Showing
36 changed files
with
188 additions
and
593 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
sample-compose/app/src/debug/java/co/nimblehq/sample/compose/EmptyHiltActivity.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
sample-compose/app/src/main/java/co/nimblehq/sample/compose/di/modules/NavigatorModule.kt
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
sample-compose/app/src/main/java/co/nimblehq/sample/compose/extension/ViewModelExt.kt
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/AppDestination.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package co.nimblehq.sample.compose.ui | ||
|
||
import androidx.navigation.* | ||
|
||
const val KeyId = "id" | ||
|
||
sealed class AppDestination(val route: String = "") { | ||
|
||
open val arguments: List<NamedNavArgument> = emptyList() | ||
|
||
open var destination: String = route | ||
|
||
object Up : AppDestination() | ||
|
||
object Home : AppDestination("home") | ||
|
||
object Second : AppDestination("second/{$KeyId}") { | ||
|
||
override val arguments = listOf( | ||
navArgument(KeyId) { type = NavType.StringType } | ||
) | ||
|
||
fun buildDestination(id: String) = apply { | ||
destination = "second/$id" | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/AppNavigation.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package co.nimblehq.sample.compose.ui | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.navigation.* | ||
import androidx.navigation.compose.* | ||
import co.nimblehq.sample.compose.ui.screens.home.HomeComposeScreen | ||
import co.nimblehq.sample.compose.ui.screens.second.SecondScreen | ||
|
||
@Composable | ||
fun AppNavigation( | ||
navController: NavHostController = rememberNavController(), | ||
startDestination: String = AppDestination.Home.destination | ||
) { | ||
NavHost( | ||
navController = navController, | ||
startDestination = startDestination | ||
) { | ||
composable(AppDestination.Home) { | ||
HomeComposeScreen( | ||
navigator = { destination -> navController.navigate(destination) } | ||
) | ||
} | ||
|
||
composable(AppDestination.Second) { backStackEntry -> | ||
SecondScreen( | ||
navigator = { destination -> navController.navigate(destination) }, | ||
id = backStackEntry.arguments?.getString(KeyId).orEmpty() | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun NavGraphBuilder.composable( | ||
destination: AppDestination, | ||
deepLinks: List<NavDeepLink> = emptyList(), | ||
content: @Composable (NavBackStackEntry) -> Unit | ||
) { | ||
composable( | ||
route = destination.route, | ||
arguments = destination.arguments, | ||
deepLinks = deepLinks, | ||
content = content | ||
) | ||
} | ||
|
||
private fun NavHostController.navigate(appDestination: AppDestination) { | ||
when (appDestination) { | ||
is AppDestination.Up -> navigateUp() | ||
else -> navigate(route = appDestination.destination) | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseActivity.kt
This file was deleted.
Oops, something went wrong.
65 changes: 0 additions & 65 deletions
65
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseComposeFragment.kt
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
...pose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseComposeFragmentCallbacks.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.