NavDisplay.TransitionKey
-
Cmn
object NavDisplay.TransitionKey : NavMetadataKey
The key for NavEntry.metadata or Scene.metadata to notify the NavDisplay of how the content should be animated when adding to the backstack.
IMPORTANT NavDisplay only looks at the Scene.metadata to determine the final ContentTransform. It is the responsibility of the Scene.metadata to decide which ContentTransform to return, whether that be from the NavEntry.metadata or something custom.
HOW TO USE Within the metadata DSL, invoke MetadataScope.put and pass TransitionKey as the key. The value: AnimatedContentTransitionScope<Scene<*>>.() -> ContentTransform? should be the ContentTransform to be used when adding to the backstack.
import androidx.compose.foundation.layout.Box import androidx.navigation3.runtime.NavEntry import androidx.navigation3.runtime.entryProvider import androidx.navigation3.runtime.metadata import androidx.navigation3.runtime.rememberNavBackStack import androidx.navigation3.runtime.rememberSaveableStateHolderNavEntryDecorator import androidx.navigation3.scene.Scene import androidx.navigation3.scene.SceneStrategy import androidx.navigation3.ui.NavDisplay val backStack = rememberNavBackStack(A) NavDisplay( backStack, onBack = { backStack.removeLastOrNull() }, entryDecorators = listOf(rememberSaveableStateHolderNavEntryDecorator()), // the Scene overrides the NavEntry's slide vertical with slide horizontal transitions sceneStrategy = SceneOverrideEntryTransitionsSceneStrategy(), entryProvider = entryProvider { entry<A> { BlueBox("A") { backStack.add(B) } } // the entry defines slide vertical transitions entry<B>( metadata = metadata { put(NavDisplay.TransitionKey) { slideVertical } put(NavDisplay.PopTransitionKey) { slideVertical } put(NavDisplay.PredictivePopTransitionKey, { _: Int -> slideVertical }) } ) { RedBox("B") } }, )