Skip to content

by tangleViewModel in a Fragment attempts to initialize eagerly (and crashes) #227

@RBusarow

Description

@RBusarow

This is a regression in 0.12.0, and clearly isn't handled by any existing tests.

I removed a layer of lazy { ... } from the by tangleViewModel delegate, making this:

public inline fun <reified VM : ViewModel> Fragment.tangleViewModel(): Lazy<VM> {

  // this is done eagerly
  val viewModelFactory = TangleViewModelFactory(
    owner = this,
    defaultArgs = arguments,
    defaultFactory = defaultViewModelProviderFactory
  )

  // still Lazy
  return ViewModelLazy(VM::class, { viewModelStore }, { viewModelFactory })
}

The actual ViewModel being returned is still lazy, but the eager piece of code is being executed before the Fragment is attached, which causes a crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions