Skip to content

Commit

Permalink
Merge pull request #111 from ryanmoelter/expose-current-navigable
Browse files Browse the repository at this point in the history
Expose the current navigable in ComposeNavigator
  • Loading branch information
ryanmoelter authored Jan 30, 2024
2 parents ffb7ac0 + 44d1d05 commit fc6587d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.ryanmoelter.magellanx.core.Displayable
import com.ryanmoelter.magellanx.core.Navigable
import com.ryanmoelter.magellanx.core.lifecycle.LifecycleAwareComponent
import com.ryanmoelter.magellanx.core.lifecycle.LifecycleLimit
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map

Expand All @@ -41,11 +42,12 @@ public open class ComposeNavigator :
/**
* Get a snapshot of the current navigable, i.e. the last item of the current [backStack].
*/
private val currentNavigable
public val currentNavigable: Navigable<@Composable () -> Unit>?
get() = backStack.lastOrNull()?.navigable

private val currentNavigationEventFlow = backStackFlow.map { it.lastOrNull() }
private val currentNavigableFlow = currentNavigationEventFlow.map { it?.navigable }
public val currentNavigableFlow: Flow<Navigable<@Composable () -> Unit>?> =
currentNavigationEventFlow.map { it?.navigable }

// TODO: make default transition configurable
private val transitionFlow: MutableStateFlow<MagellanComposeTransition> =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ryanmoelter.magellanx.test

import androidx.compose.runtime.Composable
import com.ryanmoelter.magellanx.compose.navigation.ComposeNavigationEvent
import com.ryanmoelter.magellanx.compose.navigation.ComposeNavigator
import com.ryanmoelter.magellanx.compose.navigation.Direction
Expand All @@ -15,12 +14,6 @@ import com.ryanmoelter.magellanx.core.navigation.LinearNavigator
public class FakeComposeNavigator : ComposeNavigator() {
public override var backStack: List<ComposeNavigationEvent> = emptyList()

/**
* The [Navigable] that's currently on the top of the [backStack]
*/
public val currentNavigable: Navigable<@Composable () -> Unit>?
get() = backStack.lastOrNull()?.navigable

/**
* Clear this navigator for the next test. [destroy] will do the same thing, and it's also safe to
* leave this object to be garbage collected instead.
Expand Down

0 comments on commit fc6587d

Please sign in to comment.