flow
flow copied to clipboard
Support for multiple histories
In our app, we would like to support bottom bar navigation and retain the histories of all the different views available there. 5 buttons in the bottom bar equals 5 distinct histories to switch between.
AFAICT this is not possible today due to the fact that Flow is tied to the Activity and only has 1 linear history.
I've kinda worked something out by cheating with package names and such, but I feel this should've been supported by the library one way or another.
MultiKeys doesn't help either. OTOH, MultiKeys are so confusing ;-) that I might be wrong.
You could dump a history any time a bottom bar position changed by Flow::getHistory
and replace it by Flow::setHistory
@lassem I've been thinking a lot about this, but if you have multiple history stacks, then you need to give your Flow instances id
s to separate the ID by which Flow persists the history to the Activity bundle.
Another possibility is to flatten the 5 history stacks into one using interfaces to determine which key belongs to which view, and the custom dispatcher logic can evaluate which stack this belongs to, and update the current selected bottom navigation element in the activity based on whether there is a mismatch between the new and previous element's stack group.
Although if you have anything else in mind, maybe it helps me brainstorm :)
In the end, I just made my own library that allows it via backstackDelegate.setPersistenceTag()
EDIT from the future: It actually makes managing them kinda difficult though... :|
You could dump a history any time a bottom bar position changed by
Flow::getHistory
and replace it byFlow::setHistory
I have this working following this advice but an easy way to Parcel a History
would be very handy to implement this. It's not trivial.
@BraisGabin only InternalLifecycleIntegration
knows how to parcel a History, no?
It does, I copied&pasted that code. But It doesn't fill right to copy&paste something like that.