Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Navigation Architecture Component animation

I've been following the sample from NavigationBasicSample

but used newest library for navigation:

implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha05"
implementation "android.arch.navigation:navigation-ui-ktx:1.0.0-alpha05"

and androidx library:

implementation 'androidx.core:core-ktx:1.0.0-rc01'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-rc01'

and add to bundle.gradle

androidExtensions {
        experimental = true
}

all works except animation. It is bug maybe or ?

this is my nav_graph:

<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/nav_graph"
    app:startDestination="@+id/categoryFragment">
    <fragment
        android:id="@+id/categoryFragment"
        android:name="com.sample.CategoriesFragment"
        android:label="Categories"
        tools:layout="@layout/fragment_categories">
        <action
            android:id="@+id/action_categoryFragment_to_itemsFragment"
            app:destination="@id/itemsFragment"
            app:popEnterAnim="@anim/slide_in_left"
            app:popExitAnim="@anim/slide_out_right"
            app:enterAnim="@anim/slide_in_right"
            app:exitAnim="@anim/slide_out_left" />
    </fragment>
    <fragment
        android:id="@+id/itemsFragment"
        android:name="com.sample.ItemsFragment"
        android:label="Items"
        tools:layout="@layout/fragment_items" >

        <argument android:name="cat_id" android:defaultValue="-1" />

    </fragment>

</navigation>

and my navhost fragment:

<fragment
        android:id="@+id/fragment_nav_host"
        app:defaultNavHost="true"
        android:name="androidx.navigation.fragment.NavHostFragment"
        app:navGraph="@navigation/nav_graph"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
like image 208
Marko Ljubisavljevic Avatar asked Aug 16 '18 14:08

Marko Ljubisavljevic


People also ask

Can we use navigation component for activity?

The Navigation component uses an activity as a host for navigation and swaps individual fragments into that host as your users navigate through your app. Before you can start to layout out your app's navigation visually, you need to configure a NavHost inside of the activity that is going to host this graph.

What is Androidx navigation?

Navigation is a framework for navigating between 'destinations' within an Android application that provides a consistent API whether destinations are implemented as Fragments, Activities, or other components. Latest Update. Stable Release. Release Candidate. Beta Release.


1 Answers

I think you use this code:

findNavController(it, R.id. fragment_nav_host).navigate(R.id. itemsFragment)

If this is true, then it is wrong. You must use the action you wrote with your animation.

Correct will be:

findNavController(it,R.id.fragment_nav_host).navigate(R.id.action_categoryFragment_to_itemsFragment)
like image 80
Timur Mukhortov Avatar answered Oct 13 '22 23:10

Timur Mukhortov