简体   繁体   中英

Android Navigation Component: How to solve the circular navigation with nested graph?

In our user requirement we have a flow like this.

在此处输入图像描述

I have searched the following:

https://developer.android.com/guide/navigation/navigation-principles

Circular Reference with Nested Nav Graphs

But nothing can help...

What I have done?

Currently I split 2 graph and add duplicate Fragment C in Graph2. Also, I change the graph start destination to Fragment C in graph 1 programmatically only I clicked from graph2. This is an ugly solution But I have no idea how to solve this issue.

My question is: Is there any way to do it rather making a duplicate destination and changing the start destination?

Graph 1:

<include app:graph="@navigation/graph2" />
<dialog
        android:id="@+id/fragmentA"
        android:label="Fragment A"
        tools:layout="@layout/fragmentA"/>
<dialog
        android:id="@+id/fragmentB"
        android:label="Fragment B"
        tools:layout="@layout/fragmentB">
    <action
            android:id="@+id/NavigateToGraph2"
            app:destination="@id/graph2">
</dialog>
<dialog
        android:id="@+id/fragmentC"
        android:label="Fragment C"
        tools:layout="@layout/fragmentC"/>
<dialog
        android:id="@+id/fragmentD"
        android:label="Fragment D"
        tools:layout="@layout/fragmentD"/>
<dialog
        android:id="@+id/fragmentE"
        android:label="Fragment E"
        tools:layout="@layout/fragmentE"/>

Graph 2

<dialog
        android:id="@+id/fragmentF"
        android:label="Fragment F"
        tools:layout="@layout/fragmentF"/>
<dialog
        android:id="@+id/fragmentG"
        android:label="Fragment G"
        tools:layout="@layout/fragmentG"/>
<dialog
        android:id="@+id/fragmentC"
        android:label="Fragment C"
        tools:layout="@layout/fragmentC"/>

I think it is better to create a graph for fragment F and break the circular loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM