-
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.
[#352] Setup the nav graph and navigation logic on Sample Compose pro…
…ject
- Loading branch information
Showing
32 changed files
with
256 additions
and
572 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
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.
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
package co.nimblehq.sample.compose.ui | ||
|
||
import androidx.navigation.* | ||
|
||
const val KEY_ID = "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") | ||
|
||
/** | ||
* We can define route as "coin/details" without "coinId" parameter because we're passing it as argument already. | ||
* So either passing "coinId" via arguments or passing it via route. | ||
* | ||
* We keep passing "coinId" in both route and arguments for this destination to give example of navigation concept | ||
* about how to build a destination with parameters. | ||
*/ | ||
object Second : AppDestination("second/{$KEY_ID}") { | ||
|
||
override val arguments = listOf( | ||
navArgument(KEY_ID) { 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) { | ||
SecondScreen( | ||
navigator = { destination -> navController.navigate(destination) }, | ||
id = it.arguments?.getString(KEY_ID).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(destination: AppDestination) { | ||
when (destination) { | ||
is AppDestination.Up -> popBackStack() | ||
else -> navigate(route = destination.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.