brabo-hi
01/17/2022, 9:15 PMnavController.currentBackStackEntry?.savedStateHandle?.set("person", person)
and
navController.currentBackStackEntry?.arguments?.putParcelable("person", person)
Ian Lake
01/17/2022, 9:16 PMIan Lake
01/17/2022, 9:19 PMPerson
as an argument at all as per the documentation:
To pass around custom complex data, store the data elsewhere such as a ViewModel or database and only pass an identifier while navigating; then retrieve the data in the new location after navigation has concluded.
Ian Lake
01/17/2022, 9:20 PMCaution: Passing complex data structures over arguments is considered an anti-pattern. Each destination should be responsible for loading UI data based on the minimum necessary information, such as item IDs. This simplifies process recreation and avoids potential data inconsistencies.
Ian Lake
01/17/2022, 9:25 PMPerson
class certainly seems like something that you shouldn't be passing between destinations, but something that a common PersonRepository
that both destinations use as their source of truth would make a lot more senseIan Lake
01/17/2022, 9:27 PMColton Idle
01/17/2022, 9:37 PMNavigation does support custom types as arguments, but those are for sending composition specific state between screens and not for sending domain objects (edited)ooh. what composition specific state would that be? Would this lead to shared element transitions by chance?
Ian Lake
01/17/2022, 9:40 PMSearchParameters
class used as an example in those exact docsIan Lake
01/17/2022, 9:41 PMSearchParametersRepository
wouldn't make any sense (and has never been a recommendation) as that state doesn't exist outside of the context it is created and consumed inIan Lake
01/17/2022, 9:49 PMplants
vs plant/{id}
point to two different screens. Shared element information isn't part of a screen's identity (just like how animations aren't part of the screen's identity) so I wouldn't expect arguments and shared elements to have any overlapbrabo-hi
01/17/2022, 9:59 PMZoltan Demant
01/21/2022, 2:48 PMMichal Klimczak
01/21/2022, 3:02 PMIan Lake
01/21/2022, 10:02 PMbrabo-hi
01/21/2022, 10:06 PMIan Lake
01/21/2022, 10:08 PMDialog
usages across Compose don't need to be a dialog destination, not all bottom sheets need to be a bottom sheet destinationIan Lake
01/21/2022, 10:11 PMDialog
that needs its own independent set of viewmodels, state, etc. that is separate from whoever called it. And sometimes you need a bottom sheet that is completely independent from whoever called it. If that isn't the case, having it as a separate destination isn't the right choice in the first placeColton Idle
01/21/2022, 10:13 PMshould just be an implementation detail on how the functionality of a single destination is implemented on a specific form factorCouldn't you also do that even when using a modal as a destination? I'm not arguing against your statement. What I've found is that its way easier to do stuff in a single screen that contains all of the modals it needs. But was just curioius if there was something inherently stopping me from treating certain things (like a button press) different on a "phone" vs "tablet" (i.e. nav event to a modal vs just showing some extra info in an additional pane on the tablet)
Ian Lake
01/21/2022, 10:15 PMColton Idle
01/21/2022, 10:27 PMIan Lake
01/21/2022, 10:36 PMThis is suitable only when this dialog represents a separate screen in your app that needs its own lifecycle and saved state, independent of any other destination in your navigation graph. For use cases such asI would imagine that date and time pickers should also not be a separate destination entirely, although I realize that the bottom sheet APIs in Compose are quite a bit more...complicated to use than, you should use those APIs directly in theAlertDialog
destination that wants to show that dialog.composable
Dialog
🙂Michal Klimczak
01/22/2022, 6:52 AMColton Idle
01/22/2022, 7:15 AM