# NavEntryDecorator

# NavEntryDecorator

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/navigation3/runtime/NavEntryDecorator "View this page in Java")
Common/AllAndroid/JVM
  - Cmn  

  ```
  open class NavEntryDecorator<T : Any>
```  
Known direct subclasses  
[SaveableStateHolderNavEntryDecorator](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/SaveableStateHolderNavEntryDecorator),[ViewModelStoreNavEntryDecorator](https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/navigation3/ViewModelStoreNavEntryDecorator)  

|------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SaveableStateHolderNavEntryDecorator](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/SaveableStateHolderNavEntryDecorator)   | Wraps the content of a[NavEntry](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry)with a[SaveableStateHolder.SaveableStateProvider](https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/SaveableStateHolder#SaveableStateProvider(kotlin.Any,kotlin.Function0))to ensure that calls to[rememberSaveable](https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/package-summary#rememberSaveable(kotlin.Array,androidx.compose.runtime.saveable.Saver,kotlin.String,kotlin.Function0))within the content work properly and that state can be saved. |
| [ViewModelStoreNavEntryDecorator](https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/navigation3/ViewModelStoreNavEntryDecorator) | Provides the content of a[NavEntry](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry)with a[ViewModelStoreOwner](https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner)and provides that[ViewModelStoreOwner](https://developer.android.com/reference/kotlin/androidx/lifecycle/ViewModelStoreOwner)as a[LocalViewModelStoreOwner](https://developer.android.com/reference/kotlin/androidx/lifecycle/viewmodel/compose/LocalViewModelStoreOwner)so that it is available within the content.                                                                                |

*** ** * ** ***

Decorate the[NavEntry](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry)s that are integrated with a[rememberDecoratedNavEntries](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/package-summary#rememberDecoratedNavEntries(kotlin.collections.List,kotlin.collections.List,kotlin.Function1)).

**HOW TO USE**Primary usages include but are not limited to:

1. provide information to entries with[androidx.compose.runtime.CompositionLocal](https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocal), i.e.

```kotlin
val decorator = NavEntryDecorator<Any> { entry ->
   ...
   CompositionLocalProvider(LocalMyStateProvider provides myState) {
       entry.content.invoke(entry.key)
   }
}
```

1. Wrap entry content with other composable content

```kotlin
val decorator = NavEntryDecorator<Any> { entry ->
   ...
   MyComposableFunction {
       entry.content.invoke(entry.key)
   }
}
```

**REUSABILITY**To enhance reusability, the NavEntryDecorator can be returned by a function or subclassed:  

```kotlin
// a reusable function
fun <T : Any> myDecorator(val myState: MyState): NavEntryDecorator<T> =
    NavEntryDecorator(onPop = { contentKey ->  myState.clear(contentKey) }) { entry ->
          myState.storeState(entry.contentKey)
          entry.Content()
    }

// or subclass NavEntryDecorator
class MyDecorator(
     val myState: MyState
): NavEntryDecorator(
     onPop = { contentKey ->  myState.clear(contentKey) },
     decorate = { entry ->
         myState.storeState(entry.contentKey)
         entry.Content()
     }
)
```  

|                                      Parameters                                       |
|---------------------------------------------------------------------------------------|-------------------------------|
| `<T : `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`>` | the type of the backStack key |

|                                                    See also                                                     |
|-----------------------------------------------------------------------------------------------------------------|---|
| [contentKey](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry#contentKey()) |   |

## Summary

|                                                                                                                                                                                                                                                                                                                                                                           ### Public constructors                                                                                                                                                                                                                                                                                                                                                                            |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| `<T : `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`> `[NavEntryDecorator](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntryDecorator#NavEntryDecorator(kotlin.Function1,kotlin.Function1))`(` ` onPop: (key: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`,` ` decorate: @`[Composable](https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable)` (entry: `[NavEntry](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry)`<T>) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) `)` | Cmn |

## Public constructors

### NavEntryDecorator

Cmn  

```
<T : Any> NavEntryDecorator(
    onPop: (key: Any) -> Unit = {},
    decorate: @Composable (entry: NavEntry<T>) -> Unit
)
```  

|                                                                                                                                                    Parameters                                                                                                                                                     |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `<T : `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`>`                                                                                                                                                                                                                             | the type of the backStack key                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `onPop: (key: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` = {}`                                                                                                                           | the callback to clean up the decorator state associated with a[NavEntry.contentKey](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry#contentKey())when the last[NavEntry](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry)with that contentKey has been popped from the backStack. It provides the[NavEntry.contentKey](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry#contentKey())of the popped entry as input. This callback is invoked if and only if all these conditions are met: 1. A[NavEntry](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry)has been popped from the backStack 2. The[NavEntry](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry)that has been popped is the last entry on the backStack with that particular[NavEntry.contentKey](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry#contentKey())3. The[NavEntry.content](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry#content())of the popped NavEntry has left composition |
| `decorate: @`[Composable](https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable)` (entry: `[NavEntry](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry)`<T>) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | the composable function to decorate a[NavEntry](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry). Note that this function only gets invoked for NavEntries that are actually getting rendered (i.e. by invoking the[NavEntry.content](https://developer.android.com/reference/kotlin/androidx/navigation3/runtime/NavEntry#content()).)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |