Hi, I’m trying to update from 1.10.2 to 1.11.6 and...
# compose-destinations
a
Hi, I’m trying to update from 1.10.2 to 1.11.6 and I’m facing a some issue where I’m not really sure where to dig further. For some reason my code stopped working with the following exception.
Copy code
java.lang.IllegalArgumentException: navigation destination multi_step_checkout_screen is not a direct child of this NavGraph
Nothing else was changed and if go back to 1.10.2 it still works as expected. Here is the code in the MainActivity where i set the DestinationsNavHost according to whether the app was called with some paymentMetadata or not. I also only have one NavGraph defined. Code in the thread
Copy code
@OptIn(KoinExperimentalAPI::class)
@Composable
fun App(paymentMetadata: PaymentMetadata? = null) {
    KoinAndroidContext {
        WalletAppTheme {
            Surface(color = MaterialTheme.colorScheme.background) {
                val navHostEngine = rememberNavHostEngine(
                    rootDefaultAnimations = RootNavGraphDefaultAnimations.ACCOMPANIST_FADING,
                )

                if (paymentMetadata == null) {
                    DestinationsNavHost(
                        navGraph = NavGraphs.root,
                        engine = navHostEngine,
                    )
                } else {
                    DestinationsNavHost(
                        navGraph = NavGraphs.root,
                        engine = navHostEngine,
                        startRoute = MultiStepCheckoutScreenDestination,
                    ) {
                        composable(MultiStepCheckoutScreenDestination) {
                            MultiStepCheckoutScreen(paymentMetadata)
                        }
                    }
                }
            }
        }
    }
}
with this NavGraphs
Copy code
/**
 * Class generated if any Composable is annotated with `@Destination`.
 * It aggregates all [TypedDestination]s in their [NavGraph]s.
 */
public object NavGraphs {

    public val root: NavGraph = NavGraph(
        route = "root",
        startRoute = WelcomeScreenDestination,
        destinations = listOf(
          ChargeScreenDestination,
          WelcomeScreenDestination,
          CheckoutScreenDestination,
          MultiStepCheckoutScreenDestination
        )
    )
}
Anyone maybe has some idea what is going wrong here?
r
i bet you did gradle sync right? it happens to bug out and build mix old and new code when there are any changes and clean does not solves that out, you could try to move ur desrtination to a separate graph and set start destination to a graph which might help
a
Ah okay, might be the case that it was somehow mixed up. I did do sync ,“clean” and “kspDebugKotlin” multiple times … so not sure where it went wrong. I after banging my head against it for a while i tried 2.1.0-beta12 where this issue did not pop up anymore … 🤷 I guess i will leave it here.
🙌 1
r
At least in my experience, gradle sync, clean, build solves all issues (related to ksp or not). Very very rarely I might have to delete caches.
s
I faced the same issue, what I noticed is it is happening if I am using a Nav argument with no default values; Diff wise, in case when default value is not passed, it is appending it as path param and calling it as nested navigation. Also, have found related online threads where they mention similar thing like this this Full Diff here - https://www.diffchecker.com/Ef6YGPa0/
So, does it mean we should pass default values always?
r
No, I don’t think you should be concerned with routes when using compose destinations. I’m sure there’s something else going on here. Do you have multiple DestinationsNavHost calls?
s
Yeah, I have multiple DestinationsNavHost
r
Can you show me your NavGraphs generated Kotlin file?
Btw what you describe is totally expected. Mandatory arguments are sent in this way - it is not related with nested navigation at all.
Check this answer I wrote yesterday about a similar setup / issue
r
fyi there were some changes that changed behaviour of how it works for sure just because some people are starting to face the problem including me some time ago
r
At least I’m sure from my side the expected and correct setups will not just start having this issue all of a sudden 🙂
Can’t say the same for official library, but I’d be really surprised if that was not also the case.