Skip to content

Commit 0ba881e

Browse files
committed
Review "NavHost.js.kt" comparing it to the original "NavHost.kt", and try adding back some code related to viewModelStoreOwner
1 parent 8d7a18f commit 0ba881e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

navigation/src/jsMain/kotlin/com/huanshankeji/androidx/navigation/compose/NavHost.js.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.huanshankeji.androidx.navigation.compose
22

33
import androidx.compose.runtime.*
4+
import androidx.lifecycle.ViewModelStore
5+
import androidx.lifecycle.ViewModelStoreOwner
46
import androidx.navigation.*
57
import com.huanshankeji.compose.foundation.layout.Box
68
import 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
3232
actual 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

Comments
 (0)