Hey guys, I am having trouble getting any response...
# compose
m
Hey guys, I am having trouble getting any responses on Stack Overflow, so I'll try here. Has anyone tried having a single
Scaffold
for the entire app? I am trying to implement that just because of the awesome animations I am able to do with the FAB as well as the top and bottom bar, however, separation of concerns is a huge issue when having a single
Scaffold
.
z
I did something similar with one of my app screens. I made a sealed interface with an implementation for each of the subscreens. And I stored value of what the current subscreen is. something like this
Copy code
var currentScreen by remember { mutableStateOf(Screen.Home) }

Scaffold(
  topBar = {
    TopBar(
      title = { Text(currentScreen.title) }
    )
  }
) {
  when (currentScreen) {
    ...
  }
}
m
@zt Yeah, this part, that's the easy part. The difficult part is to get everything else working. For example, let's say you have a couple of action buttons on your TopAppBar. There's a back button, which takes you back to the previous screen. Since you have access to the NavHostController from your main Scaffold, it's as simple as
navController.navigateUp()
. However, what if you have a button which saves the data from the current screen (for example NewPlayerScreen) to the database? Suddenly, you need to have access to the NewPlayerScreenViewModel because that ViewModel has got the state of that screen and only that ViewModel can save the data from that screen to the database, because it's got the PlayerRepository injected into itself.
Let me know if you need more clarification, because I feel like my explanation might not convey the idea very well