title: How to do Assisted Injection with Navigation Compose?
body: <p>I've a composable called <code>ParentScreen</code> and a <code>ViewModel</code> named <code>ParentViewModel</code>. Inside the <code>ParentViewModel</code>, I am collecting a value from my repo.</p>
  <pre class="lang-kotlin prettyprint-override"><code>class MyRepo @Inject constructor() {
      fun getParentData() = System.currentTimeMillis().toString() // some dummy value
  }
  
  @HiltViewModel
  class ParentViewModel @Inject constructor(
      myRepo: MyRepo
  ) : ViewModel() {
      private val _parentData = MutableStateFlow(&quot;&quot;)
      val parentData = _parentData.asStateFlow()
  
      init {
          val realData = myRepo.getParentData()
          _parentData.value = realData
      }
  }
  
  @Composable
  fun ParentScreen(
      parentViewModel: ParentViewModel = hiltViewModel()
  ) {
      val parentData by parentViewModel.parentData.collectAsState()
      ChildWidget(parentData = parentData)
  }
  </code></pre>
  <p>Inside the <code>ParentScreen</code> composable, I have a <code>ChildWidget</code> composable and it has its own <code>ViewModel</code> named <code>ChildViewModel</code>.</p>
  <pre class="lang-kotlin prettyprint-override"><code>@HiltViewModel
  class ChildViewModel @AssistedInject constructor(
      @Assisted val parentData: String
  ) : ViewModel() {
  
      @AssistedFactory
      interface ChildViewModelFactory {
          fun create(parentData: String): ChildViewModel
      }
  
      init {
          Timber.d(&quot;Child says data is $parentData &quot;)
      }
  }
  
  @Composable
  fun ChildWidget(
      parentData: String,
      childViewModel: ChildViewModel = hiltViewModel() // How do I supply assisted injection factory here?
  ) {
      // Code omitted
  }
  </code></pre>
  <p>Now, I want to get <code>parentData</code> inside <code>ChildViewModel</code>'s constructor.</p>
  <p><strong>Questions</strong></p>
  <ul>
  <li>How do I supply <code>ChildViewModelFactory</code> to Navigation Compose's <code>hiltViewModel</code> method?</li>
  <li>If that's not possible, what would be the most suitable method to inject an object from the parent composable to the child composable's <code>ViewModel</code>? How about creating a <code>lateinit</code> property and <code>init</code> method like below?</li>
  </ul>
  <pre class="lang-kotlin prettyprint-override"><code>@HiltViewModel
  class ChildViewModel @Inject constructor(
  ) : ViewModel() {
      lateinit var parentData: Long
  
      fun init(parentData: Long){
          if(this::parentData.isInitialized) return
          this.parentData = parentData
      }
  }
  </code></pre>