https://kotlinlang.org logo
Title
a

ayodele

02/13/2023, 8:37 PM
I just migrated from OrbitMVI to Ballast. In 3mins. I like the "it just works" nature. Kudos. I'm moving onto navigation with Ballast. If I'm not mistaken, it's built ontop on the redo and undo lib by the same author. My question is do I still need compose navigation with Ballast navigation? If yes does ballast handle backstack??
c

Casey Brooks

02/13/2023, 9:09 PM
A few things to unpack:
If I’m not mistaken, it’s built ontop on the redo and undo lib
ballast-navigation
only depends on
ballast-core
, not
ballast-undo
. The backstack functionality is part of the navigation module itself. Out of the box, it allows you to do forward/lateral navigation to a specific destination, and to go backward to the previous destination. https://copper-leaf.github.io/ballast/wiki/modules/ballast-navigation/#step-4-navigate Adding the undo/redo module to the Router allows you to handle returning to a screen after going backward, without referencing the Router itself. Normally, you can go back, but you cannot restore to the screen you just “went back from”. It adds the “forward” button of a browser’s address bar, which is not available in the base
ballast-navigation
module. This might help illustrate the difference: Without Undo/Redo module:
1. RouterContract.Inputs.GoToDestination(A)
    - Backstack: [A]
2. RouterContract.Inputs.GoToDestination(B)
    - Backstack: [A, B]
3. RouterContract.Inputs.GoBack()
    - Backstack: [A]
4. Cannot return to B, you have to do GoToDestination(B) again
With Undo/Redo module:
1. RouterContract.Inputs.GoToDestination(A)
    - State History:
        - Backstack: [A] (current state, destination is B)
2. RouterContract.Inputs.GoToDestination(B)
    - State History:
        - Backstack: [A]
        - Backstack: [A, B] (current state, destination is B)
3. UndoController.undo()
    - State History:
        - Backstack: [A] (current state, destination is A)
        - Backstack: [A, B]
4. UndoController.redo()
    - State History:
        - Backstack: [A]
        - Backstack: [A, B] (current state, destination is B once again)
The Compose Desktop example shows how this works.
do I still need compose navigation with Ballast navigation
No, Ballast Navigation is an alternative to
navigation-compose
, and is not compatible with it, nor is it built upon anything from that library. Ballast is a completely separate navigation library which offers a simpler way to do navigation that is not limited to Android or Compose like
navigation-compose
is. However, since it isn’t tied directly to Compose, it may take a bit more work from you to get some of the nicer features of
navigation-compose
like transition animations and scoping ViewModels to the NavGraph.
a

ayodele

02/13/2023, 9:29 PM
Thanks for the clarity.