Merge "Revert "Revert "Update type in AnimatedNavHost""" into udc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0870eea43f
@@ -18,7 +18,7 @@ package com.android.settingslib.spa.framework.compose
|
||||
|
||||
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.AnimatedContentScope
|
||||
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||
import androidx.compose.animation.ContentTransform
|
||||
import androidx.compose.animation.EnterTransition
|
||||
import androidx.compose.animation.ExitTransition
|
||||
@@ -78,14 +78,10 @@ public fun AnimatedNavHost(
|
||||
modifier: Modifier = Modifier,
|
||||
contentAlignment: Alignment = Alignment.Center,
|
||||
route: String? = null,
|
||||
enterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition) =
|
||||
{ fadeIn(animationSpec = tween(700)) },
|
||||
exitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition) =
|
||||
{ fadeOut(animationSpec = tween(700)) },
|
||||
popEnterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition) =
|
||||
enterTransition,
|
||||
popExitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition) =
|
||||
exitTransition,
|
||||
enterTransition: (AnimatedScope.() -> EnterTransition) = { fadeIn(animationSpec = tween(700)) },
|
||||
exitTransition: (AnimatedScope.() -> ExitTransition) = { fadeOut(animationSpec = tween(700)) },
|
||||
popEnterTransition: (AnimatedScope.() -> EnterTransition) = enterTransition,
|
||||
popExitTransition: (AnimatedScope.() -> ExitTransition) = exitTransition,
|
||||
builder: NavGraphBuilder.() -> Unit
|
||||
) {
|
||||
AnimatedNavHost(
|
||||
@@ -123,14 +119,10 @@ public fun AnimatedNavHost(
|
||||
graph: NavGraph,
|
||||
modifier: Modifier = Modifier,
|
||||
contentAlignment: Alignment = Alignment.Center,
|
||||
enterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition) =
|
||||
{ fadeIn(animationSpec = tween(700)) },
|
||||
exitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition) =
|
||||
{ fadeOut(animationSpec = tween(700)) },
|
||||
popEnterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition) =
|
||||
enterTransition,
|
||||
popExitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition) =
|
||||
exitTransition,
|
||||
enterTransition: (AnimatedScope.() -> EnterTransition) = { fadeIn(animationSpec = tween(700)) },
|
||||
exitTransition: (AnimatedScope.() -> ExitTransition) = { fadeOut(animationSpec = tween(700)) },
|
||||
popEnterTransition: (AnimatedScope.() -> EnterTransition) = enterTransition,
|
||||
popExitTransition: (AnimatedScope.() -> ExitTransition) = exitTransition,
|
||||
) {
|
||||
|
||||
val lifecycleOwner = LocalLifecycleOwner.current
|
||||
@@ -168,7 +160,7 @@ public fun AnimatedNavHost(
|
||||
val backStackEntry = visibleEntries.lastOrNull()
|
||||
|
||||
if (backStackEntry != null) {
|
||||
val finalEnter: AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition = {
|
||||
val finalEnter: AnimatedScope.() -> EnterTransition = {
|
||||
val targetDestination = targetState.destination as AnimatedComposeNavigator.Destination
|
||||
|
||||
if (composeNavigator.isPop.value) {
|
||||
@@ -182,7 +174,7 @@ public fun AnimatedNavHost(
|
||||
}
|
||||
}
|
||||
|
||||
val finalExit: AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition = {
|
||||
val finalExit: AnimatedScope.() -> ExitTransition = {
|
||||
val initialDestination =
|
||||
initialState.destination as AnimatedComposeNavigator.Destination
|
||||
|
||||
@@ -245,19 +237,16 @@ public fun AnimatedNavHost(
|
||||
DialogHost(dialogNavigator)
|
||||
}
|
||||
|
||||
@ExperimentalAnimationApi
|
||||
internal val enterTransitions =
|
||||
mutableMapOf<String?,
|
||||
(AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)?>()
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
internal typealias AnimatedScope = AnimatedContentTransitionScope<NavBackStackEntry>
|
||||
|
||||
@ExperimentalAnimationApi
|
||||
internal val exitTransitions =
|
||||
mutableMapOf<String?, (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)?>()
|
||||
internal val enterTransitions = mutableMapOf<String?, (AnimatedScope.() -> EnterTransition?)?>()
|
||||
|
||||
@ExperimentalAnimationApi
|
||||
internal val popEnterTransitions =
|
||||
mutableMapOf<String?, (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)?>()
|
||||
internal val exitTransitions = mutableMapOf<String?, (AnimatedScope.() -> ExitTransition?)?>()
|
||||
@ExperimentalAnimationApi
|
||||
internal val popEnterTransitions = mutableMapOf<String?, (AnimatedScope.() -> EnterTransition?)?>()
|
||||
|
||||
@ExperimentalAnimationApi
|
||||
internal val popExitTransitions =
|
||||
mutableMapOf<String?, (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)?>()
|
||||
internal val popExitTransitions = mutableMapOf<String?, (AnimatedScope.() -> ExitTransition?)?>()
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settingslib.spa.framework.compose
|
||||
|
||||
import androidx.compose.animation.AnimatedContentScope
|
||||
import androidx.compose.animation.AnimatedVisibilityScope
|
||||
import androidx.compose.animation.EnterTransition
|
||||
import androidx.compose.animation.ExitTransition
|
||||
@@ -25,9 +24,7 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.navigation.NamedNavArgument
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import androidx.navigation.NavDeepLink
|
||||
import androidx.navigation.NavGraph
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.compose.navigation
|
||||
import androidx.navigation.get
|
||||
|
||||
/**
|
||||
@@ -47,14 +44,10 @@ public fun NavGraphBuilder.composable(
|
||||
route: String,
|
||||
arguments: List<NamedNavArgument> = emptyList(),
|
||||
deepLinks: List<NavDeepLink> = emptyList(),
|
||||
enterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)? = null,
|
||||
exitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)? = null,
|
||||
popEnterTransition: (
|
||||
AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?
|
||||
)? = enterTransition,
|
||||
popExitTransition: (
|
||||
AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?
|
||||
)? = exitTransition,
|
||||
enterTransition: (AnimatedScope.() -> EnterTransition?)? = null,
|
||||
exitTransition: (AnimatedScope.() -> ExitTransition?)? = null,
|
||||
popEnterTransition: (AnimatedScope.() -> EnterTransition?)? = enterTransition,
|
||||
popExitTransition: (AnimatedScope.() -> ExitTransition?)? = exitTransition,
|
||||
content: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit
|
||||
) {
|
||||
addDestination(
|
||||
@@ -76,43 +69,3 @@ public fun NavGraphBuilder.composable(
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a nested [NavGraph]
|
||||
*
|
||||
* @param startDestination the starting destination's route for this NavGraph
|
||||
* @param route the destination's unique route
|
||||
* @param arguments list of arguments to associate with destination
|
||||
* @param deepLinks list of deep links to associate with the destinations
|
||||
* @param enterTransition callback to define enter transitions for destination in this NavGraph
|
||||
* @param exitTransition callback to define exit transitions for destination in this NavGraph
|
||||
* @param popEnterTransition callback to define pop enter transitions for destination in this
|
||||
* NavGraph
|
||||
* @param popExitTransition callback to define pop exit transitions for destination in this NavGraph
|
||||
* @param builder the builder used to construct the graph
|
||||
*
|
||||
* @return the newly constructed nested NavGraph
|
||||
*/
|
||||
@ExperimentalAnimationApi
|
||||
public fun NavGraphBuilder.navigation(
|
||||
startDestination: String,
|
||||
route: String,
|
||||
arguments: List<NamedNavArgument> = emptyList(),
|
||||
deepLinks: List<NavDeepLink> = emptyList(),
|
||||
enterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)? = null,
|
||||
exitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)? = null,
|
||||
popEnterTransition: (
|
||||
AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?
|
||||
)? = enterTransition,
|
||||
popExitTransition: (
|
||||
AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?
|
||||
)? = exitTransition,
|
||||
builder: NavGraphBuilder.() -> Unit
|
||||
) {
|
||||
navigation(startDestination, route, arguments, deepLinks, builder).apply {
|
||||
enterTransition?.let { enterTransitions[route] = enterTransition }
|
||||
exitTransition?.let { exitTransitions[route] = exitTransition }
|
||||
popEnterTransition?.let { popEnterTransitions[route] = popEnterTransition }
|
||||
popExitTransition?.let { popExitTransitions[route] = popExitTransition }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user