Skip to content

Commit

Permalink
Use NiaNavigator to add and navigate to ForYou screen
Browse files Browse the repository at this point in the history
  • Loading branch information
adityabhaskar committed Dec 3, 2024
1 parent fe4ff49 commit d021b97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.BookmarksNavigator
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouBaseRoute
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.forYouSection
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouNavigator
import com.google.samples.apps.nowinandroid.feature.interests.navigation.navigateToInterests
import com.google.samples.apps.nowinandroid.feature.search.navigation.searchScreen
import com.google.samples.apps.nowinandroid.feature.topic.navigation.navigateToTopic
Expand Down Expand Up @@ -49,15 +49,21 @@ fun NiaNavHost(
startDestination = ForYouBaseRoute,
modifier = modifier,
) {
forYouSection(
onTopicClick = navController::navigateToTopic,
) {
topicScreen(
showBackButton = true,
onBackClick = navController::popBackStack,
appState.navigatorProvider.get(ForYouNavigator::class.java).screen(
navGraphBuilder = this,
navController = navController,
actions = ForYouNavigator.Actions(
onTopicClick = navController::navigateToTopic,
)
}
topicDestination = {
topicScreen(
showBackButton = true,
onBackClick = navController::popBackStack,
onTopicClick = navController::navigateToTopic,
)
},
),
properties = Unit,
)
appState.navigatorProvider.get(BookmarksNavigator::class.java).screen(
navGraphBuilder = this,
navController = navController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import com.google.samples.apps.nowinandroid.core.navigation.NiaNavigatorProvider
import com.google.samples.apps.nowinandroid.core.ui.TrackDisposableJank
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.BookmarksNavigator
import com.google.samples.apps.nowinandroid.feature.bookmarks.navigation.BookmarksRoute
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.navigateToForYou
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouBaseRoute
import com.google.samples.apps.nowinandroid.feature.foryou.navigation.ForYouNavigator
import com.google.samples.apps.nowinandroid.feature.interests.navigation.navigateToInterests
import com.google.samples.apps.nowinandroid.feature.search.navigation.navigateToSearch
import com.google.samples.apps.nowinandroid.navigation.TopLevelDestination
Expand Down Expand Up @@ -161,8 +162,13 @@ class NiaAppState(
}

when (topLevelDestination) {
FOR_YOU -> navController.navigateToForYou(topLevelNavOptions)

FOR_YOU -> navigatorProvider.get(ForYouNavigator::class.java)
.navigateToRoute(
navController = navController,
route = ForYouBaseRoute,
navOptions = topLevelNavOptions,
)

BOOKMARKS -> navigatorProvider.get(BookmarksNavigator::class.java)
.navigateToRoute(
navController = navController,
Expand Down

0 comments on commit d021b97

Please sign in to comment.