diff --git a/404.html b/404.html new file mode 100644 index 00000000..792005ab --- /dev/null +++ b/404.html @@ -0,0 +1,901 @@ + + + +
+ + + + + + + + + + + + + + + + +Success
+To use the getViewModel
you should first import cafe.adriel.voyager:voyager-hilt
(see Setup).
Add @HiltViewModel
and @Inject
annotations to your ViewModel
.
@HiltViewModel
+class HomeViewModel @Inject constructor() : ViewModel() {
+ // ...
+}
+
Call getViewModel()
to get a new instance.
class HomeScreen : Screen {
+
+ @Composable
+ override fun Content() {
+ val screenModel = getViewModel<HomeScreenModel>()
+ // ...
+ }
+}
+
Currently there’s no Assisted Injection support for Hilt ViewModels (issue).
+Info
+Sample code here.
+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 ViewModel
s 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.
Info
+Source code here.
+Since 1.1.0-beta01 we have introduce a experimental API for ViewModel KMP. It is under the package cafe.adriel.voyager:voyager-lifecycle-kmp
(see Setup).
You will need to call ProvideNavigatorLifecycleKMPSupport
before all Navigator
calls and it will be working out of the box.
@Composable
+fun MainView() {
+ ProvideNavigatorLifecycleKMPSupport {
+ Navigator(...)
+ }
+}
+
+class MyScreen : Screen {
+ @Composable
+ fun Content() {
+ val myViewModel = viewModel { MyScreenViewModel() }
+ }
+}
+
Voyager 1.1.0-beta01 also have introduced the support for Navigator scoped ViewModel and Lifecycle. +This will make easy to share a ViewModel cross screen of the same navigator.
+class MyScreen : Screen {
+ @Composable
+ fun Content() {
+ val myViewModel = navigatorViewModel { MyScreenViewModel() }
+ }
+}
+
This version also brings the Lifecycle events for Screen lifecycle in KMP, now is possible to +a generic third party API that listen to Lifecycle of a Screen in KMP.
+ + + + + + + + + + + + + +