-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ActivityViewModelContext for activity scope #676
Conversation
@apramana How about this? val parentFragment = scope as? Fragment ?: if (scope !is Activity) findFragmentFromView(view) else null
if (parentFragment != null) {
val args = argsFactory?.invoke() ?: parentFragment.arguments?.get(Mavericks.KEY_ARG)
FragmentViewModelContext(activity, args, parentFragment)
} else {
val args = argsFactory?.invoke() ?: activity.intent.extras?.get(Mavericks.KEY_ARG)
ActivityViewModelContext(activity, args, viewModelStoreOwner, savedStateRegistry)
} |
Yeah I suppose scope could be a non-fragment/activity lifecycle owner... updated to use a when expression. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix @apramana - can you add a unit test?
Thanks! |
Thanks @rossbacher ! |
Fixes: #674
parentFragment should not get set if the scope is an activity.