Files
coco 723ce1af5c a
2026-07-03 15:12:48 +08:00

819 B

Android ViewModel

class PostListScreen : Screen {

    @Composable
    override fun Content() {
        val viewModel = viewModel<PostListViewModel>()
        // ...
    }
}

By default Voyager provides its own LocalViewModelStoreOwner and LocalSavedStateRegistryOwner, that way you can safely create ViewModels without depending on Activity or Fragment.

!!! info Voyager provides a similar implementation, the ScreenModel, which does the same as ViewModel but also works with Compose Multiplatform.

Sample

!!! info Source code here.