如何防止BottomSheetDialogFragment在导航到另一个片段后解除? [英] How to prevent BottomSheetDialogFragment from dismissing after a navigation to another fragment?

本文介绍了如何防止BottomSheetDialogFragment在导航到另一个片段后解除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用上使用 NavigationComponent.

我有一个特定的流程,在点击 BottomSheetDialogFragment 的按钮后,应用程序应该导航到另一个片段.但是当那个 Fragment 弹出时,我需要导航回之前的 BottomSheetDialogFragment.

出于某种原因,BottomSheetDialogFragment 被自动关闭.

Frag A : 点击一个按钮片段 A ->对话框 B:单击按钮片段 A ->对话框 B ->Frag C : 从堆栈中弹出 Frag CFrag A : 对话框 B 被自动关闭 =;/

如何防止这种解雇?


问:为什么我需要 BottomSheetDialogFragment 不被解除?
A:我通过一个LiveData来监听打开片段的结果.由于取消了 BottomSheetDialogFragment,它永远不会收到结果.

解决方案

这是不可能的.对话框目标实现了 FloatingWindow 接口,它指出:

<块引用>

当您导航到新目的地时,实现此接口的目的地将自动从返回堆栈中弹出.

因此,当您导航到 目标时,预计对话框目标会自动从返回堆栈中弹出.在多个对话目标之间导航时不是这种情况(这些目标可以堆叠在一起).

这个问题更详细地解释了此处的限制,即:

<块引用>

  1. 对话框是始终位于活动窗口上方的独立窗口.这意味着无论底层 FragmentManager 处于何种状态或您执行何种 FragmentTransactions,对话框都将继续拦截系统后退按钮.

  2. 片段容器(即您的正常目的地)上的操作不会影响对话片段.如果您在嵌套的 FragmentManager 上执行 FragmentTransactions,则相同.

因此,一旦您导航到您的 目的地,系统后退按钮实际工作的唯一方法就是弹出所有浮动窗口(否则它们会在之前拦截后退按钮)其他任何东西),因为这些窗口总是浮动在内容之上.

这不是导航组件强加的限制 - 相同的问题适用于 BottomSheetDialogFragment 关于片段返回堆栈和系统返回按钮的任何用法.

I am using NavigationComponent on my App.

I have an specific flow where after a click on a button of BottomSheetDialogFragment the app should navigate to another fragment. But when that Fragment is popped I need to navigate back to the previous BottomSheetDialogFragment.

For some reason the BottomSheetDialogFragment is being dismissed automatically.

Frag A : click on a button  
Frag A -> Dialog B : click on a button  
Frag A -> Dialog B -> Frag C : pop Frag C from the stack  
Frag A : Dialog B was automatically dismissed =;/  

How can one prevent that dismissing?


Q: Why do I need the BottomSheetDialogFragment not dismissed?
A: I listen to the result of the opened fragment through a LiveData. Due to the dismissing of the BottomSheetDialogFragment it never receives the result.

解决方案

This is not possible. Dialog destinations implement the FloatingWindow interface which states:

Destinations that implement this interface will automatically be popped off the back stack when you navigate to a new destination.

So it is expected that dialog destinations are automatically popped off the back stack when you navigate to a <fragment> destination. This is not the case when navigating between multiple dialog destinations (those can be stacked on top of one another).

This issue explains a bit more about the limitations here, namely that:

  1. Dialogs are separate windows that always sit above your activity's window. This means that the dialog will continue to intercept the system back button no matter what state the underlying FragmentManager is in or what FragmentTransactions you do.

  2. Operations on the fragment container (i.e., your normal destinations) don't affect dialog fragments. Same if you do FragmentTransactions on a nested FragmentManager.

So once you navigate to your <fragment> destination, the only way for the system back button to actually work is for all floating windows to be popped (otherwise they would intercept the back button before anything else) as those windows are always floating above the content.

This isn't a limitation imposed by the Navigation Component - the same issues apply to any usages of BottomSheetDialogFragment regarding the Fragment back stack and the system back button.

这篇关于如何防止BottomSheetDialogFragment在导航到另一个片段后解除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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