NavController is needed for navigation that is called in features. The register Graph(…) function registers the feature navigation graph either as separate screens via posable(…), or as a nested graph via navGraphBuilder.navigation(.). All API features are also interfaces and must be inherited from them.ĪPI features are supplemented with methods that return routes to their screens, taking into account navigation arguments. The interface below is the main API feature contract. Let’s create a core module and call it feature-api. In this example, we will call a feature the separate module with screens, which is paired with its API module. Here we will not argue about the feature statement, where is the end of one feature and the beginning of another. Therefore, a unified approach to adding features will be of great help to us. However, what about multi-modularity? It is absurd to register each new screen in one file endlessly, inflating it to infinity.
#Husky multi tool code
Let’s consider the code in which Scaffold (Material design layout) is created, in which we declare a BottomBar - composable function with a Bottom Nav Bar rendering and an AppNavGraph - composable function with a screen rendering from the navigation graph. In the example Github repository you can check the source code and library version that is used in the build.
#Husky multi tool update
Most likely, the IDE will prompt you to update the library versions this may initially lead to merge conflicts. Create a template project “Empty Compose Activity”.
#Husky multi tool install
To work with Compose, you need to install Android Studio Arctic Fox and higher. This is enough for the start! So let’s get to the code. This is an interface that has three heirs, which, for example, allow you to configure Activity Options or navigation on Dynamic feature. Navigator.Extras is also found in the parameters of the NavController.navigate(.) methods. In our example, this parameter won’t be used. You can find more details in the documentation. It allows you to set up transition animations, to work with saving and reading the Bundle type state screens in the back stack, to choose which screen to clear the back stack to, or set the navigation behavior to a screen that is already in the back stack. NavOptions is found in the parameters of the NavController.navigate(.) methods. This is a replacement of the graph description in xml as in Jetpack Navigation for Fragments. NavHost is a composable function that binds route with destination or with a nested graph. A single instance is created in the “root” composable, which must be passed to all “child” destinations. NavController is a class, the main entity through which navigation takes place. Passed arguments are written in the same string by analogy with the web (an alternative way may be to save the Bundle in the back stack). Here, unlike Jetpack Navigation for Fragments, navigation occurs only through links. There will be a retelling of the documentation here, so those who already have experience with this tool can move to the next section.ĭestination is the general name of the screen (in our case, the composable function) for the navigation. Let us consider the main entities from this library. Here I want to share how started making a multi-module application with Jetpack Compose Navigation using a simple example. Thirdly, in our opinion, the library is intuitive and has a low entry threshold.
Secondly, it is a fairly flexible tool that meets modern needs: flexible work with the back stack, simple integration with the Bottom Nav Bar, transition animations, a mechanism for integration with deep links.
On the other hand, it should be scalable so that the growth of the modules’ size and number does not create troubles, such as annoying build times or frequent merge conflicts.Īfter studying the documentation, examples with Google Compose and searching for solutions on the web, it was decided to use the Jetpack Compose Navigation library, because, first of all, it is being developed by Google. On the one hand, the solution should be quite concise and understandable for new developers. As always, I had to solve the issue of choosing a multi-module architecture and a navigation mechanism. When I started the development of a new application I took advantage of the opportunity to make UI right on Jetpack Compose.