From 5e224016e5842a381cfe42f8956296cbc30a463a Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Sun, 4 Jun 2023 13:05:33 +0800 Subject: [PATCH] Update type in AnimatedNavHost AnimatedContentScope is miragated to AnimatedContentTransitionScope in AndroidX Compose Animation library. Fix: 285619939 Test: m SpaLib Change-Id: I07ea5a9d8d1a2c37a2c66dbecb3085c7d0ae90fd --- .../spa/framework/compose/AnimatedNavHost.kt | 47 ++++++---------- .../spa/framework/compose/NavGraphBuilder.kt | 55 ++----------------- 2 files changed, 22 insertions(+), 80 deletions(-) diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/compose/AnimatedNavHost.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/compose/AnimatedNavHost.kt index 57bb838d55ea6..81bbc2456577a 100644 --- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/compose/AnimatedNavHost.kt +++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/compose/AnimatedNavHost.kt @@ -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.() -> EnterTransition) = - { fadeIn(animationSpec = tween(700)) }, - exitTransition: (AnimatedContentScope.() -> ExitTransition) = - { fadeOut(animationSpec = tween(700)) }, - popEnterTransition: (AnimatedContentScope.() -> EnterTransition) = - enterTransition, - popExitTransition: (AnimatedContentScope.() -> 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.() -> EnterTransition) = - { fadeIn(animationSpec = tween(700)) }, - exitTransition: (AnimatedContentScope.() -> ExitTransition) = - { fadeOut(animationSpec = tween(700)) }, - popEnterTransition: (AnimatedContentScope.() -> EnterTransition) = - enterTransition, - popExitTransition: (AnimatedContentScope.() -> 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.() -> 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.() -> 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.() -> EnterTransition?)?>() +@OptIn(ExperimentalAnimationApi::class) +internal typealias AnimatedScope = AnimatedContentTransitionScope @ExperimentalAnimationApi -internal val exitTransitions = - mutableMapOf.() -> ExitTransition?)?>() +internal val enterTransitions = mutableMapOf EnterTransition?)?>() @ExperimentalAnimationApi -internal val popEnterTransitions = - mutableMapOf.() -> EnterTransition?)?>() +internal val exitTransitions = mutableMapOf ExitTransition?)?>() +@ExperimentalAnimationApi +internal val popEnterTransitions = mutableMapOf EnterTransition?)?>() @ExperimentalAnimationApi -internal val popExitTransitions = - mutableMapOf.() -> ExitTransition?)?>() +internal val popExitTransitions = mutableMapOf ExitTransition?)?>() diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/compose/NavGraphBuilder.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/compose/NavGraphBuilder.kt index 9e58603bbafff..bf92f5dda1a98 100644 --- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/compose/NavGraphBuilder.kt +++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/framework/compose/NavGraphBuilder.kt @@ -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 = emptyList(), deepLinks: List = emptyList(), - enterTransition: (AnimatedContentScope.() -> EnterTransition?)? = null, - exitTransition: (AnimatedContentScope.() -> ExitTransition?)? = null, - popEnterTransition: ( - AnimatedContentScope.() -> EnterTransition? - )? = enterTransition, - popExitTransition: ( - AnimatedContentScope.() -> 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 = emptyList(), - deepLinks: List = emptyList(), - enterTransition: (AnimatedContentScope.() -> EnterTransition?)? = null, - exitTransition: (AnimatedContentScope.() -> ExitTransition?)? = null, - popEnterTransition: ( - AnimatedContentScope.() -> EnterTransition? - )? = enterTransition, - popExitTransition: ( - AnimatedContentScope.() -> 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 } - } -}