Merge "Revert "Revert "Update type in AnimatedNavHost""" into udc-dev-plus-aosp
This commit is contained in:
committed by
Android (Google) Code Review
commit
96633835d0
@@ -18,7 +18,7 @@ package com.android.settingslib.spa.framework.compose
|
|||||||
|
|
||||||
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
|
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
|
||||||
import androidx.compose.animation.AnimatedContent
|
import androidx.compose.animation.AnimatedContent
|
||||||
import androidx.compose.animation.AnimatedContentScope
|
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||||
import androidx.compose.animation.ContentTransform
|
import androidx.compose.animation.ContentTransform
|
||||||
import androidx.compose.animation.EnterTransition
|
import androidx.compose.animation.EnterTransition
|
||||||
import androidx.compose.animation.ExitTransition
|
import androidx.compose.animation.ExitTransition
|
||||||
@@ -78,14 +78,10 @@ public fun AnimatedNavHost(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentAlignment: Alignment = Alignment.Center,
|
contentAlignment: Alignment = Alignment.Center,
|
||||||
route: String? = null,
|
route: String? = null,
|
||||||
enterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition) =
|
enterTransition: (AnimatedScope.() -> EnterTransition) = { fadeIn(animationSpec = tween(700)) },
|
||||||
{ fadeIn(animationSpec = tween(700)) },
|
exitTransition: (AnimatedScope.() -> ExitTransition) = { fadeOut(animationSpec = tween(700)) },
|
||||||
exitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition) =
|
popEnterTransition: (AnimatedScope.() -> EnterTransition) = enterTransition,
|
||||||
{ fadeOut(animationSpec = tween(700)) },
|
popExitTransition: (AnimatedScope.() -> ExitTransition) = exitTransition,
|
||||||
popEnterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition) =
|
|
||||||
enterTransition,
|
|
||||||
popExitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition) =
|
|
||||||
exitTransition,
|
|
||||||
builder: NavGraphBuilder.() -> Unit
|
builder: NavGraphBuilder.() -> Unit
|
||||||
) {
|
) {
|
||||||
AnimatedNavHost(
|
AnimatedNavHost(
|
||||||
@@ -123,14 +119,10 @@ public fun AnimatedNavHost(
|
|||||||
graph: NavGraph,
|
graph: NavGraph,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentAlignment: Alignment = Alignment.Center,
|
contentAlignment: Alignment = Alignment.Center,
|
||||||
enterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition) =
|
enterTransition: (AnimatedScope.() -> EnterTransition) = { fadeIn(animationSpec = tween(700)) },
|
||||||
{ fadeIn(animationSpec = tween(700)) },
|
exitTransition: (AnimatedScope.() -> ExitTransition) = { fadeOut(animationSpec = tween(700)) },
|
||||||
exitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition) =
|
popEnterTransition: (AnimatedScope.() -> EnterTransition) = enterTransition,
|
||||||
{ fadeOut(animationSpec = tween(700)) },
|
popExitTransition: (AnimatedScope.() -> ExitTransition) = exitTransition,
|
||||||
popEnterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition) =
|
|
||||||
enterTransition,
|
|
||||||
popExitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition) =
|
|
||||||
exitTransition,
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val lifecycleOwner = LocalLifecycleOwner.current
|
val lifecycleOwner = LocalLifecycleOwner.current
|
||||||
@@ -168,7 +160,7 @@ public fun AnimatedNavHost(
|
|||||||
val backStackEntry = visibleEntries.lastOrNull()
|
val backStackEntry = visibleEntries.lastOrNull()
|
||||||
|
|
||||||
if (backStackEntry != null) {
|
if (backStackEntry != null) {
|
||||||
val finalEnter: AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition = {
|
val finalEnter: AnimatedScope.() -> EnterTransition = {
|
||||||
val targetDestination = targetState.destination as AnimatedComposeNavigator.Destination
|
val targetDestination = targetState.destination as AnimatedComposeNavigator.Destination
|
||||||
|
|
||||||
if (composeNavigator.isPop.value) {
|
if (composeNavigator.isPop.value) {
|
||||||
@@ -182,7 +174,7 @@ public fun AnimatedNavHost(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val finalExit: AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition = {
|
val finalExit: AnimatedScope.() -> ExitTransition = {
|
||||||
val initialDestination =
|
val initialDestination =
|
||||||
initialState.destination as AnimatedComposeNavigator.Destination
|
initialState.destination as AnimatedComposeNavigator.Destination
|
||||||
|
|
||||||
@@ -245,19 +237,16 @@ public fun AnimatedNavHost(
|
|||||||
DialogHost(dialogNavigator)
|
DialogHost(dialogNavigator)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExperimentalAnimationApi
|
@OptIn(ExperimentalAnimationApi::class)
|
||||||
internal val enterTransitions =
|
internal typealias AnimatedScope = AnimatedContentTransitionScope<NavBackStackEntry>
|
||||||
mutableMapOf<String?,
|
|
||||||
(AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)?>()
|
|
||||||
|
|
||||||
@ExperimentalAnimationApi
|
@ExperimentalAnimationApi
|
||||||
internal val exitTransitions =
|
internal val enterTransitions = mutableMapOf<String?, (AnimatedScope.() -> EnterTransition?)?>()
|
||||||
mutableMapOf<String?, (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)?>()
|
|
||||||
|
|
||||||
@ExperimentalAnimationApi
|
@ExperimentalAnimationApi
|
||||||
internal val popEnterTransitions =
|
internal val exitTransitions = mutableMapOf<String?, (AnimatedScope.() -> ExitTransition?)?>()
|
||||||
mutableMapOf<String?, (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)?>()
|
@ExperimentalAnimationApi
|
||||||
|
internal val popEnterTransitions = mutableMapOf<String?, (AnimatedScope.() -> EnterTransition?)?>()
|
||||||
|
|
||||||
@ExperimentalAnimationApi
|
@ExperimentalAnimationApi
|
||||||
internal val popExitTransitions =
|
internal val popExitTransitions = mutableMapOf<String?, (AnimatedScope.() -> ExitTransition?)?>()
|
||||||
mutableMapOf<String?, (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)?>()
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settingslib.spa.framework.compose
|
package com.android.settingslib.spa.framework.compose
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedContentScope
|
|
||||||
import androidx.compose.animation.AnimatedVisibilityScope
|
import androidx.compose.animation.AnimatedVisibilityScope
|
||||||
import androidx.compose.animation.EnterTransition
|
import androidx.compose.animation.EnterTransition
|
||||||
import androidx.compose.animation.ExitTransition
|
import androidx.compose.animation.ExitTransition
|
||||||
@@ -25,9 +24,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.navigation.NamedNavArgument
|
import androidx.navigation.NamedNavArgument
|
||||||
import androidx.navigation.NavBackStackEntry
|
import androidx.navigation.NavBackStackEntry
|
||||||
import androidx.navigation.NavDeepLink
|
import androidx.navigation.NavDeepLink
|
||||||
import androidx.navigation.NavGraph
|
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.compose.navigation
|
|
||||||
import androidx.navigation.get
|
import androidx.navigation.get
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,14 +44,10 @@ public fun NavGraphBuilder.composable(
|
|||||||
route: String,
|
route: String,
|
||||||
arguments: List<NamedNavArgument> = emptyList(),
|
arguments: List<NamedNavArgument> = emptyList(),
|
||||||
deepLinks: List<NavDeepLink> = emptyList(),
|
deepLinks: List<NavDeepLink> = emptyList(),
|
||||||
enterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)? = null,
|
enterTransition: (AnimatedScope.() -> EnterTransition?)? = null,
|
||||||
exitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)? = null,
|
exitTransition: (AnimatedScope.() -> ExitTransition?)? = null,
|
||||||
popEnterTransition: (
|
popEnterTransition: (AnimatedScope.() -> EnterTransition?)? = enterTransition,
|
||||||
AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?
|
popExitTransition: (AnimatedScope.() -> ExitTransition?)? = exitTransition,
|
||||||
)? = enterTransition,
|
|
||||||
popExitTransition: (
|
|
||||||
AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?
|
|
||||||
)? = exitTransition,
|
|
||||||
content: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit
|
content: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit
|
||||||
) {
|
) {
|
||||||
addDestination(
|
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