4

I've been searching through documentation and I could not find a confirmation. Does anyone know if the navigation and compose component from Android Jetpack are compatible with each other? I know that Jetpack Compose is not production ready and is only in developer preview mode, however I am testing with it and cannot seem to configure my project to work with both of these jetpack components.

Any information would be highly appreciated.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ljtomev
  • 898
  • 7
  • 11
  • Does this answer your question? [How to handle navigation in Jetpack Compose?](https://stackoverflow.com/questions/59620988/how-to-handle-navigation-in-jetpack-compose) – eli Jun 30 '20 at 11:54
  • Hi eli, I was trying to integrate jetpack compose within an existing project that already uses the jetpack navigation component. I think that solution is just a workaround to avoid the jetpack navigation component. Anyway, thank you. – ljtomev Jun 30 '20 at 11:57
  • 1
    Hi there, if anyone is still struggling with the Compose support in Navigation Component, please check out my library written exclusively for Compose: https://github.com/olshevski/compose-navigation-reimagined – olshevski Feb 04 '22 at 11:38

2 Answers2

6

Long-term, there will be first-class support in the Navigation component for Jetpack Compose. Google has indicated this on several occasions, mostly in the Kotlinlang Slack #compose channel.

Right now (30 June 2020), Navigation knows nothing about Compose. Eventually, my guess is that the Navigation DSL will support referencing composables (or lambdas that update states), but that is just a guess.

If you want to use both today, one option would be to continue using fragments:

  • Have Compose define the UI for those fragments
  • Have Navigation route between the fragments

Later, when Navigation directly supports Compose, you could "unwind" those fragments and do everything directly in Compose+Navigation.

Alternatively, there are non-Navigation routing options available from third parties (though, like Compose, they are all fairly new).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for your quick and detailed answer. Do you perhaps have any sources for how to use jetpack compose with fragments instead of activity? I would highly appreciate that :) – ljtomev Jun 30 '20 at 15:31
  • 3
    There is no `setContent()` extension function for `Fragment` right now, though they have discussed adding it. Right now, you would use `setContent()` on `ViewGroup`, for a `FrameLayout` that your fragment would set up as the destination for your composition. That too is likely to change (they are discussing getting rid of `ViewGroup.setContent()` and having a dedicated `AndroidComposeView` instead), but that's life with developer previews. :-) – CommonsWare Jun 30 '20 at 15:57
  • 1
    Just for reference here are the `ComposeView` docs: https://developer.android.com/jetpack/compose/interop – Joaquim Ley Sep 13 '20 at 21:23
5

There is now support for compose navigation with 1.0.0-alpha06 release. https://developer.android.com/jetpack/compose/navigation

Ziv Kesten
  • 1,206
  • 25
  • 41