• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * 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  *      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 com.android.photopicker.core.navigation
18 
19 import androidx.compose.animation.AnimatedContentTransitionScope
20 import androidx.compose.animation.EnterTransition
21 import androidx.compose.animation.ExitTransition
22 import androidx.compose.runtime.Composable
23 import androidx.compose.ui.window.DialogProperties
24 import androidx.navigation.NamedNavArgument
25 import androidx.navigation.NavBackStackEntry
26 import androidx.navigation.NavDeepLink
27 
28 /** A definition of a navigable route inside of the Photopicker navigation graph. */
29 interface Route {
30 
31     /**
32      * The id of the route. This should be unique to the application, and should in most cases be an
33      * [PhotopickerDestinations] enum to prevent collisions.
34      *
35      * UI elements will use this string to tell the [NavController] to navigate to this route.
36      */
37     val route: String
38 
39     /**
40      * The priority with which the application should consider this route as the initial route to
41      * use on application start. The highest priority is chosen at application start up, and then
42      * this value has no further effect.
43      *
44      * If a route should not be considered to be the initial route it should use [Priority.LAST]
45      */
46     val initialRoutePriority: Int
47 
48     /**
49      * Named navigation arguments that can be accessed by this route's composable. If nothing is
50      * required, this should return an empty list.
51      */
52     val arguments: List<NamedNavArgument>
53 
54     /**
55      * A list of navigation deep links to associate with this Route. If nothing is required, this
56      * should return an empty list.
57      */
58     val deepLinks: List<NavDeepLink>
59 
60     /**
61      * Whether this route should be rendered as a [androidx.compose.ui.window.Dialog]. This is
62      * suitable only when this route represents a separate screen in your app that needs its own
63      * lifecycle and saved state, independent of any other destination in your navigation graph. For
64      * use cases such as [AlertDialog], you should use those APIs directly in the composable
65      * destination that wants to show that dialog.
66      */
67     val isDialog: Boolean
68 
69     /**
70      * In the event [isDialog] is set to true, these are the [DialogProperties] that will be passed
71      * to the [androidx.compose.ui.window.Dialog] instance.
72      */
73     val dialogProperties: DialogProperties?
74 
75     /** Animation callback to define enter transitions for destination in this NavGraph */
76     val enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)?
77 
78     /** Animation callback to define exit transitions for destination in this NavGraph */
79     val exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)?
80 
81     /** Animation callback to define pop enter transitions for destination in this NavGraph */
82     val popEnterTransition:
83         (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)?
84 
85     /** Animation callback to define pop exit transitions for destination in this NavGraph */
86     val popExitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)?
87 
88     /**
89      * The composable content for this Route.
90      *
91      * If this route is a Dialog, this is the composable content that will be hosted inside of the
92      * [androidx.compose.ui.window.Dialog]
93      *
94      * This content is attached to the compose UI tree, and shares all of the same contexts as the
95      * rest of the compose tree. (i.e. can access the LocalCompositionProvider to obtain the
96      * [FeatureManager])
97      *
98      * @param navBackStackEntry the navBackStackEntry is provided for this Route for checking
99      *   navigation arguments, or other navigation related tasks.
100      */
composablenull101     @Composable fun composable(navBackStackEntry: NavBackStackEntry?): Unit
102 }
103