Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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