|
16 | 16 |
|
17 | 17 | package androidx.navigation.compose |
18 | 18 |
|
| 19 | +import androidx.compose.animation.AnimatedContentTransitionScope |
| 20 | +import androidx.compose.animation.EnterTransition |
| 21 | +import androidx.compose.animation.ExitTransition |
| 22 | +import androidx.compose.animation.SizeTransform |
19 | 23 | import androidx.compose.animation.core.AnimationConstants.DefaultDurationMillis |
| 24 | +import androidx.compose.animation.core.spring |
| 25 | +import androidx.compose.animation.core.tween |
| 26 | +import androidx.compose.animation.fadeIn |
| 27 | +import androidx.compose.animation.fadeOut |
| 28 | +import androidx.compose.animation.scaleOut |
20 | 29 | import androidx.compose.foundation.layout.Column |
21 | 30 | import androidx.compose.foundation.layout.fillMaxSize |
22 | 31 | import androidx.compose.foundation.text.BasicText |
@@ -54,6 +63,7 @@ import androidx.lifecycle.testing.TestLifecycleOwner |
54 | 63 | import androidx.lifecycle.viewmodel.CreationExtras |
55 | 64 | import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner |
56 | 65 | import androidx.lifecycle.viewmodel.compose.viewModel |
| 66 | +import androidx.navigation.NavBackStackEntry |
57 | 67 | import androidx.navigation.NavGraph |
58 | 68 | import androidx.navigation.NavGraph.Companion.findStartDestination |
59 | 69 | import androidx.navigation.NavHostController |
@@ -843,15 +853,21 @@ class NavHostTest { |
843 | 853 | } |
844 | 854 |
|
845 | 855 | @Test |
846 | | - @Ignore //animations are different between platforms |
847 | 856 | fun testNavHostAnimations() = runComposeUiTestOnUiThread { |
848 | 857 | lateinit var navController: NavHostController |
849 | 858 |
|
850 | 859 | mainClock.autoAdvance = false |
851 | 860 |
|
852 | 861 | setContent { |
853 | 862 | navController = rememberNavController() |
854 | | - NavHost(navController, startDestination = first) { |
| 863 | + NavHost( |
| 864 | + navController = navController, |
| 865 | + enterTransition = TestNavTransitions.enterTransition, |
| 866 | + exitTransition = TestNavTransitions.exitTransition, |
| 867 | + popEnterTransition = TestNavTransitions.enterTransition, |
| 868 | + popExitTransition = TestNavTransitions.exitTransition, |
| 869 | + startDestination = first |
| 870 | + ) { |
855 | 871 | composable(first) { BasicText(first) } |
856 | 872 | composable(second) { BasicText(second) } |
857 | 873 | } |
@@ -1304,3 +1320,18 @@ private class TestViewModelStoreOwnerWithDefaults( |
1304 | 1320 | override val defaultViewModelProviderFactory: ViewModelProvider.Factory = TestViewModelFactory(), |
1305 | 1321 | override val defaultViewModelCreationExtras: CreationExtras = CreationExtras.Empty, |
1306 | 1322 | ) : ViewModelStoreOwner, HasDefaultViewModelProviderFactory |
| 1323 | + |
| 1324 | +private object TestNavTransitions { |
| 1325 | + |
| 1326 | + val enterTransition: |
| 1327 | + AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition = |
| 1328 | + { |
| 1329 | + fadeIn(animationSpec = tween(700)) |
| 1330 | + } |
| 1331 | + |
| 1332 | + val exitTransition: |
| 1333 | + AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition = |
| 1334 | + { |
| 1335 | + fadeOut(animationSpec = tween(700)) |
| 1336 | + } |
| 1337 | +} |
0 commit comments