Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 887 Bytes

File metadata and controls

31 lines (22 loc) · 887 Bytes
title sidebar_label
Compose
Compose

Tangle supports ViewModel "injection" in composables in a manner very similar to Hilt's navigation/viewModel artifact. It will scope the ViewModel to the composable's NavBackStackEntry.

The viewModels are still able to make use of automatic SavedStateHandle injection, including arguments annotated with @TangleParam.

import androidx.compose.runtime.Composable
import androidx.navigation.NavController
import tangle.viewmodel.compose.tangleViewModel

@Composable
fun MyComposable(
  navController: NavController,
  viewModel: MyViewModel = tangleViewModel()
) { /* ... */ }