Created
March 19, 2019 11:35
-
-
Save Nimrodda/ab010b7dbffe176e3c68cf9b69b98b16 to your computer and use it in GitHub Desktop.
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 ViewModelFactory @Inject constructor( | |
private val viewModelMap: MutableMap<Class<out ViewModel>, ViewModelAssistedFactory<out ViewModel>>, | |
owner: SavedStateRegistryOwner, | |
defaultArgs: Bundle? | |
) : AbstractSavedStateVMFactory(owner, defaultArgs) { | |
override fun <T : ViewModel?> create( | |
key: String, | |
modelClass: Class<T>, | |
handle: SavedStateHandle): T { | |
return viewModelMap[modelClass]?.create(handle) as? T | |
?: throw IllegalStateException("Unknown ViewModel class") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment