Hello my people! We have a problem with navigation...
# compose
j
Hello my people! We have a problem with navigation and passing arguments. In our app, we use MVVM with clean usecase/repository patten with the Google Navigation for Compose. In screen A we can run a search and get back a list with results. These results are from the backend and they are temporary results (aka they have no specific id's to recreate a specific result). If we open a detail page for such a search result, lets say screen B, we need to pass the search result from A to B. Screen A is part of a screen with bottom navigation. So the hierarchy is MainNavHost -> BottomNavigationNavHost -> A Screen B is not part of this screen, so it lives directly in the MainNavHost. My question: How can I open Screen B from screen A, and pass the data? I can't pass an id for the specific result (so I can't retrieve it), and in theory I shouldn't pass an object into the navigation graph. I was thinking about making an activity scoped ViewModel, pass the object there and if the screen B observes that object but there is none, close the screen. However, this is not recreation friendly at all. So for now we will just bubble up the event through the compose tree, serialize the search result into a string and pass it as a navigation argument to open screen B where we deserialize the navigation argument. Does anyone know a better solution?