Hi everyone! Does anyone here has experience build...
# compose
j
Hi everyone! Does anyone here has experience building medium-large scale app (in production) using Compose Navigation? If yes, how was it for you and what are your thoughts about it? Do you recommend it? I’m about to write a new app and I’m hesitant between using full “Compose + Compose Navigation” vs “Navigation Component with Fragments + ComposeView”. Hoping someone could shed a light. 🙂 PS. I’d prefer not using a 3rd party navigation library
l
Don't use Fragments for a new project.
fist bump 6
☝️ 4
s
Use androidx.navigation, and make sure to follow the principles here https://developer.android.com/guide/navigation/principles Read this message https://kotlinlang.slack.com/archives/CJLTWPH7S/p1661620380882159?thread_ts=1661611283.762479&cid=CJLTWPH7S and the one linked to it. Now read it again. And then probably come back to it many times in the future. You need to properly understand what Ian tries to convey here. Once you do that you're gonna be in a spot where adding navigation screens is gonna be a breeze, especially in a multi-module app. Here's an example of a module contributing their own nav graph into the rest of the app using this technique. Where everything else is internal to the library. Aka the rest of the app sees the entry-point to that feature, but the rest isn't accessible at all, making it easy not to accidentally navigate to the wrong place. This then allows you to have your "Screens" look like this on the graph side and this on the screen impl. One composable internally accessible to that module screen which knows nothing about what kind of navigation you are doing, and simply gets lambdas to forward the right things up to your NavController. The ViewModel coming in there, scoped to the right destination. (Here btw you can probably also use the fact that the VM will get the nav arguments passed into it, and not have to do the forwarding we do. By using this https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:navigati[…]38-40?q=toRoute&ss=androidx%2Fplatform%2Fframeworks%2Fsupport from the type-safe support of androidx.navigation). And then a private screen which does not even know about the VM, and is very easily previewable. If you ever want a project to look at, look at the one I work at https://github.com/HedvigInsurance/android/blob/6b68a2f3a075336e6c28e7cb958ebb1e72[…]/main/kotlin/com/hedvig/android/app/navigation/HedvigNavHost.kt we use it along with this type-safe library wrapper, but the official one has type-safety in there too. We'll migrate eventually. You should just start using the official solution from the get go.
j
Thanks for the detailed response! I will look into this 🙌