FragmentViewModelContext

data class FragmentViewModelContext(activity: ComponentActivity, args: Any?, fragment: Fragment, owner: ViewModelStoreOwner, savedStateRegistry: SavedStateRegistry) : ViewModelContext

The ViewModelContext for a ViewModel created with a fragment scope (val viewModel by fragmentViewModel<MyViewModel>).

The owner and savedStateRegistry default to the Fragment as the provider, if you need to use an alternative source for the ViewModelStoreOwner and/or SavedStateRegistry; such in the case of JetPack Navigation Component destinations with ViewModels, then you can provided them via this context.

Constructors

FragmentViewModelContext
Link copied to clipboard
fun FragmentViewModelContext(activity: ComponentActivity, args: Any?, fragment: Fragment, owner: ViewModelStoreOwner = fragment, savedStateRegistry: SavedStateRegistry = fragment.savedStateRegistry)

Functions

activity
Link copied to clipboard
fun <A : ComponentActivity> activity(): A

Convenience method to type activity.

app
Link copied to clipboard
fun <A : Application> app(): A

Convenience method to access a typed Application.

args
Link copied to clipboard
fun <A> args(): A

Convenience method to type args.

fragment
Link copied to clipboard
fun <F : Fragment> fragment(): F

Convenience method to type fragment.

Properties

activity
Link copied to clipboard
open override val activity: ComponentActivity

The activity which is using the ViewModel.

args
Link copied to clipboard
open override val args: Any?

Fragment arguments set via Mavericks.KEY_ARG.

fragment
Link copied to clipboard
val fragment: Fragment

The fragment owner of the ViewModel.