I'm having trouble figuring out what "screen" I'm ...
# compose
c
I'm having trouble figuring out what "screen" I'm on since I joined a new codebase. When joining a new android project, in the past I just put a log statement in the base activity or basefragment, OR just took a look at the profiler in Android studio and it called out each fragment transaction, etc. Is there a way to do something similar in compose to learn what "screens"/destinations make up an app? I started on a new app today and I'm finding it really hard to figure out what classes relate to which screens. Maybe something in compose nav could help (im investigating) but wanted to see if anyone else had any tips.
n
Could you move that log statement to the screens ViewModel or Presenter? I'm assuming each screen has its own ViewModel or Presenter so you can map that to screens
j
If you’re looking for one central place to put a single log statement that’ll tell you every screen then the place that comes to mind for me is inside the NavHost Composable definitions if they are using navigation compose.
You could also collect the visibleEntries flow off of the NavController and log when that changes.
l
Can you use the Layout Inspector? When you open the app, it should give you the composable structure. You should be able to find some ‘Top Level’ composable for the screen and search for it.
c
oh. layout inspector is a good idea. idk y i didnt think of that. I ended up finding that nav controller had a dest changed listener!
Copy code
val navController = rememberAnimatedNavController()
navController.addOnDestinationChangedListener(NavController.OnDestinationChangedListener { controller, destination, arguments ->
     Log.e("LEARNING", "route: ${destination.route}")
})
thanks everyone for the ideas
i
It also has a Flow if you'd rather collect on that (e.g., in a LaunchedEffect), which will give you the coroutine scoping / clean up side automatically instead of calling
addOnDestinationChangedListener
as part of composition (which is going to give you more and more copies if you ever recompose that function): https://developer.android.com/reference/androidx/navigation/NavController#currentBackStackEntryFlow()