Skip to content

Commit a98e6bc

Browse files
committed
Try a different approach in making the nav graph unique by using a unique_instance argument
1 parent 595359d commit a98e6bc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

turbo/src/main/kotlin/dev/hotwire/turbo/nav/TurboNavGraphBuilder.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ internal class TurboNavGraphBuilder(
3838
registeredActivities: List<KClass<out AppCompatActivity>>,
3939
registeredFragments: List<KClass<out Fragment>>
4040
): NavGraph {
41-
// Use a random number to start the nav graph, so the graph is unique every time
42-
// and it can be reset/recreated on-demand. Updating an existing nav graph with
43-
// an identical one would bypass recreating the nav stack from scratch.
44-
var currentRoute = Random.nextInt()
41+
var currentRoute = 1
4542

4643
val activityDestinations = registeredActivities.map {
4744
ActivityDestination(
@@ -95,6 +92,15 @@ internal class TurboNavGraphBuilder(
9592
argument("location") {
9693
defaultValue = startLocation
9794
}
95+
96+
// Use a random number to represent a unique instance of the graph, so the
97+
// graph is unique every time. This lets it be reset/recreated on-demand from
98+
// `TurboSessionNavHostFragment.reset()`. Replacing an existing nav graph with
99+
// an identical one would bypass recreating the nav stack from scratch in
100+
// `NavController.setGraph()`.
101+
argument("unique_instance") {
102+
defaultValue = Random.nextInt()
103+
}
98104
}
99105
}
100106

0 commit comments

Comments
 (0)