Search code examples
androidkotlinbottomnavigationview

What are features of Flow, Cicerone, Fragnav, Simple-stack and when to use them?


I am using BottomNavigationView in my application with 3 tabs. I want to implement instagram like navigation, saving each section fragments states. Firstly I used navigation component, but it is difficult to save states of each tab (section). Then I find some libraries like flow, cicerone, fragnav, simple-stack.

What are features of flow, cicerone, fragnav, simple-stack and when to use them?

I have 2 activity and MainActivity. Mvvm architecture, dagger2, kotlin


Solution

  • I saw this question a bit late, I'm the maintainer of Simple-Stack and found this question with some elaborate searches.

    Anyway,

    Firstly I used navigation component, but it is difficult to save states of each tab (section).

    Technically they made this large block of code that you can include and now lets you manage N navHostFragments and therefore have multiple backstacks in an app.

    Whether it scales well or not I'm not sure, but it does work across rotation and process death.

    square/flow

    Flow is dead, Square works on Workflow now.

    But Flow was originally a solution to track a list of screens [Screen1, Screen2] and make that survive configuration changes and process death. They also allowed you to handle changes such as [Screen1, Screen2] -> [Screen1, Screen2, Screen3] in an async way (you had to call a completion callback when you were done).

    It had some elements of scoping support. I tried it but couldn't make that aspect of it work.

    Cicerone

    Cicerone enqueues navigation commands while there is no one registered to handle them.

    Otherwise, it has some navigation commands out of the box to somewhat simplify fragment/activity navigation.

    Fragnav

    FragNav was built with multi-stack support in mind. Theoretically, it tracks fragment stacks for a maximum of 5 bottom nav tabs.

    Simple-Stack

    Simple-Stack was written to be a rewrite and replacement for what square/flow intended to do: 1 stack, asynchronous state transition support, enqueueing navigation actions while no one can handle them, persist/restore navigation state across config changes and process death.

    The key difference between Flow and Simple-Stack was:

    • API naming conventions (Flow had some tricky names like "Dispatcher" and "Traversal", which are in simple-stack called StateChanger and StateChange)

    • simpler lifecycle integration (no more overriding attachBaseContext)

    • all-new scoping support with ability to easily share data between screens, and persist/restore the state of these "scoped services" across process death, while getting important lifecycle callbacks about creation/destruction (kinda like ViewModels)

    • completion: Flow was left as "alpha" version and is no longer maintained.


    Flow and Simple-Stack were both built to make Single Activity apps easier to develop. Same is true of Jetpack Navigation.

    Both Jetpack Navigation and Simple-Stack allows the creation of "scopes shared between screens", JN does it with navgraph-scoped viewmodels, while SS doing it with scoped services.

    Multi-stack is a bit of a pain no matter what, FragNav has direct support for it out of the box, and simple-stack has a sample for it (and Jetpack Navigation also has a sample for it).


    Pick whichever tool seems like it solves the most problems for you with minimal friction.