132f050cea59fa19b1b187c0283310839e323774 |
|
09-Apr-2018 |
Ian Lake <ilake@google.com> |
Create Kotlin DSL for navigation graphs Allow developers to easily build a NavGraph programmatically via a Kotlin DSL. The DSL is started with a call to createGraph(), an extension method on NavigatorProvider (as well as NavController and NavHost, for convenience). This provides a NavGraphBuilder, the main DSL for adding destinations to a NavGraph. Concrete subclasses of NavDestination then provide an extension method on NavGraphBuilder and a subclass of NavDestinationBuilder to insert themselves into the DSL. This allows developers to write code such as: val navGraph = navHost.createGraph(startDestination = HOME_ID) { fragment<HomeFragment>(HOME_ID) { label = "Home" action(ACTION_SIGN_IN_ID) { destinationId = SIGN_IN } } navigation(SIGN_IN, startDestination = LOGIN_ID) { fragment<LoginFragment>(LOGIN_ID) { action(NEXT_ID) { destinationId = PASSWORD_ID } } fragment<PasswordFragment>(PASSWORD_ID) } } Test: new ktx tests BUG: 77536435 Change-Id: I29b190c2c26ff03f6607230f239d3fd96fa3c9f6
/frameworks/support/navigation/runtime/ktx/src/main/java/androidx/navigation/NavHost.kt
|