https://kotlinlang.org logo
#compose
Title
# compose
f

FunkyMuse

03/03/2021, 5:42 PM
java.lang.UnsupportedOperationException: Arrays don't support default values. Does anyone know why I can't pass StringArrayType in compose navigation?
i

Ian Lake

03/03/2021, 5:48 PM
Routes, the way of navigating between destinations, are like URIs. They don't support arrays or complex types. What are you trying to do?
f

FunkyMuse

03/03/2021, 5:48 PM
Trying to pass list/array of strings to a navigation composable
The string list/array consists of 5 dynamic URLs that i need to provide everytime i open that screen
i

Ian Lake

03/03/2021, 5:51 PM
Okay, so why 5 dynamic URLs?
f

FunkyMuse

03/03/2021, 5:51 PM
Because i have these 5 urls on the list screen and i want to have them in the details screen
And they're different for every list item
i

Ian Lake

03/03/2021, 5:52 PM
So every list item has 5 urls associated with it?
f

FunkyMuse

03/03/2021, 5:53 PM
True
i

Ian Lake

03/03/2021, 5:53 PM
So you should be passing the ID of the list item through your arguments, not the individual fields of the list item, same as if you were trying to pass a Parcelable
👍 1
f

FunkyMuse

03/03/2021, 5:53 PM
When i open the details, i call an API with the id as the first navigation (route) parameter passed to the navigation and these 5 URLs as a second parameter
Because in the details of the API i don't have these URLs
Limitations of the backend
i

Ian Lake

03/03/2021, 5:57 PM
It seems like the same approach suggested for Parcelables, or any complicated set of data, also applies here. Don't send all your content your arguments. https://kotlinlang.slack.com/archives/CJLTWPH7S/p1604087992002000?thread_ts=1604053414.451400&cid=CJLTWPH7S
g

Gabriel Melo

03/03/2021, 5:58 PM
Is there somewhere where you elaborate on the rationale behind this design choice, @Ian Lake? I don't quite understand the choice to stop supporting navigation with complex arguments.
i

Ian Lake

03/03/2021, 5:58 PM
You mean, like in that thread I just linked?
g

Gabriel Melo

03/03/2021, 5:59 PM
The thread says what to do, not really why. Unless I missed something.
I'll check it again.
But again, this seems more like an argument in favour of caching than against complex navigation arguments. It seems to me that this approach requires the new view to sort out its own dependencies instead of allowing the previous one provide them.
f

FunkyMuse

03/03/2021, 6:06 PM
Is there a possibility to obtain the view model holding the list somehow, like scope it to the previous backstack entry or something and just get the model with the id from that list?
i

Ian Lake

03/03/2021, 6:14 PM
Again, you have keep in mind that your app can be killed and then later restored at any point in time. It will come back up at the same destination it is at, but any ViewModel / in memory only information is going to be lost
👍 2
f

FunkyMuse

03/03/2021, 6:15 PM
Same goes with in memory database as a temp data holder for the URLs?
i

Ian Lake

03/03/2021, 6:16 PM
Your list of items should already be just displaying data from a local repository; your detail view should just be accessing that same local repository
👍 3
f

FunkyMuse

03/03/2021, 6:44 PM
Right, so there's no way to pass lists as nav argument to compose at all?
g

Gabriel Melo

03/03/2021, 6:49 PM
It's not currently supported and there are no plans to support it AFAIK.
😢 1
It may be a blessing in disguise, @FunkyMuse. It will "force" us to think about a single source of truth, persistence and process death.
f

FunkyMuse

03/03/2021, 6:52 PM
Yeah true that, some habits die hard
but i guess there should be an information pointing that
since NavType.StringArray still exists
then i guess Parcelize won't have much usage in the future, i.e deprecateD?
g

Gabriel Melo

03/03/2021, 8:47 PM
I believe it still has its place in passing arguments to activities and fragments, just not composables.
g

Gabriel Feo

03/04/2021, 1:08 AM
Compose still needs to interface with the platform. The underlying APIs are unlikely to stop using Bundles and Parcelables. We’ll still use
@Parcelize
for state restoration going forward: https://developer.android.com/jetpack/compose/state#restore-ui-state
22 Views