-
-
Save matpag/74ce059d590ff571c8240428b274c8c5 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<declare-styleable name="DialogFragmentNavigator"> | |
<attr name="android:name"/> | |
</declare-styleable> | |
</resources> |
example of how to use this gist, please?
@deckyfx @JackSparling Here the instructions: https://stackoverflow.com/a/55256858/2910520
Guys if you have problems, be sure to copy both the file and the style
Btw i've updated the gist fixing small typos
I am getting the error below even though I add DialogNavigator to my provider:
Caused by: java.lang.IllegalStateException: Could not find Navigator with name "dialog". You must call NavController.addNavigator() for each navigation type.
@nuhkocamobven I think your problem is that in your XML you used the dialog
tag instead of dialog-fragment
tag.
You should have your dialogs in the navigation graph like this:
<dialog-fragment
android:id="@+id/test_dialog"
android:name="com.example.testapp.dev.ui.todoadd.TodoAddFragment"
android:label="fragment_todolist"
tools:layout="@layout/fragment_todo_add" />
thanks for the code, it basically works.
But I found a problem, if we set a dialog-fragment
as start destination of a nested graph, after jumping from the main nav graph to this nested graph, if I want to nav to other destinations inside the same nested graph as the dialog-fragment
, it will crash caused by
navigation xxxxxx is unknown to this NavController
@kuno
I don't think currently this code supports a dialog-fragment
as start-destination.
I can see if I have time to dig into it more and try to fix that but currently is not working
PS: Remember that this is a temporary solution, for advanced cases like the one you mentioned, we probably should wait for the official implementation.
Updated the GIST to be used with:
Navigation 2.1.0-alpha02
Fragment 1.1.0-alpha06
Thanks for the reply and I fully agreed with u
Thanks but you can't close the dialog by calling either:
findNavController().popBackStack(R.id.fragmentId, false)
or
findNavController().popBackStack(R.id.fragmentId, false)
Only the back button works for closing.
@Willburt I will check the behaviour when i'm back to home
Please, any update on this?
@Wilburt Yes,
the trick currently is to replace the last line of navigate
method from
return null
to
return createDestination()
Then I used findNavController().popBackStack()
and it worked fine.
If you are using NavigationUI
with DrawerLayout or AppConfigurationBar probably you need manual handling when navigation is changed. Let me know how it goes :)
Thanks, it worked. Lucky, I am neither using a DrawerLayout or AppConfigurationBar.
Thanks.
What do you mean with tag? If you moved to the latest version of Navigation library, you need to remove all the stuff of this gist from your code and follow the official documentation on how to implement dialog-fragments
mine doesn't work. Unresolved reference: plusAssign and Line166: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch