Jetpack Compose Clean Navigation

<p>Everybody in the Android world knows that navigation in Jetpack Compose isn&rsquo;t its brightest side. There are a lot of&nbsp;<code>callbacks</code>&nbsp;and&nbsp;<code>navControllers</code>&nbsp;that you need to pass to execute navigation, and what if you need to do some business logic before sending arguments? Code gets pretty messy.</p> <p>There are a lot of discussions on how to implement navigation, and&nbsp;one great library also. Feel free to check it out, shout out to Rafael Costa for creating something like that.</p> <p>But what if you don&rsquo;t want to be dependent on somebody else, or the policy of your company is to not use external libraries? Navigation is one of the most important things in the app. You can&rsquo;t rely on someone else, even tho that library is maintained 24/7. You need to create a solution, that works well. Before going through my clean solution, let&rsquo;s dive into the problem so we understand 100% what we are doing here.</p> <p>You pass lambdas, and that&rsquo;s it. The second option is that instead of lambdas you pass&nbsp;<code>navController</code>. Either solution doesn&rsquo;t look that good. The screen could have too many callbacks if it is complex enough. Your code gets messy a lot. Maybe your logic around routes isn&rsquo;t hardcoded like this, but you get the point of the problem.</p> <p>What if you need to do some business logic, for example, calculate something, and the result of the calculation is an argument for the next screen? You need to call&nbsp;<code>ViewModel</code>&nbsp;to do the business logic(the&nbsp;<code>View</code>shouldn&rsquo;t do that), observe the result and then invoke the callback. Too much forwards and backward between the&nbsp;<code>Screen</code>&nbsp;and&nbsp;<code>ViewModel</code>.</p> <p><a href="https://betterprogramming.pub/jetpack-compose-clean-navigation-94b386f7a076">Visit Now</a></p>