11package com.huanshankeji.androidx.navigation.compose
22
33import androidx.compose.runtime.*
4+ import androidx.lifecycle.ViewModelStore
5+ import androidx.lifecycle.ViewModelStoreOwner
46import androidx.navigation.*
57import com.huanshankeji.compose.foundation.layout.Box
68import com.huanshankeji.compose.foundation.layout.fillMaxSize
@@ -10,10 +12,11 @@ import com.huanshankeji.compose.ui.Modifier
1012// copied and adapted from "NavHost.kt" in `androidx.navigation.compose`
1113
1214
13- /*
14- private class ComposeViewModelStoreOwner: ViewModelStoreOwner {
15+ private class ComposeViewModelStoreOwner : ViewModelStoreOwner {
1516 override val viewModelStore: ViewModelStore = ViewModelStore ()
16- fun dispose() { viewModelStore.clear() }
17+ fun dispose () {
18+ viewModelStore.clear()
19+ }
1720}
1821
1922@Composable
@@ -24,9 +27,6 @@ private fun rememberViewModelStoreOwner(): ViewModelStoreOwner {
2427 }
2528 return viewModelStoreOwner
2629}
27- */
28-
29-
3030
3131@Composable
3232actual fun NavHost (
@@ -56,9 +56,9 @@ actual fun NavHost(
5656) {
5757
5858 // val lifecycleOwner = LocalLifecycleOwner.current
59- // val viewModelStoreOwner = LocalViewModelStoreOwner.current ?: rememberViewModelStoreOwner()
59+ val viewModelStoreOwner = /* LocalViewModelStoreOwner.current ?:*/ rememberViewModelStoreOwner()
6060
61- // navController.setViewModelStore(viewModelStoreOwner.viewModelStore)
61+ navController.setViewModelStore(viewModelStoreOwner.viewModelStore)
6262
6363 // Then set the graph
6464 navController.graph = graph
@@ -110,7 +110,7 @@ actual fun NavHost(
110110 // ViewModelStoreOwner and LifecycleOwner
111111 currentEntry?.LocalOwnersProvider(saveableStateHolder) {
112112 (currentEntry.destination as ComposeNavigator.Destination)
113- .content( currentEntry)
113+ .content(currentEntry)
114114 }
115115 */
116116 currentEntry?.let {
0 commit comments