mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 18:47:03 +05:30
refactor: properly use TopLevelRoute
This commit is contained in:
parent
e011870986
commit
9c76617700
2 changed files with 21 additions and 4 deletions
|
@ -22,14 +22,33 @@ import io.github.aakira.napier.Napier
|
|||
* to the front while lists add behind. To counter these expectations with the actual backing data
|
||||
* structure, many APIs in this class inverse of identically named functions on [List].
|
||||
*/
|
||||
class ClawBackStack<T : NavKey>(startRoute: T) {
|
||||
class ClawBackStack<T : NavKey>(private val startRoute: T) {
|
||||
/**
|
||||
* Marker interface for routes that occupy the "top" level of the back stack.
|
||||
*
|
||||
* This is used by [dev.msfjarvis.claw.android.ui.navigation.ClawBackStack.add] to ensure that
|
||||
* duplicate instances of these routes do not end up in the back stack.
|
||||
*/
|
||||
interface TopLevelRoute
|
||||
|
||||
val backStack = mutableStateListOf(startRoute)
|
||||
|
||||
/** Pushes a new destination onto the stack. */
|
||||
/**
|
||||
* Pushes a new destination onto the stack.
|
||||
*
|
||||
* Top level routes are specially handled to ensure that the distance between the incoming [route]
|
||||
* and the [startRoute] cannot have anything in between. This prevents users from getting stuck in
|
||||
* a frustratingly long stack of top level destinations that are so easily accessible that they
|
||||
* have no reason to be on the stack.
|
||||
*/
|
||||
fun add(route: T) {
|
||||
logCurrentState("add")
|
||||
if (route is TopLevelRoute) {
|
||||
backStack.clear()
|
||||
if (route != startRoute) {
|
||||
backStack.add(startRoute)
|
||||
}
|
||||
}
|
||||
backStack.add(route)
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,6 @@ import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
|
|||
import dev.msfjarvis.claw.common.user.UserProfile
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.persistentMapOf
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
|
@ -131,7 +130,6 @@ fun Nav3Screen(
|
|||
coroutineScope.launch { if (savedPosts.isNotEmpty()) savedListState.scrollToItem(0) }
|
||||
},
|
||||
)
|
||||
val navDestinations = navItems.map(NavigationItem::destination).toPersistentList()
|
||||
// endregion
|
||||
|
||||
val postActions = remember {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue