Create a variable to declare the route concatenated with arguments

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

@ -35,12 +35,4 @@ interface NiaNavigationDestination {
* destination's route from the route of the entire nested graph it belongs to. * destination's route from the route of the entire nested graph it belongs to.
*/ */
val destination: String 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.compose.composable
import androidx.navigation.navArgument import androidx.navigation.navArgument
import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigationDestination 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 import com.google.samples.apps.nowinandroid.feature.author.AuthorRoute
object AuthorDestination : NiaNavigationDestination, NiaNavigationWithArguments { object AuthorDestination : NiaNavigationDestination {
override val route = "author_route" override val route = "author_route"
override val destination = "author_destination" override val destination = "author_destination"
const val authorIdArg = "authorId" const val authorIdArg = "authorId"
val routeWithArgs = "$route/{$authorIdArg}"
override val routeWithArguments: String
get() = route.plus("/{$authorIdArg}")
} }
fun NavGraphBuilder.authorGraph( fun NavGraphBuilder.authorGraph(
onBackClick: () -> Unit onBackClick: () -> Unit
) { ) {
composable( composable(
route = AuthorDestination.routeWithArguments, route = AuthorDestination.routeWithArgs,
arguments = listOf( arguments = listOf(
navArgument(AuthorDestination.authorIdArg) { navArgument(AuthorDestination.authorIdArg) {
type = NavType.StringType type = NavType.StringType

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

Loading…
Cancel
Save