Hello, I have a question regarding this code sampl...
# compose
a
Hello, I have a question regarding this code sample, when using bottom navigation routes with the new navigation type safe apis in compose, is this still relavant?
In this sample, when i try to use hasRoute(destination::class) i need to annotate with @RastrictedApi
how do you get the current route from a list of routes, is there a new way of doing this?
i
There's no restricted APIs being used in that example, so it sounds like how you are building your list of classes incorrectly. You don't use string routes at all, but KClass or, like this example uses, actual instances (which works well since you should really be using nested navigation graphs (which never have arguments) with bottom nav)
a
Copy code
sealed class BottomBarDestination(val label: String, val icon: Int) {
    data object Inspections : BottomBarDestination(
        label = "Inspektimet",
        icon = R.drawable.document_validation_stroke_rounded
    )

    data object Profile : BottomBarDestination(
        label = "Profili",
        icon = R.drawable.user_square_stroke_rounded
    )
}

@Stable
val bottomBarDestinations = listOf(
    BottomBarDestination.Inspections to CompletedFormsRoute,
    BottomBarDestination.Profile to ProfileScreenRoute
)
This is the list of my bottom bar routes
and this is how i check if it the current selected destination
Copy code
selected = currentDestination?.hierarchy?.any { it.hasRoute(destination::class) } == true,
as in the example
i
Can you click into the method that it thinks you are using and include the entire definition of the method? The KClass one (the one that this should be using) should not be restricted
a
this is where I am referenced to
I am on the latest available version of the lib
i
None of those are restricted, as you can see
a
Alright, I think i found why the IDE was throwing that error
I just turned off K2 mode
and it went away...
I assumed InternalSerializationApi meant I was restricted of using it
i
Very interesting 🤔
No, that has nothing to do with restricted APIs
1
Just means we are using Serialization APIs (none of which are technically stable)
a
no warning is thrown without K2 mode on, I am guessing the problem lies deeper within
Anyways, not sure if I should report this somewhere or not
Thanks for your support Ian
i
Worth filing an issue against Navigation and we can bring it up with the Kotlin team: https://issuetracker.google.com/issues/new?component=409828&template=1093757
1
a
Alright, will do! Thank you