I may need to file a bug report or it may somehow ...
# compose-android
j
I may need to file a bug report or it may somehow be on me, but I just noticed the oddest issue. When I include this arguments parameter in my
composable
of my NavGraph, it causes my BottomNavBar to reset to the base tab/route when I rotate the device, but if I take out these arguments the rotation doesn't affect the BottomNavBar at all 🤔. It is also affecting completely unrelated tabs and routes too, anywhere I rotate it sends me back to my home route, like it's destroying the graph state
Copy code
arguments = listOf(navArgument(BuildsNavigation.ItemList.initialItemIdsArg) {
      this.type = NavType.LongArrayType
      this.defaultValue = LongArray(0)
    }),
So looking into it further and doing some process of elimination, if I remove the line with default value it works fine, but the presence of that default value breaks it. I also converted it to
emptyArray<Long>()
to see if maybe my usage of LongArray was causing it but it just seems to be if I assign a default value it is breaking my graph entirely
a
It could be your lambda instance is getting recreated and then your BotttomBarState is getting reset. If you can remember your creation of values then that can prevent that issue
j
Okay after some digging, I noticed that the NavDestinations
equal
ended up not being equal for this route when some logic was comparing it, because of the referential equality, so I wonder if that's the issue. I did pull out the default array so it only uses the one referenced array across calls and that fixes it. Thanks Atul for the comment, I don't think the lambda was the issue but specifically the defaultValue. I ended up switching to a string of items joined together after I first discovered this. But now I'm curious if we're not supposed to be using a
NavType.LongArrayType
since a default value for a non-primitive breaks the graph
a
Can you use
longArrayOf(0)
it creates array of primitive long(but not sure if
defaultValue
will take that or not)