1 /*
<lambda>null2 * Copyright 2024 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 * https://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.compose.material.navigation
18
19 import androidx.compose.foundation.layout.ColumnScope
20 import androidx.compose.runtime.Composable
21 import androidx.compose.ui.util.fastForEach
22 import androidx.navigation.NamedNavArgument
23 import androidx.navigation.NavBackStackEntry
24 import androidx.navigation.NavDeepLink
25 import androidx.navigation.NavGraphBuilder
26 import androidx.navigation.NavType
27 import androidx.navigation.get
28 import kotlin.reflect.KClass
29 import kotlin.reflect.KType
30
31 /**
32 * Add the [content] [Composable] as bottom sheet content to the [NavGraphBuilder]
33 *
34 * @sample androidx.compose.material.navigation.samples.BottomSheetNavDemo
35 * @param route route for the destination
36 * @param arguments list of arguments to associate with destination
37 * @param deepLinks list of deep links to associate with the destinations
38 * @param content the sheet content at the given destination
39 */
40 public fun NavGraphBuilder.bottomSheet(
41 route: String,
42 arguments: List<NamedNavArgument> = emptyList(),
43 deepLinks: List<NavDeepLink> = emptyList(),
44 content: @Composable ColumnScope.(backstackEntry: NavBackStackEntry) -> Unit
45 ) {
46 destination(
47 BottomSheetNavigatorDestinationBuilder(
48 provider[BottomSheetNavigator::class],
49 route,
50 content
51 )
52 .apply {
53 arguments.fastForEach { (argumentName, argument) ->
54 argument(argumentName, argument)
55 }
56 deepLinks.fastForEach { deepLink -> deepLink(deepLink) }
57 }
58 )
59 }
60
61 /**
62 * Add the [content] [Composable] as bottom sheet content to the [NavGraphBuilder]
63 *
64 * @sample androidx.compose.material.navigation.samples.BottomSheetNavDemo
65 * @param T route from a [KClass] for the destination
66 * @param typeMap map of destination arguments' kotlin type [KType] to its respective custom
67 * [NavType]. May be empty if [T] does not use custom NavTypes.
68 * @param arguments list of arguments to associate with destination
69 * @param deepLinks list of deep links to associate with the destinations
70 * @param content the sheet content at the given destination
71 */
bottomSheetnull72 public inline fun <reified T : Any> NavGraphBuilder.bottomSheet(
73 typeMap: Map<KType, @JvmSuppressWildcards NavType<*>> = emptyMap(),
74 arguments: List<NamedNavArgument> = emptyList(),
75 deepLinks: List<NavDeepLink> = emptyList(),
76 noinline content: @Composable ColumnScope.(backstackEntry: NavBackStackEntry) -> Unit
77 ) {
78 bottomSheet(T::class, typeMap, arguments, deepLinks, content)
79 }
80
81 @PublishedApi
bottomSheetnull82 internal fun NavGraphBuilder.bottomSheet(
83 route: KClass<*>,
84 typeMap: Map<KType, @JvmSuppressWildcards NavType<*>>,
85 arguments: List<NamedNavArgument>,
86 deepLinks: List<NavDeepLink> = emptyList(),
87 content: @Composable ColumnScope.(backstackEntry: NavBackStackEntry) -> Unit
88 ) {
89 destination(
90 BottomSheetNavigatorDestinationBuilder(
91 provider[BottomSheetNavigator::class],
92 route,
93 typeMap,
94 content
95 )
96 .apply {
97 arguments.fastForEach { (argumentName, argument) ->
98 argument(argumentName, argument)
99 }
100 deepLinks.fastForEach { deepLink -> deepLink(deepLink) }
101 }
102 )
103 }
104