OverlayScene


public interface OverlayScene<T extends Object> extends Scene


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

It is expected that the content is rendered in one or more separate windows (e.g., a dialog, popup window, etc.) that are visible above any additional Scene instances calculated from the overlaidEntries.

When processing overlaidEntries, expect processing of each SceneStrategy to restart from the first strategy. This may result in multiple instances of the same OverlayScene to be shown simultaneously, making a unique key even more important.

Summary

Public methods

abstract @NonNull List<@NonNull NavEntry<@NonNull T>>

The NavEntrys that should be handled by another Scene that sits below this Scene.

default void

Callback that is invoked after this OverlayScene is popped from the backStack, but before it leaves composition.

Inherited methods

From androidx.navigation3.scene.Scene
abstract @Composable @NonNull Function0<Unit>

The content rendering the Scene itself.

abstract @NonNull List<@NonNull NavEntry<@NonNull T>>

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

abstract @NonNull Object

The key identifying the Scene.

default @NonNull Map<@NonNull String, @NonNull Object>

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

abstract @NonNull List<@NonNull NavEntry<@NonNull T>>

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

Public methods

getOverlaidEntries

Added in 1.0.0
abstract @NonNull List<@NonNull NavEntry<@NonNull T>> getOverlaidEntries()

The NavEntrys that should be handled by another Scene that sits below this Scene.

This must always be a non-empty list to correctly display entries below the overlay.

onRemove

Added in 1.1.0-alpha04
default void onRemove()

Callback that is invoked after this OverlayScene is popped from the backStack, but before it leaves composition.

Animations for exiting overlays should be implemented within onRemove. This ensures that any suspending animations or other suspending work completes before the overlay is removed from composition.

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.navigation3.runtime.entryProvider
import androidx.navigation3.runtime.metadata
import androidx.navigation3.runtime.rememberNavBackStack
import androidx.navigation3.scene.Scene
import androidx.navigation3.scene.SceneStrategy
import androidx.navigation3.ui.NavDisplay

val backStack = rememberNavBackStack(Landing)
NavDisplay(
    backStack = backStack,
    onBack = { backStack.removeLastOrNull() },
    sceneStrategy = AnimatedBottomSheetSceneStrategy(),
    entryProvider =
        entryProvider {
            entry<Landing> {
                Box(Modifier.fillMaxSize().background(Color.Green)) {
                    Button(onClick = { backStack.add(AnimatedBottomSheet) }) {
                        Text("Click to open bottom sheet")
                    }
                }
            }
            entry<AnimatedBottomSheet>(
                metadata = AnimatedBottomSheetSceneStrategy.bottomSheet()
            ) {
                Column {
                    Text("BottomSheet")
                    Button(onClick = { backStack.removeLastOrNull() }) {
                        Text("Close BottomSheet")
                    }
                }
            }
        },
)