Skip to content

Instantly share code, notes, and snippets.

@CostaFot
Last active February 1, 2026 17:11
Show Gist options
  • Select an option

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

Select an option

Save CostaFot/443a48dc9687b9abe1ef0b4ec5051782 to your computer and use it in GitHub Desktop.
@EntryPoint
@InstallIn(ActivityComponent::class)
interface CustomRetainedViewModelEntryPoint {
fun customRetainedViewModel(): CustomRetainedViewModel
}
@Composable
fun rememberCustomRetainedViewModel(): CustomRetainedViewModel {
val context = LocalContext.current
return retain {
val entryPoint = EntryPoints.get(context, CustomRetainedViewModelEntryPoint::class.java)
entryPoint.customRetainedViewModel()
}
}
// compose layer
@Composable
fun FirstScreen() {
val customRetainedViewModel = rememberCustomRetainedViewModel()
val state by customRetainedViewModel.state.collectAsStateWithLifecycle()
// .... rest of the owl
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment