Jetpack navigation component has a nice visual representation of nav_graph.xml
file between fragments, however if we use navigation component for Jetpack Compose there is no support nav_graph.xml
for composable functions. Then the question is how visually to see the navigation graph between composable widgets and screens similarly what we can see
with nav_graph.xml
in Android Studio?
Question posted in Android Studio
The official documentation can be found here.
The official documentation can be found here.
2
Answers
Visualization of composable functions in Jetpack Compose Navigation is not supported in Android Studio at the moment. However as a workaround you could use Jetpack Navigation library and preview your composable widgets inside of fragments.
Workaround:
To get preview working, we can use Jetpack Navigation library (non-compose version) for handling navigation inside the app and previewing graphs. Therefore, we need to use our composable widgets inside of a
Fragment
.Create
XML
resource for yourFragment
with a root element beingComposeView
:In
tools:composableName
attribute specify full path to your annotated@Preview
function.Then create a
Fragment
for your composable widget (how):Create graph
res/navigation/home_graph
and add your fragment:Don’t forget to specify
tools:layout
tag as it tells Android Studio to draw the preview ofXML
file.Build project and you will see working preview of a composable function inside the navigation graph!
We don’t have a visual representation of the graph yet. This article also mentioned.
https://medium.com/google-developer-experts/navigating-in-jetpack-compose-78c78d365c6a