Modify navigation

Modify navigation between Activities

The navigation between Activities happens in a centralised navigator Navigator. To modify its behaviour, apply the decorator pattern and modify the appropriate method.

class CustomNavigator(
navigator: Navigator
): Navigator by navigator {
override fun goToSomeDestination() {
//Your new destination code
}
}

Modify navigation between Fragments

The navigation between Fragments, within the same feature, happens with Android Jetpack Navigation. To modify the navigation you need to:

  1. Extend the main activity of the feature.
  2. The PoqSDK provides extension functions to simplify the replacement of Fragments on the most common scenarios:
    • Replace a Fragment:
      navController.replaceDestination(
      R.id.idFragmentToReplace,
      YourFragment::class.java
      )
    • Replace the start destination Fragment:
      navController.replaceStartDestination(
      R.id.idFragmentToReplace,
      YourFragment::class.java,
      getFragmentArgsBundle() // Protected method available on the Activities with parameters
      )
    • Replace a fragment in a nested graph:
      navController.findSubGraph(R.id.nested_nav_graph)
      .replaceDestination(R.id.idFragmentToReplace, YourFragment::class.java)

If the above is not possible, as a final resource, you can replace the whole graph replacing the navigation XML creating a new file matching the name.

Avoid copy-paste code as much as you can. Copy-paste code will cause hard to track breaking changes when doing migrations.