https://kotlinlang.org logo
e

Eric Ampire [MOD]

10/28/2020, 7:56 PM
What will it take to pass a parcellable as an argument? @Ian Lake
i

Ian Lake

10/28/2020, 8:01 PM
In general, this isn't something you should consider doing: pass the ID of the item instead of the item itself. The route structure in Navigation Compose has the best analog with a restful web service
profile/{id}
not
profile/{a whole set of fields representing a user's profile}
which is essentially what passing a parcelable is doing
e

Eric Ampire [MOD]

10/28/2020, 8:19 PM
Ok thanks
There is not a method
navigate
with String as parameter
a

arkon

10/28/2020, 10:45 PM
It's an extension function.
i

Ian Lake

10/28/2020, 11:08 PM
Yep, import the extension function
e

Eric Ampire [MOD]

10/28/2020, 11:12 PM
Doesn’t this extension come with this dependence?
androidx.navigation:navigation-composite:1.0.0-alpha01
I just noticed that I had to import the method manually.
Thanks
i

Ian Lake

10/28/2020, 11:17 PM
Import should be one of the quick fixes for that error. Was that not the case for you?
e

Eric Ampire [MOD]

10/28/2020, 11:19 PM
Exactly
k

Kshitij Patil

10/29/2020, 11:13 AM
Does an issue have been filed regarding this behavior?
i

Ian Lake

10/29/2020, 2:57 PM
There's no intention to change the behavior, but please do file a bug so we can properly call this out in the documentation
k

Kshitij Patil

10/29/2020, 3:00 PM
I mean we do need to import that function manually, Android studio isn't suggesting the same
i

Ian Lake

10/29/2020, 3:01 PM
Ah, yes you should file a bug against Studio if it isn't suggesting extension functions
p

Philip Blandford

10/30/2020, 9:27 AM
I'm still confused.. where do I import it from? Edit: Found it..
Copy code
import androidx.navigation.compose.navigate
j

Jeziel Lago

03/12/2021, 6:23 PM
@Ian Lake what do you think about this solution to disallow complex types as argument type? https://github.com/jeziellago/androidx/commit/fa4711838092061ca02409b998a59f12ef0b7143
i

Ian Lake

03/12/2021, 7:34 PM
No, that's not the right approach. The problem isn't with having arguments with complex types - that's actually totally fine (and you could absolutely use an
EnumType
with a
defaultValue
to build an argument based listener ). It is easy to conflate the list of arguments in your route with the total list of arguments, but those are purposefully separate things
j

Jeziel Lago

03/12/2021, 8:39 PM
Interesting! Thanks!!
f

Florian

08/06/2021, 4:04 PM
@Ian Lake When we send a result back through the previous back stack entries' SavedStateHandle, putting a Parcelable object in there is no problem. It's unclear to me if it's fine to use Parcelable there or if we should avoid that as well. Because why send Parcelables in one direction but not the other?
i

Ian Lake

08/06/2021, 4:18 PM
The first thing you should do is define your single source of truth. An observable repository is an example of a source of truth - any destination can read that data and get the same answer back. Any source can update that data and have it automatically flow back to everyone using that source of data. Arguments and results should not be a source of truth for your app's data
f

Florian

08/06/2021, 4:26 PM
@Ian Lake. I see, thank you. The Parcelable I'm sending back is not an entity. It's a sealed result class. Is it fine to put that in the
SavedStateHandle
of the
previousBackstackEntry
?
i

Ian Lake

08/06/2021, 4:27 PM
Nothing is going to stop you 👍
f

Florian

08/06/2021, 4:28 PM
Alright, thank you very much!