# OverlayScene

Artifact: [androidx.navigation3:navigation3-ui](https://developer.android.com/jetpack/androidx/releases/navigation3) [View Source](https://cs.android.com/search?q=file:androidx/navigation3/scene/OverlayScene.kt+class:androidx.navigation3.scene.OverlayScene) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation3#1.0.0) Common/All
- Cmn

  ```
  interface OverlayScene<T : Any> : Scene<T>
  ```

*** ** * ** ***

A specific scene to render 1 or more `https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry` instances as an overlay.

It is expected that the `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene#content()` is rendered in one or more separate windows (e.g., a dialog, popup window, etc.) that are visible above any additional `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene` instances calculated from the `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/OverlayScene#overlaidEntries()`.

When processing `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/OverlayScene#overlaidEntries()`, expect processing of each `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/SceneStrategy` to restart from the first strategy. This may result in multiple instances of the same `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/OverlayScene` to be shown simultaneously, making a unique `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene#key()` even more important.

**Important** Implementations of this interface should either be data classes, or implement equals and hashcode to ensure that the same `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene` is used when appropriate.

## Summary

| ### Public functions |
|---|---|---|
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/OverlayScene#onRemove()()` Callback that is invoked after this `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/OverlayScene` is popped from the backStack, but before it leaves composition. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry<T>>` | `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/OverlayScene#overlaidEntries()` The `https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry`s that should be handled by another `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene` that sits below this Scene. | Cmn |

### Inherited properties

From [androidx.navigation3.scene.Scene](https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene) `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene#content()`

The content rendering the `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene` itself.
Cmn `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry<T>>` `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene#entries()`

The list of `https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry`s that can be displayed in this scene.
Cmn `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene#key()`

The key identifying the `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene`.
Cmn `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html>` `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene#metadata()`

Provide `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene`-specific information to `https://developer.android.com/reference/kotlin/androidx/navigation3/ui/NavDisplay`.
Cmn `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry<T>>` `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene#previousEntries()`

The resulting `https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry`s that should be computed after pressing back updates the backstack.
Cmn

## Public functions

### onRemove

Cmn Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/navigation3#1.1.0)

```
open suspend fun onRemove(): Unit
```

Callback that is invoked after this `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/OverlayScene` is popped from the backStack, but before it leaves composition.

Animations for exiting overlays should be implemented within `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/OverlayScene#onRemove()`. This ensures that any suspending animations or other suspending work completes before the overlay is removed from composition.

```kotlin
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() },
    sceneStrategies = listOf(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")
                    }
                }
            }
        },
)
```

## Public properties

### overlaidEntries

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigation3#1.0.0)

```
val overlaidEntries: List<NavEntry<T>>
```

The `https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry`s that should be handled by another `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/Scene` that sits below this Scene.

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

In general the default value for this should be the same as `https://developer.android.com/reference/kotlin/androidx/navigation3/scene/OverlayScene#previousEntries()`.