JavierSegoviaCordoba
JavierSegoviaCordoba

Reputation: 6621

findNavController and isolated fragment

I launch a BottomSheetDialogFragment from the main fragment with the show function (navigation component can't start DialogFragments).

Now in the BottomSheetDialogFragment I have a button to move to a detail activity.

I have the BottomSheetDialogFragment defined in the graph (isolated) and it points to the detail activity.

But when I try to navigate, it can't find the navController. Is it possible to pass the navController to this isolated fragment?

MainFragment to Detail is working DialogFragment to Detail is not working.

I tried: - findNavController: navigation is not set - activity.findNavController(...)

enter image description here

Upvotes: 1

Views: 1540

Answers (1)

Ibrahim Ali
Ibrahim Ali

Reputation: 1297

But when I try to navigate, it can't find the navController. That's how navigation-component work.

Is it possible to pass the navController to this isolated fragment? I hope you will not going with that, replacing navController is not the perfect solution for your case.

What to do?

You can have new nav.xml with new parent activity and the (isolated) fragment as child, and navigate from the BottomSheetDialogFragment to (isolated) fragment-activity.

Otherwise, I don't see any problems that prevent you from adding related fragments in one nav.xml.

Also you may need to obey for navigation-component contract, don't use show() function while using navigation-component, you may miss some advantages here!

You really don't need show function see:-

Android Activity as a dialog

Explanation:-

You can have a parent activity and set it's theme as Dialog, so all fragments (inside the nav.xml) will be dialogs..

I used this trick in one of my apps before.

Upvotes: 1

Related Questions