Revert "Update type in AnimatedNavHost"

Revert submission 23556316-compose_drop

Reason for revert: b/286077407

Reverted changes: /q/submissionid:23556316-compose_drop

Change-Id: If0c30aaa81f89131842699b3700155997ae5ebfe
This commit is contained in:
Daniel Norman
2023-06-06 22:53:46 +00:00
committed by Android (Google) Code Review
parent 5e224016e5
commit 7917bcd9c2
2 changed files with 80 additions and 22 deletions

View File

@@ -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.AnimatedContentTransitionScope
import androidx.compose.animation.AnimatedContentScope
import androidx.compose.animation.ContentTransform
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
@@ -78,10 +78,14 @@ public fun AnimatedNavHost(
modifier: Modifier = Modifier,
contentAlignment: Alignment = Alignment.Center,
route: String? = null,
enterTransition: (AnimatedScope.() -> EnterTransition) = { fadeIn(animationSpec = tween(700)) },
exitTransition: (AnimatedScope.() -> ExitTransition) = { fadeOut(animationSpec = tween(700)) },
popEnterTransition: (AnimatedScope.() -> EnterTransition) = enterTransition,
popExitTransition: (AnimatedScope.() -> ExitTransition) = exitTransition,
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,
builder: NavGraphBuilder.() -> Unit
) {
AnimatedNavHost(
@@ -119,10 +123,14 @@ public fun AnimatedNavHost(
graph: NavGraph,
modifier: Modifier = Modifier,
contentAlignment: Alignment = Alignment.Center,
enterTransition: (AnimatedScope.() -> EnterTransition) = { fadeIn(animationSpec = tween(700)) },
exitTransition: (AnimatedScope.() -> ExitTransition) = { fadeOut(animationSpec = tween(700)) },
popEnterTransition: (AnimatedScope.() -> EnterTransition) = enterTransition,
popExitTransition: (AnimatedScope.() -> ExitTransition) = exitTransition,
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,
) {
val lifecycleOwner = LocalLifecycleOwner.current
@@ -160,7 +168,7 @@ public fun AnimatedNavHost(
val backStackEntry = visibleEntries.lastOrNull()
if (backStackEntry != null) {
val finalEnter: AnimatedScope.() -> EnterTransition = {
val finalEnter: AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition = {
val targetDestination = targetState.destination as AnimatedComposeNavigator.Destination
if (composeNavigator.isPop.value) {
@@ -174,7 +182,7 @@ public fun AnimatedNavHost(
}
}
val finalExit: AnimatedScope.() -> ExitTransition = {
val finalExit: AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition = {
val initialDestination =
initialState.destination as AnimatedComposeNavigator.Destination
@@ -237,16 +245,19 @@ public fun AnimatedNavHost(
DialogHost(dialogNavigator)
}
@OptIn(ExperimentalAnimationApi::class)
internal typealias AnimatedScope = AnimatedContentTransitionScope<NavBackStackEntry>
@ExperimentalAnimationApi
internal val enterTransitions =
mutableMapOf<String?,
(AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)?>()
@ExperimentalAnimationApi
internal val enterTransitions = mutableMapOf<String?, (AnimatedScope.() -> EnterTransition?)?>()
internal val exitTransitions =
mutableMapOf<String?, (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)?>()
@ExperimentalAnimationApi
internal val exitTransitions = mutableMapOf<String?, (AnimatedScope.() -> ExitTransition?)?>()
@ExperimentalAnimationApi
internal val popEnterTransitions = mutableMapOf<String?, (AnimatedScope.() -> EnterTransition?)?>()
internal val popEnterTransitions =
mutableMapOf<String?, (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)?>()
@ExperimentalAnimationApi
internal val popExitTransitions = mutableMapOf<String?, (AnimatedScope.() -> ExitTransition?)?>()
internal val popExitTransitions =
mutableMapOf<String?, (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)?>()

View File

@@ -16,6 +16,7 @@
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
@@ -24,7 +25,9 @@ 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
/**
@@ -44,10 +47,14 @@ public fun NavGraphBuilder.composable(
route: String,
arguments: List<NamedNavArgument> = emptyList(),
deepLinks: List<NavDeepLink> = emptyList(),
enterTransition: (AnimatedScope.() -> EnterTransition?)? = null,
exitTransition: (AnimatedScope.() -> ExitTransition?)? = null,
popEnterTransition: (AnimatedScope.() -> EnterTransition?)? = enterTransition,
popExitTransition: (AnimatedScope.() -> ExitTransition?)? = exitTransition,
enterTransition: (AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?)? = null,
exitTransition: (AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?)? = null,
popEnterTransition: (
AnimatedContentScope<NavBackStackEntry>.() -> EnterTransition?
)? = enterTransition,
popExitTransition: (
AnimatedContentScope<NavBackStackEntry>.() -> ExitTransition?
)? = exitTransition,
content: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit
) {
addDestination(
@@ -69,3 +76,43 @@ 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 }
}
}