|
|
@ -40,20 +40,20 @@ import androidx.navigation.compose.NavHost
|
|
|
|
import androidx.navigation.compose.composable
|
|
|
|
import androidx.navigation.compose.composable
|
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.interests.InterestsRoute
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.interests.InterestsRoute
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.interests.navigation.InterestsDestination
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.interests.navigation.InterestsRoute
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.topic.TopicDetailPlaceholder
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.topic.TopicDetailPlaceholder
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.topic.navigation.TopicDestination
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.topic.navigation.TopicRoute
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.topic.navigation.navigateToTopic
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.topic.navigation.navigateToTopic
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicScreen
|
|
|
|
import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicScreen
|
|
|
|
import kotlinx.serialization.Serializable
|
|
|
|
import kotlinx.serialization.Serializable
|
|
|
|
import java.util.UUID
|
|
|
|
import java.util.UUID
|
|
|
|
|
|
|
|
|
|
|
|
@Serializable object TopicPlaceholderDestination
|
|
|
|
@Serializable internal object TopicPlaceholderRoute
|
|
|
|
|
|
|
|
|
|
|
|
@Serializable object DetailPaneNavHostDestination
|
|
|
|
@Serializable internal object DetailPaneNavHostRoute
|
|
|
|
|
|
|
|
|
|
|
|
fun NavGraphBuilder.interestsListDetailScreen() {
|
|
|
|
fun NavGraphBuilder.interestsListDetailScreen() {
|
|
|
|
composable<InterestsDestination> {
|
|
|
|
composable<InterestsRoute> {
|
|
|
|
InterestsListDetailScreen()
|
|
|
|
InterestsListDetailScreen()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -87,9 +87,9 @@ internal fun InterestsListDetailScreen(
|
|
|
|
listDetailNavigator.navigateBack()
|
|
|
|
listDetailNavigator.navigateBack()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var nestedNavHostStartDestination by remember {
|
|
|
|
var nestedNavHostStartRoute by remember {
|
|
|
|
val destination = selectedTopicId?.let { TopicDestination(id = it) } ?: TopicPlaceholderDestination
|
|
|
|
val route = selectedTopicId?.let { TopicRoute(id = it) } ?: TopicPlaceholderRoute
|
|
|
|
mutableStateOf(destination)
|
|
|
|
mutableStateOf(route)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var nestedNavKey by rememberSaveable(
|
|
|
|
var nestedNavKey by rememberSaveable(
|
|
|
|
stateSaver = Saver({ it.toString() }, UUID::fromString),
|
|
|
|
stateSaver = Saver({ it.toString() }, UUID::fromString),
|
|
|
@ -106,11 +106,11 @@ internal fun InterestsListDetailScreen(
|
|
|
|
// If the detail pane was visible, then use the nestedNavController navigate call
|
|
|
|
// If the detail pane was visible, then use the nestedNavController navigate call
|
|
|
|
// directly
|
|
|
|
// directly
|
|
|
|
nestedNavController.navigateToTopic(topicId) {
|
|
|
|
nestedNavController.navigateToTopic(topicId) {
|
|
|
|
popUpTo<DetailPaneNavHostDestination>()
|
|
|
|
popUpTo<DetailPaneNavHostRoute>()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Otherwise, recreate the NavHost entirely, and start at the new destination
|
|
|
|
// Otherwise, recreate the NavHost entirely, and start at the new destination
|
|
|
|
nestedNavHostStartDestination = TopicDestination(id = topicId)
|
|
|
|
nestedNavHostStartRoute = TopicRoute(id = topicId)
|
|
|
|
nestedNavKey = UUID.randomUUID()
|
|
|
|
nestedNavKey = UUID.randomUUID()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
listDetailNavigator.navigateTo(ListDetailPaneScaffoldRole.Detail)
|
|
|
|
listDetailNavigator.navigateTo(ListDetailPaneScaffoldRole.Detail)
|
|
|
@ -132,15 +132,15 @@ internal fun InterestsListDetailScreen(
|
|
|
|
key(nestedNavKey) {
|
|
|
|
key(nestedNavKey) {
|
|
|
|
NavHost(
|
|
|
|
NavHost(
|
|
|
|
navController = nestedNavController,
|
|
|
|
navController = nestedNavController,
|
|
|
|
startDestination = nestedNavHostStartDestination,
|
|
|
|
startDestination = nestedNavHostStartRoute,
|
|
|
|
route = DetailPaneNavHostDestination::class,
|
|
|
|
route = DetailPaneNavHostRoute::class,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
topicScreen(
|
|
|
|
topicScreen(
|
|
|
|
showBackButton = !listDetailNavigator.isListPaneVisible(),
|
|
|
|
showBackButton = !listDetailNavigator.isListPaneVisible(),
|
|
|
|
onBackClick = listDetailNavigator::navigateBack,
|
|
|
|
onBackClick = listDetailNavigator::navigateBack,
|
|
|
|
onTopicClick = ::onTopicClickShowDetailPane,
|
|
|
|
onTopicClick = ::onTopicClickShowDetailPane,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
composable<TopicPlaceholderDestination> {
|
|
|
|
composable<TopicPlaceholderRoute> {
|
|
|
|
TopicDetailPlaceholder()
|
|
|
|
TopicDetailPlaceholder()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|