Skip to content

Commit 5e67171

Browse files
Treehugger RobotGerrit Code Review
authored andcommitted
Merge "Apply owners and the graph as part of composition" into androidx-main
2 parents dffae20 + 47546f5 commit 5e67171

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHost.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,15 @@ public fun NavHost(
9797
val onBackPressedDispatcherOwner = LocalOnBackPressedDispatcherOwner.current
9898
val onBackPressedDispatcher = onBackPressedDispatcherOwner?.onBackPressedDispatcher
9999

100-
// on successful recompose we setup the navController with proper inputs
101-
// after the first time, this will only happen again if one of the inputs changes
102-
DisposableEffect(navController, lifecycleOwner, viewModelStoreOwner, onBackPressedDispatcher) {
103-
navController.setLifecycleOwner(lifecycleOwner)
104-
navController.setViewModelStore(viewModelStoreOwner.viewModelStore)
105-
if (onBackPressedDispatcher != null) {
106-
navController.setOnBackPressedDispatcher(onBackPressedDispatcher)
107-
}
108-
109-
onDispose { }
100+
// Setup the navController with proper owners
101+
navController.setLifecycleOwner(lifecycleOwner)
102+
navController.setViewModelStore(viewModelStoreOwner.viewModelStore)
103+
if (onBackPressedDispatcher != null) {
104+
navController.setOnBackPressedDispatcher(onBackPressedDispatcher)
110105
}
111106

112-
SideEffect { navController.graph = graph }
107+
// Then set the graph
108+
navController.graph = graph
113109

114110
val saveableStateHolder = rememberSaveableStateHolder()
115111

0 commit comments

Comments
 (0)