Skip to content

Instantly share code, notes, and snippets.

@cbeyls
Last active January 1, 2022 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbeyls/7774eb41f42c755112d69ce2c472d4aa to your computer and use it in GitHub Desktop.
Save cbeyls/7774eb41f42c755112d69ce2c472d4aa to your computer and use it in GitHub Desktop.
Extension to add a CompositeLifecycleOwner property to a ViewModel
package androidx.lifecycle
import be.digitalia.utils.CompositeLifecycleOwner
private const val VIEW_LIFECYCLE_KEY = "androidx.lifecycle.VIEW_LIFECYCLE"
val ViewModel.lifecycleOwner: CompositeLifecycleOwner
get() {
return getTag(VIEW_LIFECYCLE_KEY)
?: setTagIfAbsent(VIEW_LIFECYCLE_KEY, CompositeLifecycleOwner())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment