TrickyNavigationSample

screenshot of TrickyNavigationSample

This repository contains some tricks about Android Navigation Component. 3rd party libraries not used.

Overview:

TrickyNavigationSample is a repository containing tricks and tips for using the Android Navigation Component. It provides solutions to add bottom navigation back stack, create a stack like in Instagram or Youtube, dynamically handle toolbar titles, replace fragments without losing state, and add specific fragments to the navigation controller.

Features:

  • Default Bottom Behaviour: Adds bottom navigation back stack to the Android Navigation Component by adding a menu category of "secondary".
  • Tricky "secondary": Extends the bottom tab fragments from BaseBottomTabFragment and uses utils functions to navigate from tab starter fragments, creating a stack similar to Instagram or Youtube.
  • Dynamic Label: Uses the Android Navigation Component's SafeArgs to dynamically set toolbar titles based on the fragment labels.
  • Default Replace: Provides a solution to replace fragments without losing state by passing an id to all views. Suggests using Event.kt or EventObserver.kt as the best solution.
  • Tricky Add: Introduces the use of the <dialog> tag in the navigation graph to add specific fragments to the navController, using BottomSheetDialogFragment as fullscreen with a draggable attribute set to false.

Summary:

TrickyNavigationSample provides useful solutions for enhancing the Android Navigation Component. By following the provided tricks and tips, developers can add bottom navigation back stack, create navigation stacks similar to Instagram or Youtube, dynamically handle toolbar titles, replace fragments without losing state, and add specific fragments to the navigation controller. These enhancements can improve the user experience and make navigation within the app more seamless.