Last active
March 19, 2021 21:59
-
-
Save Zhuinden/4eab8d3875e90c1686d12a2272388c9b to your computer and use it in GitHub Desktop.
Hilt NavGraphViewModels utils
This file contains hidden or 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
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!!! | |
) |
This file contains hidden or 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
@AndroidEntryPoint | |
class CreateLoginCredentialsFragment : Fragment(R.layout.create_login_credentials_fragment) { | |
private val viewModel by hiltNavGraphViewModels<RegistrationViewModel>(R.id.registration_graph) |
This file contains hidden or 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
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