Posts

Showing posts with the label LaunchedEffect

Navigation 3 - Part 3 - Muscle Car Example

Image
Part 3 As mentioned in Part 2 , this series is a little longer than I had originally hoped. In this third (and hopefully final) part, we will cover ViewModels with Navigation3 and make something that looks a little nicer. The code listing is quite long so I will avoid explaining the UI elements here and focus on the sections relevant to Navigation3 . If you haven't already read the previous entries and are not already familiar with Navigation3 , I strongly recommend starting with Part 1 . The main goal here is to give you a working sample to play with. This post will not go into too much detail on each of these points so you will need to read around any new subjects that come up to learn more. Notes - Saving Data One compromise I chose to make was not saving any data . You will be able to take notes for each car, but those notes will vanish when you change to another page. If you want to store those notes, please take a look at my DataStore post or my Room3 post . That should give...

Navigation 3 - Part 1 - Buggy Old Example 2

Image
  Broken Example 2 I want to publish this in addition to the original blog post so you can see my first broken solution. I think many people are reluctant to publish their mistakes, but I believe it can be a useful learning tool. I will keep most of the text exactly as originally published but I've changed some of the naming to make it clear that it should not be used. I'll add some additional comments at the end. Original Posting: Our second version does things a little differently. We'll reuse a lot of the Composables from the first so you will need to add those yourself if you are only creating version 2. LocalNavigate (for GuardedNavigate) We will use a function to prevent us flooding the backstack. This function is backed by a static  CompositionLocal . object BasicNav2OldBuggy { private val LocalNavigate = staticCompositionLocalOf <(NavigationScreen) -> Unit> { error ( "No LocalNavigate provided" ) } ... LocalNavigate  is our static  Composi...

Navigation 3 - Part 1 - Basic Examples

Image
Overview Navigation3 , the Compose-first Navigation library, was released as stable back in mid November ('25). April 22nd it was updated to 1.1.1. Let's take a look at it. There are three (originally planned for two) parts to this series. In Part 1 , we will deal with a minimal example of navigation as well as a refined version that fixes some issues. In  Part 2,  we will cover dual pane support. Part 3 we will dive into a more complex version that supports Wider Screens (two-pane layout) and ViewModels . This first post is designed for anyone interested in getting Navigation3 up and running as quickly as possible and exploring how to improve the basics. The follow up will be a good post for a more realistic use case and will have some nice visuals (in the screenshots / animations at least). We'll keep the visuals simple for this first one and limit the different pages to slight color variations to help understand the transitions. Ideally, I would make a Part 4 or even a...