Skip to content

Instantly share code, notes, and snippets.

@tfcporciuncula
Last active May 8, 2023 17:40
Embed
What would you like to do?
// In an activity:
private val presenter by retain { entry ->
// entry exposes the viewModelScope, savedStateHandle, and a way to listen to onClear()
MyPresenter()
}
// Or in a composable, implicitly:
val presenter = retain { MyPresenter() } // this will look at LocalViewModelStoreOwner.current
// Or explicitly:
val activity = ...
val presenter = retain (owner = activity) { MyPresenter() }
// In a Compose NavHost:
composable(route = "myRoute") { navBackStackEntry ->
val presenter = retain(navBackStackEntry) { MyPresenter() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment