Use navigation argument topicId as default value to InterestListDetailScreen

Change-Id: I659f729191bce00683b1621c360c8f36f00595f9
dt/nav-safe-args-android-dependency
Don Turner 7 months ago
parent 116e961f1b
commit 2264451bb8

@ -33,6 +33,7 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.NavHost 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 androidx.navigation.toRoute
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.InterestsDestination
import com.google.samples.apps.nowinandroid.feature.topic.TopicDetailPlaceholder import com.google.samples.apps.nowinandroid.feature.topic.TopicDetailPlaceholder
@ -45,20 +46,13 @@ import kotlinx.serialization.Serializable
@Serializable object DetailPaneNavHostDestination @Serializable object DetailPaneNavHostDestination
fun NavGraphBuilder.interestsListDetailScreen() { fun NavGraphBuilder.interestsListDetailScreen() {
composable<InterestsDestination> { composable<InterestsDestination> { backStackEntry ->
InterestsListDetailScreen() val topicIdArgument = backStackEntry.toRoute<InterestsDestination>().topicId
var topicId: String? by rememberSaveable { mutableStateOf(topicIdArgument) }
InterestsListDetailScreen(selectedTopicId = topicId, onTopicClick = { topicId = it })
} }
} }
@Composable
internal fun InterestsListDetailScreen() {
var selectedTopicId: String? by rememberSaveable { mutableStateOf(null) }
InterestsListDetailScreen(
selectedTopicId = selectedTopicId,
onTopicClick = { topicId -> selectedTopicId = topicId },
)
}
@OptIn(ExperimentalMaterial3AdaptiveApi::class) @OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable @Composable
internal fun InterestsListDetailScreen( internal fun InterestsListDetailScreen(

Loading…
Cancel
Save