Skip to content

omidMirrajei/NavigationComponent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Navigation Component

Jetpack Navigation Component in One Video by Mitch

Get started with the Navigation component by Google Developers

Android Jetpack: Introducing Navigation Component by google

  • Simplifed setup for common navigation patterns
  • Handles backstack
  • Automates fragmnet transactions
  • Type safe arrguments passing
  • Handles transition animations
  • Simplified deep linking

Three major parts working together in harmony

  1. Navigation graph: An XML resource that contains all navigation-related information in one centralized location. This includes all of the individual content areas within your app, called destinations, as well as the possible paths that a user can take through your app.

  2. NavHost: An empty container that displays destinations from your navigation graph. The Navigation component contains a default NavHost implementation, NavHostFragment, that displays fragment destinations.

  3. NavController: An object that manages app navigation within a NavHost. The NavController orchestrates the swapping of destination content in the NavHost as users move throughout your app

Project Instructions

List by mitch

  1. Creating a project with Kotlin and androidX
  2. Navigation Component dependencies
  3. Creating a navigation graph
  4. NavHostFragment (Navigation Host Fragment)
  5. Adding fragments to the navigation graph
  6. NavController and navigating between fragments
  7. Fragment transition animations using the navigation graph
  8. Backstack management with PopUpTo and PopUpToInclusive attributes
  9. Sending data as Arguments through a Bundle to a Fragment

list by Me 😎

  1. Add dependencies in build.gradle app

    def nav_version = "2.1.0"
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    
  2. Create Navigation Graph

    res > new android resource file > (file name) (Res type Navigation)

  3. Create fragment - use fragment blank (class and layout)

  4. Create fragment to main activity as host fragment

    What's view or activity is hosting your navigation graph

      <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        app:defaultNavHost="true"
        app:navGraph="@navigation/nav_graph" />
    
    • The android:name attribute contains the class name of your NavHost implementation.

    • The app:navGraph attribute associates the NavHostFragment with a navigation graph. The navigation graph specifies all of the destinations in this NavHostFragment to which users can navigate.

    • The app:defaultNavHost="true" attribute ensures that your NavHostFragment intercepts the system Back button. Note that only one NavHost can be the default. If you have multiple hosts in the same layout (two-pane layouts, for example), be sure to specify only one default NavHost.

  5. Insert fragments to Graph as destination

What is difference between the pop animation and non pop animation? pop refer to what happens when you navigate backward (back stack) not pop is forward

About

Created with mitch course

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages