Переход общего элемента из фрагмента в элемент RecyclerView без анимации с использованием компонента навигации - PullRequest
0 голосов
/ 21 января 2020

Я пытаюсь анимировать между двумя фрагментами с помощью общих элементов, используя NavigationController.

Первый фрагмент PacksFragment представляет собой RecyclerView с элементами, макет элемента является общим элементом. Второй, PackInfoFragment - показывает детали выбранного элемента. transitionName идентичны, поскольку они определены в одном и том же файле XML.

Анимация работает только вперед, а не при go возвращении к первому фрагменту.

Нажатие назад, кажется, воссоздает PacksFragment. Я хочу вернуться к выбранному элементу списка.

PacksFragment - (Переход к PackInfoFragment)

Навигация - это переход от элемента RecyclerView к общему элементу на PackInfoFragment

private val onItemClickListener = object : PackListAdapter.OnItemClickListener {
        override fun onItemClick(view: View, position: Int) {
            preventDoubleClick(view)
            val packCover = packsOnScreen[position]

            val extras = FragmentNavigatorExtras(view to ViewCompat.getTransitionName(view)!!)

            val bundle = bundleOf(Pair(packID, packCover?.id))
            findNavController().navigate(R.id.action_packsFragment_to_packInfoFragment, bundle, null, extras)
        }
    }

PackInfoFragment - (возвращение к PacksFragment)

backButton.setOnClickListener {

            val extras = FragmentNavigatorExtras(packCard to ViewCompat.getTransitionName(packCard)!!)

            findNavController().navigate(R.id.action_packInfoFragment_to_packsFragment, null, null, extras)
        }

Nav Graph XML

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/navigation_graph"
    app:startDestination="@id/splashFragment">

    <fragment
        android:id="@+id/splashFragment"
        android:name="uk.co.ontrac.eswp.fragments.SplashFragment"
        android:label="fragment_splash"
        tools:layout="@layout/fragment_splash" >

        <action
            android:id="@+id/action_user_packs"
            app:popUpTo="@+id/splashFragment"
            app:popUpToInclusive="true"
            app:destination="@id/packsFragment" />

        <action
            android:id="@+id/action_user_login"
            app:popUpTo="@+id/splashFragment"
            app:popUpToInclusive="true"
            app:destination="@id/loginFragment" />

    </fragment>

    <fragment
        android:id="@+id/packsFragment"
        android:name="uk.co.ontrac.eswp.fragments.PacksFragment"
        android:label="fragment_packs"
        tools:layout="@layout/fragment_packs" >

        <action
            android:id="@+id/action_logout"
            app:destination="@id/loginFragment"
            app:popUpTo="@+id/packsFragment"
            app:popUpToInclusive="true" />

        <action
            android:id="@+id/action_packsFragment_to_packInfoFragment"
            app:destination="@id/packInfoFragment" />

    </fragment>

    <fragment
        android:id="@+id/loginFragment"
        android:name="uk.co.ontrac.eswp.fragments.LoginFragment"
        android:label="fragment_login"
        tools:layout="@layout/fragment_login" >

        <action
            android:id="@+id/action_login"
            app:destination="@id/packsFragment"
            app:popUpTo="@id/loginFragment"
            app:popUpToInclusive="true"
            app:enterAnim="@anim/fragment_open_enter"
            app:exitAnim="@anim/fragment_open_exit"
            app:popEnterAnim="@anim/fragment_open_enter"
            app:popExitAnim="@anim/fragment_open_exit" />

    </fragment>

    <dialog
        android:id="@+id/downloadFragment"
        android:name="uk.co.ontrac.eswp.fragments.DownloadFragment"
        android:label="fragment_download"
        tools:layout="@layout/fragment_download" />
    <fragment
        android:id="@+id/packInfoFragment"
        android:name="uk.co.ontrac.eswp.fragments.PackInfoFragment"
        android:label="PackInfoFragment"
        tools:layout="@layout/fragment_pack_info">
        <action
            android:id="@+id/action_packInfoFragment_to_downloadFragment"
            app:destination="@id/downloadFragment" />
        <action
            android:id="@+id/action_packInfoFragment_to_packsFragment"
            app:destination="@id/packsFragment"
            app:launchSingleTop="true"
            app:popUpTo="@+id/packInfoFragment"
            app:popUpToInclusive="true" />
    </fragment>

</navigation>
...