Create a variable to declare the route concatenated with arguments

pull/156/head^2^2
ratobing 3 years ago
parent 263b5adde3
commit dec1919204

@ -36,11 +36,3 @@ interface NiaNavigationDestination {
*/
val destination: String
}
interface NiaNavigationWithArguments {
/**
* Defines the arguments on the screen, which will be combined with the screen route.
*/
val routeWithArguments: String
}

@ -21,23 +21,20 @@ import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigationDestination
import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigationWithArguments
import com.google.samples.apps.nowinandroid.feature.author.AuthorRoute
object AuthorDestination : NiaNavigationDestination, NiaNavigationWithArguments {
object AuthorDestination : NiaNavigationDestination {
override val route = "author_route"
override val destination = "author_destination"
const val authorIdArg = "authorId"
override val routeWithArguments: String
get() = route.plus("/{$authorIdArg}")
val routeWithArgs = "$route/{$authorIdArg}"
}
fun NavGraphBuilder.authorGraph(
onBackClick: () -> Unit
) {
composable(
route = AuthorDestination.routeWithArguments,
route = AuthorDestination.routeWithArgs,
arguments = listOf(
navArgument(AuthorDestination.authorIdArg) {
type = NavType.StringType

@ -21,23 +21,20 @@ import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigationDestination
import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigationWithArguments
import com.google.samples.apps.nowinandroid.feature.topic.TopicRoute
object TopicDestination : NiaNavigationDestination, NiaNavigationWithArguments {
object TopicDestination : NiaNavigationDestination {
override val route = "topic_route"
override val destination = "topic_destination"
const val topicIdArg = "topicId"
override val routeWithArguments: String
get() = route.plus("/{$topicIdArg}")
val routeWithArgs = "$route/{$topicIdArg}"
}
fun NavGraphBuilder.topicGraph(
onBackClick: () -> Unit
) {
composable(
route = TopicDestination.routeWithArguments,
route = TopicDestination.routeWithArgs,
arguments = listOf(
navArgument(TopicDestination.topicIdArg) {
type = NavType.StringType

Loading…
Cancel
Save