Created
August 2, 2021 05:35
-
-
Save thegarlynch/cda51b493f55e484d04c049553fb6c2e to your computer and use it in GitHub Desktop.
Parent Fragment ViewModel Access
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
import androidx.fragment.app.Fragment | |
import androidx.fragment.app.viewModels | |
import androidx.lifecycle.ViewModel | |
import androidx.lifecycle.ViewModelStoreOwner | |
inline fun <reified VM : ViewModel> Fragment.parentViewModel() : Lazy<VM>{ | |
return viewModels( | |
ownerProducer = { | |
parentFragmentManager as ViewModelStoreOwner | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment