1

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

JavierSegoviaCordoba
  • 6,531
  • 9
  • 37
  • 51
  • **MainFragment to Detail is working DialogFragment to Detail is not working.** It won't work because you opened it using `show` function. You need to start with navigation-component to continue with it. If you used `show` function` you better continue with it, Unless you choose the workaround I suggest in my answer below. – Ibrahim Ali Apr 10 '19 at 21:40
  • @IbrahimAli all the animation I used for it will work? – JavierSegoviaCordoba Apr 10 '19 at 21:44
  • see how to set animation using nav-comp https://developer.android.com/guide/navigation/navigation-animate-transitions – Ibrahim Ali Apr 10 '19 at 21:50
  • @IbrahimAli I will try it in some days (I have to travel tomorrow) I will post the result – JavierSegoviaCordoba Apr 10 '19 at 22:27

1 Answers1

1

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.

Ibrahim Ali
  • 1,237
  • 9
  • 20