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

Spikey Sanju

02/27/2021, 4:27 PM
Hi guys, how to send data class as an arguments instead of each type in the data class? P.S -> I'm having list of items in home screen when onClick I need to pass the data as a class!
s

Spikey Sanju

02/27/2021, 4:42 PM
c

Colton Idle

02/27/2021, 6:28 PM
Yeah. I like the way that Ian Lake puts it. You should think of actions like urls and you would pass an id in a url, not the entire object.
a

Arkadii Ivanov

02/27/2021, 6:42 PM
It is very questionable. This implies that you have persistent storage. But you may not need one, and perhaps navigation should not be the only reason of introducing one. E.g. the app may be fully online (like Uber Eats). Ability to pass objects between screens may dramatically improve UX. E.g. when you open a restaurant menu cart, server may send fully detailed items. So you don't need additional requests when opening specific items from the menu.
1
c

Colton Idle

02/27/2021, 6:44 PM
Just hoist that object to another scope. I.e. if you have object in fragment a and want that object in fragment b, just put the object in the next scope up. Like the activity or navigation view model scope.
a

Arkadii Ivanov

02/27/2021, 6:45 PM
And then you open a heavy app like camera and your app is killed.
c

Colton Idle

02/27/2021, 6:46 PM
Parcelables are land mines. The binder transaction limit shrinks in every release.
a

Arkadii Ivanov

02/27/2021, 6:48 PM
Yes, it is still fine to pass a few thouand bytes. Anyway, glad there will always be ways to use parcelable.
Even with compose-navigation, we can always encode a parcelable into a string)))
i

Ian Lake

02/27/2021, 7:45 PM
Please don't
✔️ 2
a

Arkadii Ivanov

02/27/2021, 7:46 PM
It's a joke)
3 Views