Skip to content

Instantly share code, notes, and snippets.

@CostaFot
Created March 4, 2026 12:09
Show Gist options
  • Select an option

  • Save CostaFot/e4367f90dff594d377904eba868bc954 to your computer and use it in GitHub Desktop.

Select an option

Save CostaFot/e4367f90dff594d377904eba868bc954 to your computer and use it in GitHub Desktop.
RetainDecorator.kt
class RetainDecorator<T : Any>(
retainedValuesStoreRegistry: RetainedValuesStoreRegistry,
) : NavEntryDecorator<T>(
decorate = { entry ->
logDebug { "Retaining ${entry.contentKey}" }
retainedValuesStoreRegistry.LocalRetainedValuesStoreProvider(entry.contentKey) {
entry.Content()
}
},
onPop = { contentKey ->
logDebug { "Popping $contentKey" }
retainedValuesStoreRegistry.clearChild(contentKey)
}
)
@Composable
fun rememberRetainDecorator(): RetainDecorator<Any> {
val retainedValuesStoreRegistry = retainRetainedValuesStoreRegistry()
return remember {
RetainDecorator(
retainedValuesStoreRegistry = retainedValuesStoreRegistry,
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment