|
|
@ -18,6 +18,8 @@ package com.google.samples.apps.nowinandroid.ui
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.Stable
|
|
|
|
import androidx.compose.runtime.Stable
|
|
|
|
|
|
|
|
import androidx.compose.runtime.collectAsState
|
|
|
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
|
import androidx.navigation.NavController
|
|
|
|
import androidx.navigation.NavController
|
|
|
@ -25,7 +27,6 @@ import androidx.navigation.NavDestination
|
|
|
|
import androidx.navigation.NavDestination.Companion.hasRoute
|
|
|
|
import androidx.navigation.NavDestination.Companion.hasRoute
|
|
|
|
import androidx.navigation.NavGraph.Companion.findStartDestination
|
|
|
|
import androidx.navigation.NavGraph.Companion.findStartDestination
|
|
|
|
import androidx.navigation.NavHostController
|
|
|
|
import androidx.navigation.NavHostController
|
|
|
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
|
|
|
|
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
|
import androidx.navigation.navOptions
|
|
|
|
import androidx.navigation.navOptions
|
|
|
|
import androidx.tracing.trace
|
|
|
|
import androidx.tracing.trace
|
|
|
@ -83,9 +84,21 @@ class NiaAppState(
|
|
|
|
userNewsResourceRepository: UserNewsResourceRepository,
|
|
|
|
userNewsResourceRepository: UserNewsResourceRepository,
|
|
|
|
timeZoneMonitor: TimeZoneMonitor,
|
|
|
|
timeZoneMonitor: TimeZoneMonitor,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
private val previousDestination = mutableStateOf<NavDestination?>(null)
|
|
|
|
|
|
|
|
|
|
|
|
val currentDestination: NavDestination?
|
|
|
|
val currentDestination: NavDestination?
|
|
|
|
@Composable get() = navController
|
|
|
|
@Composable get() {
|
|
|
|
.currentBackStackEntryAsState().value?.destination
|
|
|
|
// Collect the currentBackStackEntryFlow as a state
|
|
|
|
|
|
|
|
val currentEntry = navController.currentBackStackEntryFlow
|
|
|
|
|
|
|
|
.collectAsState(initial = null)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fallback to previousDestination if currentEntry is null
|
|
|
|
|
|
|
|
return currentEntry.value?.destination.also { destination ->
|
|
|
|
|
|
|
|
if (destination != null) {
|
|
|
|
|
|
|
|
previousDestination.value = destination
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} ?: previousDestination.value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
val currentTopLevelDestination: TopLevelDestination?
|
|
|
|
val currentTopLevelDestination: TopLevelDestination?
|
|
|
|
@Composable get() {
|
|
|
|
@Composable get() {
|
|
|
|