Skip to content

Instantly share code, notes, and snippets.

@Zhuinden
Last active March 19, 2021 21:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zhuinden/4eab8d3875e90c1686d12a2272388c9b to your computer and use it in GitHub Desktop.
Save Zhuinden/4eab8d3875e90c1686d12a2272388c9b to your computer and use it in GitHub Desktop.
Hilt NavGraphViewModels utils
inline fun <reified T : ViewModel> Fragment.hiltNavGraphViewModels(@IdRes navGraphIdRes: Int) =
viewModels<T>(
ownerProducer = { findNavController().getBackStackEntry(navGraphIdRes) },
factoryProducer = { defaultViewModelProviderFactory } // TODO: FIX THIS. THIS ISN'T SUFFICIENT!!!
)
@AndroidEntryPoint
class CreateLoginCredentialsFragment : Fragment(R.layout.create_login_credentials_fragment) {
private val viewModel by hiltNavGraphViewModels<RegistrationViewModel>(R.id.registration_graph)
class RegistrationViewModel @ViewModelInject constructor(
private val authenticationManager: AuthenticationManager,
private val navigationDispatcher: NavigationDispatcher,
@Assisted private val savedStateHandle: SavedStateHandle
) : ViewModel() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment