Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dynamic Navigation in Modularized Apps

Dynamic Navigation in Modularized Apps

Sumayyah Ahmed

September 28, 2021
Tweet

More Decks by Sumayyah Ahmed

Other Decks in Programming

Transcript

  1. Overview 30 min talk, then questions How does modularization make

    Navigation Components complicated? How can we solve those problems? How can we ensure that users always see a cohesive flow? 3
  2. Problem 1: navigating between libraries with known destinations Problem 2:

    navigating between libraries with unknown destinations 17
  3. FragmentClass::class.java Navigator<T> Actions Deep link NavDestination XML Created by NavComponents

    Navigator<Fragment> uses FragmentTransaction Navigator<Activity> uses Intents 29
  4. 30

  5. NavDestination Navigator<NavGraph> Knows how to navigate to this navGraph 1.

    Iterate through NavDestinations to find a deep link match 2. NavGraph destination knows about its own deep links 3. NavController delegates navigation to Navigator<NavGraph>.navigate() 4. Navigator adds deep linked destination fragment to backstack 32
  6. How do fragments in the stack react to this unknown

    destination? Fragment A from host app ?? – Fragment D Fragment C from host app What if Fragment C needs to know what happens in Fragment D? They don’t share a ViewModel or Activity or data store 35
  7. Fragment A from host app ?? – Fragment D Fragment

    C from host app How can we share data across a backstack? 36
  8. 40

  9. the problem with SavedStateHandle It’s a little hacky! It requires

    fragments to know in advance what data is saved and in what format It’s fragile 44
  10. what if you don’t know where to go till runtime?

    For example: A nav destination relies on external library for content Fragment A ?? Fragment C External lib 46
  11. 49

  12. 52 Summary Navigation doesn’t have to be statically defined! Modularization

    creates unknowns and dynamically handled navigation can help deal with these unknowns