1 /*
<lambda>null2  * Copyright 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.wear.compose.navigation
18 
19 import androidx.compose.runtime.Composable
20 import androidx.navigation.NamedNavArgument
21 import androidx.navigation.NavBackStackEntry
22 import androidx.navigation.NavDeepLink
23 import androidx.navigation.NavGraphBuilder
24 import androidx.navigation.get
25 
26 /**
27  * Utility function for building Wear Compose navigation graphs.
28  *
29  * Adds the content composable to the [NavGraphBuilder] as a [WearNavigator.Destination].
30  *
31  * @param route route for the destination
32  * @param arguments list of arguments to associate with destination
33  * @param deepLinks list of deep links to associate with the destinations
34  * @param content composable for the destination
35  */
36 public fun NavGraphBuilder.composable(
37     route: String,
38     arguments: List<NamedNavArgument> = emptyList(),
39     deepLinks: List<NavDeepLink> = emptyList(),
40     content: @Composable (NavBackStackEntry) -> Unit
41 ) {
42     addDestination(
43         WearNavigator.Destination(provider[WearNavigator::class], content).apply {
44             this.route = route
45             arguments.forEach { (argumentName, argument) -> addArgument(argumentName, argument) }
46             deepLinks.forEach { deepLink -> addDeepLink(deepLink) }
47         }
48     )
49 }
50