Last active
May 8, 2023 17:40
-
-
Save tfcporciuncula/ef080b17eff6a0dba6e639333bf7f587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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