Hello, I hope it's the correct channel to ask this...
# compose
y
Hello, I hope it's the correct channel to ask this. I'm working with KMP Compose and the JB Navigation Library (Type safe) and facing an issue with
popUpTo
which doesn't pop anything from the Backstack. The navigation success but just adding it on top of the existing one. Any idea / Known bugs in this area?
k
make sure you use
popUpTo<destination>()
instead of
popUpTo(destination)
y
What's the difference? I tried this, but still the same behavior
k
because it is Type safe
y
There is an overload for type safe too as far as I know so it should be the same
k
if you use popUpTo(destination::class) then yes
anyway without a reproducer it is not possible to help you
y
I'm actually able to do this when calling it directly navController.navigate() but it's wrapped by a channel in which i'm sending the destination and a NavOptionsBuilder and calling the navController when receiving the event from the channel and in that case it doesn't work
Copy code
sealed interface NavigationAction {
    data class Navigate(
        val destination: Destination,
        val navOptions: NavOptionsBuilder.() -> Unit = {},
    ) : NavigationAction

    data object NavigateUp : NavigationAction
}
interface Navigator {
    val startDestination: Destination
    val navigationActions: Flow<NavigationAction>

    suspend fun navigate(
        destination: Destination,
        navOptions: NavOptionsBuilder.() -> Unit = {},
    )

    suspend fun navigateUp()
}

class DefaultNavigator(
    override val startDestination: Destination,
) : Navigator {
    private val _navigationActions = Channel<NavigationAction>()
    override val navigationActions = _navigationActions.receiveAsFlow()

    override suspend fun navigate(
        destination: Destination,
        navOptions: NavOptionsBuilder.() -> Unit
    ) {
        _navigationActions.send(
            NavigationAction.Navigate(
                destination = destination,
                navOptions = navOptions
            )
        )
    }

    override suspend fun navigateUp() {
        _navigationActions.send(NavigationAction.NavigateUp)
    }
}
k
y
I found the reason. There are 2 NavOptionsBuilder classed with different implementation. One file named NavOptionsBuilder.jb.kt and the other NavOptionsBuilder.kt and for some reason in the App.kt it calls the jb one and in the other place i'm calling it it calls the .kt one which doesn't do anything. Is there a way to remove the faulty one or force the ide to take the jb one? Edit: Now I see that the .kt is the expect and the other one is the actual. I don't understand why once I reach one and latter the other