Known direct subclasses
OverlayScene

A specific scene to render 1 or more NavEntry instances as an overlay.


A specific scene to render 1 or more androidx.navigation3.runtime.NavEntrys.

A scene instance is identified by its key and the class of the Scene, and this change drives the top-level animation based on the SceneStrategy calculating what the current Scene is for the backstack.

The rendering for content should invoke the content for each androidx.navigation3.runtime.NavEntry contained in entries at most once concurrently in a given Scene.

It is valid for two different instances of a Scene to render the same androidx.navigation3.runtime.NavEntry. In this situation, the content for a androidx.navigation3.runtime.NavEntry will only be rendered in the most recent target Scene that it is displayed in, as determined by entries.

Summary

Public properties

@Composable () -> Unit

The content rendering the Scene itself.

Cmn
List<NavEntry<T>>

The list of androidx.navigation3.runtime.NavEntrys that can be displayed in this scene.

Cmn
Any

The key identifying the Scene.

Cmn
open Map<StringAny>

Provide Scene-specific information to androidx.navigation3.ui.NavDisplay.

Cmn
List<NavEntry<T>>

The resulting NavEntrys that should be computed after pressing back updates the backstack.

Cmn

Public properties

content

val content: @Composable () -> Unit

The content rendering the Scene itself.

This should call the content for the entries, and can add any arbitrary UI around them specific to the Scene.

entries

val entriesList<NavEntry<T>>

The list of androidx.navigation3.runtime.NavEntrys that can be displayed in this scene.

When animating between scenes, the underlying content for each androidx.navigation3.runtime.NavEntry will only be rendered by the scene that is most recently the target scene, and is displaying that androidx.navigation3.runtime.NavEntry as determined by this entries list.

For example, consider a transition from Scene1 to Scene2 below:

Scene1:      Scene2:
+---+---+ +---+---+
|
| | | | |
|
A | B | --> | B | C |
|
| | | | |
+---+---+
+---+---+

Scene1.entries should be [A, B], and Scene2.entries should be [B, C]

When both are being rendered at the same time during the transition, the content for A will be rendered in Scene1, while the content for B and C will be rendered in Scene2.

key

val keyAny

The key identifying the Scene. This key will be combined with the class of the Scene to determine the key that drives the transition in the top-level animation for the NavDisplay.

Because the class of the Scene is also used, this key only needs to be unique for a given type of Scene to indicate a different instance of the Scene.

metadata

open val metadataMap<StringAny>

Provide Scene-specific information to androidx.navigation3.ui.NavDisplay.

By default includes the metadata of the last NavEntry in entries.

import androidx.compose.foundation.layout.Box
import androidx.navigation3.runtime.NavEntry
import androidx.navigation3.runtime.entryProvider
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
import androidx.navigation3.ui.NavDisplay.popTransitionSpec
import androidx.navigation3.ui.NavDisplay.predictivePopTransitionSpec

val backStack = rememberNavBackStack(A)
NavDisplay(
    backStack,
    onBack = { backStack.removeLastOrNull() },
    entryDecorators = listOf(rememberSaveableStateHolderNavEntryDecorator()),
    // NavDisplay default transitions slide vertically
    transitionSpec = { slideVertical },
    popTransitionSpec = { slideVertical },
    predictivePopTransitionSpec = { slideVertical },
    // but the Scene provides default transitions that slide horizontally
    sceneStrategy = DefaultSceneTransitionsSceneStrategy(),
    entryProvider =
        entryProvider {
            entry<A> { BlueBox("A") { backStack.add(B) } }
            entry<B> { RedBox("B") }
        },
)
import androidx.compose.foundation.layout.Box
import androidx.navigation3.runtime.NavEntry
import androidx.navigation3.runtime.entryProvider
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
import androidx.navigation3.ui.NavDisplay.popTransitionSpec
import androidx.navigation3.ui.NavDisplay.predictivePopTransitionSpec

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 =
                    NavDisplay.transitionSpec({ slideVertical }) +
                        popTransitionSpec({ slideVertical }) +
                        predictivePopTransitionSpec({ slideVertical })
            ) {
                RedBox("B")
            }
        },
)

previousEntries

val previousEntriesList<NavEntry<T>>

The resulting NavEntrys that should be computed after pressing back updates the backstack.

This is required for calculating the proper predictive back state, which may result in a different scene being shown.

When predictive back is occurring, this list of entries will be passed through the SceneStrategy again, to determine what the resulting scene would be if the back happens.