1

I have a screen that shows a list of elements built with Jetpack Compose.

From this screen, the user can navigate to a second screen to create new elements or edit existing ones.

How do I refresh the list of elements shown on the first screen when the second screen is closed or removed from the stack?

With the view system you could use onResume(), but what do you use in compose?

(I am using Room to store the elements, so I know I could return a Flowable directly from the Dao that will listen to changes in the database, but that will mess up my existing architecture based on Use Cases that return a List<Element> and not a Flowable<List<Element>>.)

francosang
  • 353
  • 3
  • 15
  • 1
    It sounds like you know exactly what you need to be doing: returning an observable source of data (a `Flowable`) and not just a point in time reference that never changes. – ianhanniballake Apr 15 '22 at 21:21
  • Does this answer your question? [Jetpack Compose navigate for result](https://stackoverflow.com/questions/66837132/jetpack-compose-navigate-for-result) – nglauber Apr 16 '22 at 00:48
  • Check out [this answer](https://stackoverflow.com/a/68962907/3585796) about compose view lifecycle. Yet I'm agree with @ianhanniballake, that it's cleaner to do from the view model side. – Phil Dukhov Apr 16 '22 at 04:16
  • I have to say that the change was not easy, I had to rework an entire piece of the architecture of the app that with the View system worked well. So, in conclusion, migrating to Jetpack Compose is not as straightforward as just migrating the UI. – francosang Apr 20 '22 at 15:22
  • Also, collecting the Flow from the UI was really painful. My view models expose a StateFlow that already has a scope and an initial value configured to it, but when collecting it, it was still mandatory to configure those again. I hope I was doing something wrong, because this is not nice. – francosang Apr 20 '22 at 15:27

0 Answers0