Skip to content

Commit

Permalink
fix: Multiple backstack not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhenwinch committed Feb 16, 2024
1 parent e5135a3 commit 00bdd48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
19 changes: 14 additions & 5 deletions app/src/main/kotlin/com/flixclusive/mobile/MobileApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ import com.flixclusive.model.provider.SourceDataState
import com.flixclusive.util.AppNavHost
import com.flixclusive.util.currentScreenAsState
import com.flixclusive.util.navigateIfResumed
import com.flixclusive.util.navigateSingleTopTo
import com.ramcosta.composedestinations.dynamic.within
import com.ramcosta.composedestinations.navigation.navigate
import com.ramcosta.composedestinations.utils.currentDestinationFlow
import com.ramcosta.composedestinations.utils.startDestination
import kotlinx.coroutines.launch
import kotlin.system.exitProcess
import com.flixclusive.core.util.R as UtilR
Expand Down Expand Up @@ -141,10 +142,18 @@ internal fun MobileActivity.MobileApp(
navController.run {
val isPoppingToRoot = screen == currentNavGraph

navigateSingleTopTo(
direction = screen,
isPoppingToRoot = isPoppingToRoot
)
navigate(screen) {
if (isPoppingToRoot) {
popUpTo(screen.startRoute.route)
} else {
popUpTo(MobileNavGraphs.home.startDestination.route) {
saveState = true
}
}

launchSingleTop = true
restoreState = true
}
}
}
)
Expand Down
17 changes: 0 additions & 17 deletions app/src/main/kotlin/com/flixclusive/util/NavigationHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.NavOptionsBuilder
import com.flixclusive.ROOT
Expand All @@ -37,22 +36,6 @@ import com.ramcosta.composedestinations.navigation.navigate
import com.ramcosta.composedestinations.spec.Direction
import com.ramcosta.composedestinations.spec.NavGraphSpec

internal fun NavHostController.navigateSingleTopTo(
direction: NavGraphSpec,
isPoppingToRoot: Boolean = false,
) = navigate(direction) {
if (isPoppingToRoot) {
popUpTo(direction.startRoute.route)
} else {
popUpTo(graph.findStartDestination().id) {
saveState = true
}
}

launchSingleTop = true
restoreState = true
}

private fun NavBackStackEntry.lifecycleIsResumed() =
lifecycle.currentState == Lifecycle.State.RESUMED

Expand Down

0 comments on commit 00bdd48

Please sign in to comment.