New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompositeParallelNavigator for "bottom bar navigation" #110

Open
nhaarman opened this Issue Jan 8, 2019 · 0 comments

Comments

1 participant
@nhaarman
Copy link
Owner

nhaarman commented Jan 8, 2019

The Material "Bottom Navigation" component allows movement between primary destinations in an app:

image

Each of the 'primary destinations' is represented by a tab in the bottom navigation bar, and each of them has their own navigational state.

In Acorn, this could be represented by a CompositeParallelNavigator type, which allows for such a component.

A quick sketch-up of the API could be:

enum class MyDestination {
  Favorites,
  Music,
  Places,
  News
}

class MyNavigator(
  savedState: NavigatorState? = null
) : CompositeParallelNavigator<MyDestination>(savedState) {

  override fun createNavigator(destination: MyDestination) : Navigator {
    return when(destination) {
      Favorites -> FavoritesNavigator()
      /* ... */
    }
  }

  override fun instantiateNavigator(
    navigatorClass: KClass<out Navigator>,
    state: NavigatorState?
  ) : Navigator {
    return when(navigatorClass) {
      is FavoritesNavigator::class -> FavoritesNavigator(state)
      /* ... */
    }
  }
}

The CompositeParallelNavigator<T> class could expose methods like select(T) to switch between the nested child Navigators, and provide a way to listen to changes in the selected T type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment