Skip to content

Commit

Permalink
Save state of start destination when navigating to route in Interests…
Browse files Browse the repository at this point in the history
… nested graph

Closes #1779
  • Loading branch information
anhtuannd committed Jan 9, 2025
1 parent a0f2786 commit 0b4736f
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.samples.apps.nowinandroid.feature.interests.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavOptions
import kotlinx.serialization.Serializable

Expand All @@ -29,5 +30,14 @@ fun NavController.navigateToInterests(
initialTopicId: String? = null,
navOptions: NavOptions? = null,
) {
navigate(route = InterestsRoute(initialTopicId), navOptions)
navigate(
route = InterestsRoute(initialTopicId),
navOptions = navOptions ?: androidx.navigation.navOptions {
// When navigating directly to TopicScreen route inside Interests nested graph, we need
// to save start destination state
popUpTo(this@navigateToInterests.graph.findStartDestination().id) {
saveState = true
}
},
)
}

0 comments on commit 0b4736f

Please sign in to comment.