Skip to content

The viewModel() method may be missing the postInvalidate() logic. #690

Description

@weijia1991

In activity by viewModel() is not working properly, the invalidate() method doesn't callback when the viewLifecycleOwner is started, viewModel() is missing the postInvalidate() logic like activityViewModel(), please tell me how should I do it in activity.
Can I modify the viewModel() code like this:

inline fun <T, reified VM : MavericksViewModel<S>, reified S : MavericksState> T.viewModel(
    viewModelClass: KClass<VM> = VM::class,
    crossinline keyFactory: () -> String = { viewModelClass.java.name }
): Lazy<VM> where T : ComponentActivity, T : MavericksView = lifecycleAwareLazy(this) {
    val lifecycleOwner = this
    MavericksViewModelProvider.get(
        viewModelClass = viewModelClass.java,
        stateClass = S::class.java,
        viewModelContext = ActivityViewModelContext(this, intent.extras?.get(Mavericks.KEY_ARG)),
        key = keyFactory()
    ).apply { _internal(lifecycleOwner, action = { lifecycleOwner.postInvalidate() }) }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions