diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/NavigationEffects.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/NavigationEffects.kt index 0a186f439e..cf4a4ee7e9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/NavigationEffects.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/NavigationEffects.kt @@ -34,26 +34,22 @@ import androidx.navigation.NavGraphBuilder import androidx.navigation.compose.composable import androidx.navigation.toRoute -// Per-entry hint stored on NavBackStackEntry.savedStateHandle by -// Nav.navBottomBar. When present, composableFromEnd skips the horizontal -// slide so bottom-bar taps fall back to the NavHost-level fade. -const val SKIP_SLIDE_ANIMATION_KEY = "skipSlideAnimation" - -fun NavBackStackEntry.skipsSlideAnimation(): Boolean = savedStateHandle.get(SKIP_SLIDE_ANIMATION_KEY) == true - // Per-entry hint stamped by Nav.navBottomBar marking that the entry was -// reached via a bottom-nav tab. Used by Nav.canPop so top bars can hide -// the back arrow on tab roots even though Home sits below them. +// reached via a bottom-nav tab. Used in two places: +// - composableFromEnd skips the horizontal slide on tab entries so +// bottom-bar taps fall back to the NavHost-level fade. +// - Nav.canPop hides the back arrow on tab roots even though Home +// sits below them in the stack. const val BOTTOM_NAV_ROOT_KEY = "bottomNavRoot" fun NavBackStackEntry.isBottomNavRoot(): Boolean = savedStateHandle.get(BOTTOM_NAV_ROOT_KEY) == true inline fun NavGraphBuilder.composableFromEnd(noinline content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit) { composable( - enterTransition = { if (targetState.skipsSlideAnimation()) null else slideInHorizontallyFromEnd }, - exitTransition = { if (targetState.skipsSlideAnimation()) null else scaleOut }, - popEnterTransition = { if (initialState.skipsSlideAnimation()) null else scaleIn }, - popExitTransition = { if (initialState.skipsSlideAnimation()) null else slideOutHorizontallyToEnd }, + enterTransition = { if (targetState.isBottomNavRoot()) null else slideInHorizontallyFromEnd }, + exitTransition = { if (targetState.isBottomNavRoot()) null else scaleOut }, + popEnterTransition = { if (initialState.isBottomNavRoot()) null else scaleIn }, + popExitTransition = { if (initialState.isBottomNavRoot()) null else slideOutHorizontallyToEnd }, content = content, ) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/navs/Nav.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/navs/Nav.kt index df9c92287e..3d2a94b4f5 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/navs/Nav.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/navs/Nav.kt @@ -26,7 +26,6 @@ import androidx.compose.material3.DrawerValue import androidx.compose.runtime.Stable import androidx.navigation.NavHostController import com.vitorpamplona.amethyst.ui.navigation.BOTTOM_NAV_ROOT_KEY -import com.vitorpamplona.amethyst.ui.navigation.SKIP_SLIDE_ANIMATION_KEY import com.vitorpamplona.amethyst.ui.navigation.isBottomNavRoot import com.vitorpamplona.amethyst.ui.navigation.routes.Route import com.vitorpamplona.amethyst.ui.navigation.routes.getRouteWithArguments @@ -88,12 +87,9 @@ class Nav( } launchSingleTop = true } - val entry = controller.getBackStackEntry(route) - // Skip the horizontal slide for composableFromEnd transitions. - entry.savedStateHandle[SKIP_SLIDE_ANIMATION_KEY] = true - // Mark this entry as a tab root so canPop hides the back arrow - // even though Home sits below it. - entry.savedStateHandle[BOTTOM_NAV_ROOT_KEY] = true + // Mark this entry as a tab root: hides the back arrow in canPop + // and skips the horizontal slide in composableFromEnd. + controller.getBackStackEntry(route).savedStateHandle[BOTTOM_NAV_ROOT_KEY] = true } }