带有嵌套导航图的循环参考 [英] Circular Reference with Nested Nav Graphs

查看:67
本文介绍了带有嵌套导航图的循环参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的导航结构,我从一个导航图转到然后根据某种逻辑,确定要导航到哪个导航图.但是,两个导航图都共享其他3个导航图.见下图

I have a complex navigation structure, I go from one nav graph then based on some logic, decide which nav graph to go to there. However both the nav graphs share 3 other nav graphs. See image below

如果我尝试将每个导航图包括在A&中,则会出现循环参考错误.B.我还尝试过创建全局操作,这会导致非法参数异常,因为它在导航图上不存在.

Currently I get a circular reference error if I try to include each nav graph in the A & B. I have also tried creating a global action, which leads to illegal argument exception since it doesn't exist on the nav graph.

请帮助!!!

推荐答案

我也不知道如何解决这个问题.导航组件应该通过从初始图中传递某种ID来允许模块化图的重用.

I also don't know how to solve this. The Navigation Component should allow the reuse of modular graphs by passing some sort of ID from the initiating graph.

我唯一想到的解决方法是创建具有不同起源的图的副本.

The only workaround I could think of was to create a copy of the graphs that have different origins.

例如,"Graph1"现在将具有两个版本,"Graph1_from_GraphA"和"Graph1_from_GraphB".因此,"GraphA"和"GraphB"分别引用它们.

For example, "Graph1" would now have two versions, "Graph1_from_GraphA" and "Graph1_from_GraphB". So "GraphA" and "GraphB" would reference them respectively.

如果图形不是那么遥远,那么也可以使用条件导航的解决方案,如官方文档中所述(

If the graphs are not that far way, there is also the solution of conditional navigation, as described in the official documentation (https://developer.android.com/guide/navigation/navigation-conditional), in which we can pop the BackStack in the NavController with a result in the SavedStateHandle and then in the previous fragment we can redirect to the desired destination.

这篇关于带有嵌套导航图的循环参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆