mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-11 08:47:33 +00:00
refactor(nav): collapse SKIP_SLIDE_ANIMATION_KEY into BOTTOM_NAV_ROOT_KEY
Both flags were stamped at the same call site (navBottomBar) and meant the same thing — "this entry is a bottom-nav tab root". Collapse them into a single key and use isBottomNavRoot() in composableFromEnd's transition lambdas. https://claude.ai/code/session_01PrirRcL7g8iX7vTqqLTkBS
This commit is contained in:
+9
-13
@@ -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<Boolean>(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<Boolean>(BOTTOM_NAV_ROOT_KEY) == true
|
||||
|
||||
inline fun <reified T : Any> NavGraphBuilder.composableFromEnd(noinline content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit) {
|
||||
composable<T>(
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user