Last active
January 1, 2022 20:38
-
-
Save cbeyls/7774eb41f42c755112d69ce2c472d4aa to your computer and use it in GitHub Desktop.
Extension to add a CompositeLifecycleOwner property to a ViewModel
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
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