<@UHAJKUSTU> When using Pages Navigation, I see pa...
# decompose
v
@Arkadii Ivanov When using Pages Navigation, I see pages are being destroyed and recreated Thus all my StateFlows,
init
block run again, which is resulting to API calls being made again
a
This is the default behaviour, similar to many other pager-like APIs. E.g. I believe
HorizontalPager
keeps only limited amount of Composables alive. But you can use the
childPages(pageStatus = ...)
argument to control this behaviour. E.g. to keep all components alive, just pass
pageStatus = { _, _ -> ChildNavState.Status.ACTIVE }
.
v
There is no ACTIVE field but CREATED, RESUMED, STARTED, DESTROYED
Using Resumed fixed it Thanks
@Arkadii Ivanov I dont see this behaviour when I have just 2 pages, does it happen only for more than 2 pages?
a
Yeah, new versions have RESUMED instead.
By default, it keeps +-1 page CREATED, and the selected is RESUMED.
v
@Arkadii Ivanov by setting it to RESUMED, are all pages created together at the same time? Or a page is created when its opened for the first time, and from the next time the old instance is reused
a
All pages are created at the same time. I think there is currently no way of creating pages lazily and keeping them created forever with Child Pages. I will think about this feature. In the meantime, you can try playing with Generic Navigation. You can check how the Child Pages model is implemented.
Actually, I think it's possible with Child Pages as well. Let me try.
Nope, doesn't look possible at the moment.
v
Ohh, it would be a good addition in future releases I'll take a look at Generic Navigation
a
It's a bit tricky to implement in Decompose. Let's say we have lazy creation, and the user swiped 100 pages out of 200, so there are now 100 created pages and the rest 100 are destroyed. What happens when the process is re-created or Android configuration changed? Should we re-created all 100 previously created pages, or should we start again lazily?
I think both ways might be valid, depending on the use case.
This is how it can be implemented using Generic Navigation. Basically copy-paste from Child Pages.
Just above 100 LOCs. Maybe it not worth it to over-engineer the current Child Pages implementation. Not sure.
v
This is very helpful, thanks a lot Will give it a try This kind of lazy loading will help a lot when pages have some heavy computation or quite some api calls to be made. Looking forward to see this being added in decompose's future releases
👍 1