Skip to content

Instantly share code, notes, and snippets.

@thegarlynch
Created August 2, 2021 05:35
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 thegarlynch/cda51b493f55e484d04c049553fb6c2e to your computer and use it in GitHub Desktop.
Save thegarlynch/cda51b493f55e484d04c049553fb6c2e to your computer and use it in GitHub Desktop.
Parent Fragment ViewModel Access
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