Skip to main content
Version: 0.15.0

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()
) { /* ... */ }