Before Jetpack Compose release we were used to add menu items in Fragments or Activities classes
with xml files and onCreateOptionsMenu methods.
The new UI tool is a game changer and via Scaffold composable it’s easy to add global actions
to TopAppBar. With global actions I mean items that remains visible for the entire lifecycle of the controller class.
When using Jetpack Navigation however there is only one Activity and the NavHost swaps composable destinations on the screen.
In this scenario is useful to have a concise way to easily add or remove actions from the ToolBar
for each navigation route.
The following video shows the sample app available at this link
Sample code
Note
Provide an AAR for this feature is overkilling. You can find the ToolBarController implementation
in this package.
Define a toolbarController instance (Hoist instance as up as possible)