Skip to content

Commit 4095805

Browse files
committed
refactor(navigation): Use contains for route matching
Updated the navigation logic to use `String.contains()` instead of `String.startsWith()` for matching destination routes. This makes the route matching more flexible, especially for routes that include arguments.
1 parent 2f6489f commit 4095805

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/app/navigation/NavigationUtils.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ fun NavBackStackEntry?.getCurrentScreen(): GithubStoreGraph? {
88
val route = destination.route ?: return null
99

1010
return when {
11-
route.startsWith("HomeScreen") -> GithubStoreGraph.HomeScreen
12-
route.startsWith("SearchScreen") -> GithubStoreGraph.SearchScreen
13-
route.startsWith("AuthenticationScreen") -> GithubStoreGraph.AuthenticationScreen
14-
route.startsWith("DetailsScreen") -> toRoute<GithubStoreGraph.DetailsScreen>()
15-
route.startsWith("DeveloperProfileScreen") -> toRoute<GithubStoreGraph.DeveloperProfileScreen>()
16-
route.startsWith("SettingsScreen") -> GithubStoreGraph.SettingsScreen
17-
route.startsWith("FavouritesScreen") -> GithubStoreGraph.FavouritesScreen
18-
route.startsWith("StarredReposScreen") -> GithubStoreGraph.StarredReposScreen
19-
route.startsWith("AppsScreen") -> GithubStoreGraph.AppsScreen
11+
route.contains("HomeScreen") -> GithubStoreGraph.HomeScreen
12+
route.contains("SearchScreen") -> GithubStoreGraph.SearchScreen
13+
route.contains("AuthenticationScreen") -> GithubStoreGraph.AuthenticationScreen
14+
route.contains("DetailsScreen") -> toRoute<GithubStoreGraph.DetailsScreen>()
15+
route.contains("DeveloperProfileScreen") -> toRoute<GithubStoreGraph.DeveloperProfileScreen>()
16+
route.contains("SettingsScreen") -> GithubStoreGraph.SettingsScreen
17+
route.contains("FavouritesScreen") -> GithubStoreGraph.FavouritesScreen
18+
route.contains("StarredReposScreen") -> GithubStoreGraph.StarredReposScreen
19+
route.contains("AppsScreen") -> GithubStoreGraph.AppsScreen
2020
else -> null
2121
}
2222
}

0 commit comments

Comments
 (0)