1 /*
2 * Copyright (C) 2017 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 @file:JvmName("NavControllerKt")
18 @file:JvmMultifileClass
19
20 package androidx.navigation
21
22 import androidx.annotation.CallSuper
23 import androidx.annotation.MainThread
24 import androidx.annotation.RestrictTo
25 import androidx.lifecycle.LifecycleOwner
26 import androidx.lifecycle.ViewModelStore
27 import androidx.navigation.internal.NavContext
28 import androidx.savedstate.SavedState
29 import kotlin.jvm.JvmMultifileClass
30 import kotlin.jvm.JvmName
31 import kotlin.jvm.JvmOverloads
32 import kotlin.jvm.JvmStatic
33 import kotlin.jvm.JvmSuppressWildcards
34 import kotlin.reflect.KClass
35 import kotlin.reflect.KType
36 import kotlinx.coroutines.flow.Flow
37 import kotlinx.coroutines.flow.StateFlow
38 import kotlinx.serialization.InternalSerializationApi
39
40 /**
41 * NavController manages app navigation within a [NavHost].
42 *
43 * Apps will generally obtain a controller directly from a host, or by using one of the utility
44 * methods on the [Navigation] class rather than create a controller directly.
45 *
46 * Navigation flows and destinations are determined by the [navigation graph][NavGraph] owned by the
47 * controller. These graphs are typically [inflated][navInflater] from an Android resource, but,
48 * like views, they can also be constructed or combined programmatically or for the case of dynamic
49 * navigation structure. (For example, if the navigation structure of the application is determined
50 * by live data obtained' from a remote server.)
51 */
52 public expect open class NavController {
53
54 internal val navContext: NavContext
55
56 /**
57 * The topmost navigation graph associated with this NavController.
58 *
59 * When this is set any current navigation graph data (including back stack) will be replaced.
60 *
61 * @throws IllegalStateException if called before `setGraph()`.
62 * @see NavController.setGraph
63 */
64 public open var graph: NavGraph
65 @MainThread get
66 @MainThread @CallSuper set
67
68 /**
69 * This probably isn't what you actually want. If you're looking for the back stack of a
70 * particular kind of destination (e.g., all of the composables on your back stack), then you
71 * should be looking up the back stack for the particular Navigator you want, rather than this
72 * combined back stack that is going to interleave navigation graphs with the actual back stack
73 * entries you are interested in.
74 *
75 * ```
76 * val composeNavigator = navController.navigatorProvider.get(ComposeNavigator::class)
77 * composeNavigator.backStack.collect { entries ->
78 * // Use the entries
79 * }
80 * ```
81 *
82 * @return The current back stack.
83 */
84 @get:RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
85 public val currentBackStack: StateFlow<List<NavBackStackEntry>>
86
87 /**
88 * A [StateFlow] that will emit the currently visible [NavBackStackEntries][NavBackStackEntry]
89 * whenever they change. If there is no visible [NavBackStackEntry], this will be set to an
90 * empty list.
91 * - `CREATED` entries are listed first and include all entries that are in the process of
92 * completing their exit transition. Note that this can include entries that have been popped
93 * off the Navigation back stack.
94 * - `STARTED` entries on the back stack are next and include all entries that are running their
95 * enter transition and entries whose destination is partially covered by a `FloatingWindow`
96 * destination
97 * - The last entry in the list is the topmost entry in the back stack and is in the `RESUMED`
98 * state only if its enter transition has completed. Otherwise it too will be `STARTED`.
99 *
100 * Note that the `Lifecycle` of any entry cannot be higher than the containing
101 * Activity/Fragment - if the Activity is not `RESUMED`, no entry will be `RESUMED`, no matter
102 * what the transition state is.
103 */
104 public val visibleEntries: StateFlow<List<NavBackStackEntry>>
105
106 /**
107 * OnDestinationChangedListener receives a callback when the [currentDestination] or its
108 * arguments change.
109 */
110 public fun interface OnDestinationChangedListener {
111 /**
112 * Callback for when the [currentDestination] or its arguments change. This navigation may
113 * be to a destination that has not been seen before, or one that was previously on the back
114 * stack. This method is called after navigation is complete, but associated transitions may
115 * still be playing.
116 *
117 * @param controller the controller that navigated
118 * @param destination the new destination
119 * @param arguments the arguments passed to the destination
120 */
onDestinationChangednull121 public fun onDestinationChanged(
122 controller: NavController,
123 destination: NavDestination,
124 arguments: SavedState?
125 )
126 }
127
128 @set:RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
129 /**
130 * The NavController's [NavigatorProvider]. All [Navigators][Navigator] used to construct the
131 * [navigation graph][NavGraph] for this nav controller should be added to this navigator
132 * provider before the graph is constructed.
133 *
134 * This can only be set before the graph is set via `setGraph()`.
135 *
136 * Generally, the Navigators are set for you by the [NavHost] hosting this NavController and you
137 * do not need to manually interact with the navigator provider.
138 *
139 * @throws IllegalStateException If this set called after `setGraph()`
140 */
141 public open var navigatorProvider: NavigatorProvider
142
143 /**
144 * Adds an [OnDestinationChangedListener] to this controller to receive a callback whenever the
145 * [currentDestination] or its arguments change.
146 *
147 * The current destination, if any, will be immediately sent to your listener.
148 *
149 * @param listener the listener to receive events
150 */
151 public open fun addOnDestinationChangedListener(listener: OnDestinationChangedListener)
152
153 /**
154 * Removes an [OnDestinationChangedListener] from this controller. It will no longer receive
155 * callbacks.
156 *
157 * @param listener the listener to remove
158 */
159 public open fun removeOnDestinationChangedListener(listener: OnDestinationChangedListener)
160
161 /**
162 * Attempts to pop the controller's back stack. Analogous to when the user presses the system
163 * [Back][android.view.KeyEvent.KEYCODE_BACK] button when the associated navigation host has
164 * focus.
165 *
166 * @return true if the stack was popped at least once and the user has been navigated to another
167 * destination, false otherwise
168 */
169 @MainThread public open fun popBackStack(): Boolean
170
171 /**
172 * Attempts to pop the controller's back stack back to a specific destination.
173 *
174 * @param route The topmost destination to retain. May contain filled in arguments as long as it
175 * is exact match with route used to navigate.
176 * @param inclusive Whether the given destination should also be popped.
177 * @param saveState Whether the back stack and the state of all destinations between the current
178 * destination and the [route] should be saved for later restoration via
179 * [NavOptions.Builder.setRestoreState] or the `restoreState` attribute using the same [route]
180 * (note: this matching ID is true whether [inclusive] is true or false).
181 * @return true if the stack was popped at least once and the user has been navigated to another
182 * destination, false otherwise
183 */
184 @MainThread
185 @JvmOverloads
186 public fun popBackStack(route: String, inclusive: Boolean, saveState: Boolean = false): Boolean
187
188 /**
189 * Attempts to pop the controller's back stack back to a specific destination.
190 *
191 * @param T The topmost destination to retain with route from a [KClass]. The target
192 * NavDestination must have been created with route from [KClass].
193 * @param inclusive Whether the given destination should also be popped.
194 * @param saveState Whether the back stack and the state of all destinations between the current
195 * destination and [T] should be saved for later restoration via
196 * [NavOptions.Builder.setRestoreState] or the `restoreState` attribute using the same [T]
197 * (note: this matching ID is true whether [inclusive] is true or false).
198 * @return true if the stack was popped at least once and the user has been navigated to another
199 * destination, false otherwise
200 */
201 @MainThread
202 @JvmOverloads
203 public inline fun <reified T : Any> popBackStack(
204 inclusive: Boolean,
205 saveState: Boolean = false
206 ): Boolean
207
208 /**
209 * Attempts to pop the controller's back stack back to a specific destination.
210 *
211 * @param route The topmost destination to retain with route from a [KClass]. The target
212 * NavDestination must have been created with route from [KClass].
213 * @param inclusive Whether the given destination should also be popped.
214 * @param saveState Whether the back stack and the state of all destinations between the current
215 * destination and [route] should be saved for later restoration via
216 * [NavOptions.Builder.setRestoreState] or the `restoreState` attribute using the same [T]
217 * (note: this matching ID is true whether [inclusive] is true or false).
218 * @return true if the stack was popped at least once and the user has been navigated to another
219 * destination, false otherwise
220 */
221 @MainThread
222 @JvmOverloads
223 public fun <T : Any> popBackStack(
224 route: KClass<T>,
225 inclusive: Boolean,
226 saveState: Boolean = false
227 ): Boolean
228
229 /**
230 * Attempts to pop the controller's back stack back to a specific destination.
231 *
232 * @param route The topmost destination to retain with route from an Object. The target
233 * NavDestination must have been created with route from [KClass].
234 * @param inclusive Whether the given destination should also be popped.
235 * @param saveState Whether the back stack and the state of all destinations between the current
236 * destination and the [route] should be saved for later restoration via
237 * [NavOptions.Builder.setRestoreState] or the `restoreState` attribute using the same [route]
238 * (note: this matching ID is true whether [inclusive] is true or false).
239 * @return true if the stack was popped at least once and the user has been navigated to another
240 * destination, false otherwise
241 */
242 @MainThread
243 @JvmOverloads
244 public fun <T : Any> popBackStack(
245 route: T,
246 inclusive: Boolean,
247 saveState: Boolean = false
248 ): Boolean
249
250 /**
251 * Clears any saved state associated with [route] that was previously saved via [popBackStack]
252 * when using a `saveState` value of `true`.
253 *
254 * @param route The route of the destination previously used with [popBackStack] with a
255 * `saveState` value of `true`. May contain filled in arguments as long as it is exact match
256 * with route used with [popBackStack].
257 * @return true if the saved state of the stack associated with [route] was cleared.
258 */
259 @MainThread public fun clearBackStack(route: String): Boolean
260
261 /**
262 * Clears any saved state associated with KClass [T] that was previously saved via
263 * [popBackStack] when using a `saveState` value of `true`.
264 *
265 * @param T The route from the [KClass] of the destination previously used with [popBackStack]
266 * with a `saveState`value of `true`. The target NavDestination must have been created with
267 * route from [KClass].
268 * @return true if the saved state of the stack associated with [T] was cleared.
269 */
270 @MainThread public inline fun <reified T : Any> clearBackStack(): Boolean
271
272 /**
273 * Clears any saved state associated with KClass [route] that was previously saved via
274 * [popBackStack] when using a `saveState` value of `true`.
275 *
276 * @param route The route from the [KClass] of the destination previously used with
277 * [popBackStack] with a `saveState`value of `true`. The target NavDestination must have been
278 * created with route from [KClass].
279 * @return true if the saved state of the stack associated with [route] was cleared.
280 */
281 @MainThread public fun <T : Any> clearBackStack(route: KClass<T>): Boolean
282
283 /**
284 * Clears any saved state associated with KClass [T] that was previously saved via
285 * [popBackStack] when using a `saveState` value of `true`.
286 *
287 * @param route The route from an Object of the destination previously used with [popBackStack]
288 * with a `saveState`value of `true`. The target NavDestination must have been created with
289 * route from [KClass].
290 * @return true if the saved state of the stack associated with [T] was cleared.
291 */
292 @MainThread public fun <T : Any> clearBackStack(route: T): Boolean
293
294 /**
295 * Attempts to navigate up in the navigation hierarchy. Suitable for when the user presses the
296 * "Up" button marked with a left (or start)-facing arrow in the upper left (or starting) corner
297 * of the app UI.
298 *
299 * The intended behavior of Up differs from [Back][popBackStack] when the user did not reach the
300 * current destination from the application's own task. e.g. if the user is viewing a document
301 * or link in the current app in an activity hosted on another app's task where the user clicked
302 * the link. In this case the current activity (determined by the context used to create this
303 * NavController) will be [finished][Activity.finish] and the user will be taken to an
304 * appropriate destination in this app on its own task.
305 *
306 * @return true if navigation was successful, false otherwise
307 */
308 @MainThread public open fun navigateUp(): Boolean
309
310 /**
311 * Sets the [navigation graph][NavGraph] to the specified graph. Any current navigation graph
312 * data (including back stack) will be replaced.
313 *
314 * The graph can be retrieved later via [graph].
315 *
316 * @param graph graph to set
317 * @param startDestinationArgs arguments to send to the start destination of the graph
318 * @see NavController.setGraph
319 * @see NavController.graph
320 */
321 @MainThread
322 @CallSuper
323 public open fun setGraph(graph: NavGraph, startDestinationArgs: SavedState?)
324
325 internal fun checkDeepLinkHandled(): Boolean
326
327 /**
328 * Checks the given NavDeepLinkRequest for a Navigation deep link and navigates to the
329 * destination if present.
330 *
331 * The [navigation graph][graph] should be set before calling this method.
332 *
333 * @param request The request that contains a valid deep link, an action or a mimeType.
334 * @return True if the navigation controller found a valid deep link and navigated to it.
335 * @throws IllegalStateException if deep link cannot be accessed from the current destination
336 * @see NavDestination.addDeepLink
337 */
338 @MainThread public fun handleDeepLink(request: NavDeepLinkRequest): Boolean
339
340 /** The current destination. */
341 public open val currentDestination: NavDestination?
342
343 /** Recursively searches through parents */
344 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
345 public fun findDestination(route: String): NavDestination?
346
347 /**
348 * Navigate to a destination via the given deep link [Uri]. [NavDestination.hasDeepLink] should
349 * be called on [the navigation graph][graph] prior to calling this method to check if the deep
350 * link is valid. If an invalid deep link is given, an [IllegalArgumentException] will be
351 * thrown.
352 *
353 * @param deepLink deepLink to the destination reachable from the current NavGraph
354 * @see NavController.navigate
355 */
356 @MainThread public open fun navigate(deepLink: NavUri)
357
358 /**
359 * Navigate to a destination via the given deep link [Uri]. [NavDestination.hasDeepLink] should
360 * be called on [the navigation graph][graph] prior to calling this method to check if the deep
361 * link is valid. If an invalid deep link is given, an [IllegalArgumentException] will be
362 * thrown.
363 *
364 * @param deepLink deepLink to the destination reachable from the current NavGraph
365 * @param navOptions special options for this navigation operation
366 * @see NavController.navigate
367 */
368 @MainThread public open fun navigate(deepLink: NavUri, navOptions: NavOptions?)
369
370 /**
371 * Navigate to a destination via the given deep link [Uri]. [NavDestination.hasDeepLink] should
372 * be called on [the navigation graph][graph] prior to calling this method to check if the deep
373 * link is valid. If an invalid deep link is given, an [IllegalArgumentException] will be
374 * thrown.
375 *
376 * @param deepLink deepLink to the destination reachable from the current NavGraph
377 * @param navOptions special options for this navigation operation
378 * @param navigatorExtras extras to pass to the Navigator
379 * @see NavController.navigate
380 */
381 @MainThread
382 public open fun navigate(
383 deepLink: NavUri,
384 navOptions: NavOptions?,
385 navigatorExtras: Navigator.Extras?
386 )
387
388 /**
389 * Navigate to a destination via the given [NavDeepLinkRequest]. [NavDestination.hasDeepLink]
390 * should be called on [the navigation graph][graph] prior to calling this method to check if
391 * the deep link is valid. If an invalid deep link is given, an [IllegalArgumentException] will
392 * be thrown.
393 *
394 * @param request deepLinkRequest to the destination reachable from the current NavGraph
395 * @throws IllegalArgumentException if the given deep link request is invalid
396 */
397 @MainThread public open fun navigate(request: NavDeepLinkRequest)
398
399 /**
400 * Navigate to a destination via the given [NavDeepLinkRequest]. [NavDestination.hasDeepLink]
401 * should be called on [the navigation graph][graph] prior to calling this method to check if
402 * the deep link is valid. If an invalid deep link is given, an [IllegalArgumentException] will
403 * be thrown.
404 *
405 * @param request deepLinkRequest to the destination reachable from the current NavGraph
406 * @param navOptions special options for this navigation operation
407 * @throws IllegalArgumentException if the given deep link request is invalid
408 */
409 @MainThread public open fun navigate(request: NavDeepLinkRequest, navOptions: NavOptions?)
410
411 /**
412 * Navigate to a destination via the given [NavDeepLinkRequest]. [NavDestination.hasDeepLink]
413 * should be called on [the navigation graph][graph] prior to calling this method to check if
414 * the deep link is valid. If an invalid deep link is given, an [IllegalArgumentException] will
415 * be thrown.
416 *
417 * @param request deepLinkRequest to the destination reachable from the current NavGraph
418 * @param navOptions special options for this navigation operation
419 * @param navigatorExtras extras to pass to the Navigator
420 * @throws IllegalArgumentException if the given deep link request is invalid
421 */
422 @MainThread
423 public open fun navigate(
424 request: NavDeepLinkRequest,
425 navOptions: NavOptions?,
426 navigatorExtras: Navigator.Extras?
427 )
428
429 internal fun writeIntent(request: NavDeepLinkRequest, args: SavedState)
430
431 /**
432 * Navigate to a route in the current NavGraph. If an invalid route is given, an
433 * [IllegalArgumentException] will be thrown.
434 *
435 * If given [NavOptions] pass in [NavOptions.restoreState] `true`, any args passed here as part
436 * of the route will be overridden by the restored args.
437 *
438 * @param route route for the destination
439 * @param builder DSL for constructing a new [NavOptions]
440 * @throws IllegalArgumentException if the given route is invalid
441 */
442 @MainThread public fun navigate(route: String, builder: NavOptionsBuilder.() -> Unit)
443
444 /**
445 * Navigate to a route in the current NavGraph. If an invalid route is given, an
446 * [IllegalArgumentException] will be thrown.
447 *
448 * If given [NavOptions] pass in [NavOptions.restoreState] `true`, any args passed here as part
449 * of the route will be overridden by the restored args.
450 *
451 * @param route route for the destination
452 * @param navOptions special options for this navigation operation
453 * @param navigatorExtras extras to pass to the [Navigator]
454 * @throws IllegalArgumentException if the given route is invalid
455 */
456 @MainThread
457 @JvmOverloads
458 public fun navigate(
459 route: String,
460 navOptions: NavOptions? = null,
461 navigatorExtras: Navigator.Extras? = null
462 )
463
464 /**
465 * Navigate to a route from an Object in the current NavGraph. If an invalid route is given, an
466 * [IllegalArgumentException] will be thrown.
467 *
468 * The target NavDestination must have been created with route from a [KClass]
469 *
470 * If given [NavOptions] pass in [NavOptions.restoreState] `true`, any args passed here as part
471 * of the route will be overridden by the restored args.
472 *
473 * @param route route from an Object for the destination
474 * @param builder DSL for constructing a new [NavOptions]
475 * @throws IllegalArgumentException if the given route is invalid
476 */
477 @MainThread public fun <T : Any> navigate(route: T, builder: NavOptionsBuilder.() -> Unit)
478
479 /**
480 * Navigate to a route from an Object in the current NavGraph. If an invalid route is given, an
481 * [IllegalArgumentException] will be thrown.
482 *
483 * The target NavDestination must have been created with route from a [KClass]
484 *
485 * If given [NavOptions] pass in [NavOptions.restoreState] `true`, any args passed here as part
486 * of the route will be overridden by the restored args.
487 *
488 * @param route route from an Object for the destination
489 * @param navOptions special options for this navigation operation
490 * @param navigatorExtras extras to pass to the [Navigator]
491 * @throws IllegalArgumentException if the given route is invalid
492 */
493 @MainThread
494 @JvmOverloads
495 public fun <T : Any> navigate(
496 route: T,
497 navOptions: NavOptions? = null,
498 navigatorExtras: Navigator.Extras? = null
499 )
500
501 /**
502 * Saves all navigation controller state to a SavedState.
503 *
504 * State may be restored from a SavedState returned from this method by calling [restoreState].
505 * Saving controller state is the responsibility of a [NavHost].
506 *
507 * @return saved state for this controller
508 */
509 @CallSuper public open fun saveState(): SavedState?
510
511 /**
512 * Restores all navigation controller state from a SavedState. This should be called before any
513 * call to [setGraph].
514 *
515 * State may be saved to a SavedState by calling [saveState]. Restoring controller state is the
516 * responsibility of a [NavHost].
517 *
518 * @param navState SavedState to restore
519 */
520 @CallSuper public open fun restoreState(navState: SavedState?)
521
522 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
523 public open fun setLifecycleOwner(owner: LifecycleOwner)
524
525 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
526 public open fun setViewModelStore(viewModelStore: ViewModelStore)
527
528 /**
529 * Gets the topmost [NavBackStackEntry] for a route.
530 *
531 * This is always safe to use with [the current destination][currentDestination] or
532 * [its parent][NavDestination.parent] or grandparent navigation graphs as these destinations
533 * are guaranteed to be on the back stack.
534 *
535 * @param route route of a destination that exists on the back stack. May contain filled in
536 * arguments as long as it is exact match with route used to navigate.
537 * @throws IllegalArgumentException if the destination is not on the back stack
538 */
539 public fun getBackStackEntry(route: String): NavBackStackEntry
540
541 /**
542 * Gets the topmost [NavBackStackEntry] for a route from [KClass].
543 *
544 * This is always safe to use with [the current destination][currentDestination] or
545 * [its parent][NavDestination.parent] or grandparent navigation graphs as these destinations
546 * are guaranteed to be on the back stack.
547 *
548 * @param T route from the [KClass] of a destination that exists on the back stack. The target
549 * NavBackStackEntry's [NavDestination] must have been created with route from [KClass].
550 * @throws IllegalArgumentException if the destination is not on the back stack
551 */
552 public inline fun <reified T : Any> getBackStackEntry(): NavBackStackEntry
553
554 /**
555 * Gets the topmost [NavBackStackEntry] for a [route] from [KClass].
556 *
557 * This is always safe to use with [the current destination][currentDestination] or
558 * [its parent][NavDestination.parent] or grandparent navigation graphs as these destinations
559 * are guaranteed to be on the back stack.
560 *
561 * @param route route from the [KClass] of destination [T] that exists on the back stack. The
562 * target NavBackStackEntry's [NavDestination] must have been created with route from
563 * [KClass].
564 * @throws IllegalArgumentException if the destination is not on the back stack
565 */
566 @OptIn(InternalSerializationApi::class)
567 public fun <T : Any> getBackStackEntry(route: KClass<T>): NavBackStackEntry
568
569 /**
570 * Gets the topmost [NavBackStackEntry] for a route from an Object.
571 *
572 * This is always safe to use with [the current destination][currentDestination] or
573 * [its parent][NavDestination.parent] or grandparent navigation graphs as these destinations
574 * are guaranteed to be on the back stack.
575 *
576 * @param route route from an Object of a destination that exists on the back stack. The target
577 * NavBackStackEntry's [NavDestination] must have been created with route from [KClass].
578 * @throws IllegalArgumentException if the destination is not on the back stack
579 */
580 public fun <T : Any> getBackStackEntry(route: T): NavBackStackEntry
581
582 /**
583 * The topmost [NavBackStackEntry].
584 *
585 * @return the topmost entry on the back stack or null if the back stack is empty
586 */
587 public open val currentBackStackEntry: NavBackStackEntry?
588
589 /**
590 * A [Flow] that will emit the currently active [NavBackStackEntry] whenever it changes. If
591 * there is no active [NavBackStackEntry], no item will be emitted.
592 */
593 public val currentBackStackEntryFlow: Flow<NavBackStackEntry>
594
595 /**
596 * The previous visible [NavBackStackEntry].
597 *
598 * This skips over any [NavBackStackEntry] that is associated with a [NavGraph].
599 *
600 * @return the previous visible entry on the back stack or null if the back stack has less than
601 * two visible entries
602 */
603 public open val previousBackStackEntry: NavBackStackEntry?
604
605 internal open inner class NavControllerNavigatorState(
606 navigator: Navigator<out NavDestination>
607 ) : NavigatorState {
608 val navigator: Navigator<out NavDestination>
609
610 override fun push(backStackEntry: NavBackStackEntry)
611
612 override fun pop(popUpTo: NavBackStackEntry, saveState: Boolean)
613
614 override fun popWithTransition(popUpTo: NavBackStackEntry, saveState: Boolean)
615
616 fun addInternal(backStackEntry: NavBackStackEntry)
617
618 override fun createBackStackEntry(
619 destination: NavDestination,
620 arguments: SavedState?
621 ): NavBackStackEntry
622
623 override fun prepareForTransition(entry: NavBackStackEntry)
624
625 override fun markTransitionComplete(entry: NavBackStackEntry)
626 }
627
createNavControllerNavigatorStatenull628 internal fun createNavControllerNavigatorState(
629 navigator: Navigator<out NavDestination>
630 ): NavControllerNavigatorState
631
632 public companion object {
633 /**
634 * By default, [handleDeepLink] will automatically add calls to
635 * [NavOptions.Builder.setPopUpTo] with a `saveState` of `true` when the deep link takes you
636 * to another graph (e.g., a different navigation graph than the one your start destination
637 * is in).
638 *
639 * You can disable this behavior by passing `false` for [saveState].
640 */
641 @JvmStatic
642 @NavDeepLinkSaveStateControl
643 public fun enableDeepLinkSaveState(saveState: Boolean)
644 }
645 }
646
647 /**
648 * Construct a new [NavGraph]
649 *
650 * @param startDestination the route for the start destination
651 * @param route the route for the graph
652 * @param builder the builder used to construct the graph
653 */
createGraphnull654 public inline fun NavController.createGraph(
655 startDestination: String,
656 route: String? = null,
657 builder: NavGraphBuilder.() -> Unit
658 ): NavGraph = navigatorProvider.navigation(startDestination, route, builder)
659
660 /**
661 * Construct a new [NavGraph]
662 *
663 * @param startDestination the starting destination's route from a [KClass] for this NavGraph. The
664 * respective NavDestination must be added as a [KClass] in order to match.
665 * @param route the graph's unique route from a [KClass]
666 * @param typeMap A mapping of KType to custom NavType<*> in the [route]. May be empty if [route]
667 * does not use custom NavTypes.
668 * @param builder the builder used to construct the graph
669 */
670 public inline fun NavController.createGraph(
671 startDestination: KClass<*>,
672 route: KClass<*>? = null,
673 typeMap: Map<KType, @JvmSuppressWildcards NavType<*>> = emptyMap(),
674 builder: NavGraphBuilder.() -> Unit
675 ): NavGraph = navigatorProvider.navigation(startDestination, route, typeMap, builder)
676
677 /**
678 * Construct a new [NavGraph]
679 *
680 * @param startDestination the starting destination's route from an Object for this NavGraph. The
681 * respective NavDestination must be added as a [KClass] in order to match.
682 * @param route the graph's unique route from a [KClass]
683 * @param typeMap A mapping of KType to custom NavType<*> in the [route]. May be empty if [route]
684 * does not use custom NavTypes.
685 * @param builder the builder used to construct the graph
686 */
687 public inline fun NavController.createGraph(
688 startDestination: Any,
689 route: KClass<*>? = null,
690 typeMap: Map<KType, @JvmSuppressWildcards NavType<*>> = emptyMap(),
691 builder: NavGraphBuilder.() -> Unit
692 ): NavGraph = navigatorProvider.navigation(startDestination, route, typeMap, builder)
693