Pablo
03/04/2024, 9:59 PMPablo
03/04/2024, 10:01 PMPablo
03/04/2024, 10:01 PMNavHost(
navController = navController,
startDestination = Screen.CategoriesListScreen.name,
modifier = Modifier
.padding(innerPadding)
.fillMaxHeight()
) {
if (screenType == ScreenType.LIST_ONLY) {
composable(route = Screen.CategoriesListScreen.name) {
ListScreen(
listItems = CategoriesProvider.categories,
onItemClicked = {
viewModel.updateCurrentCategory(it as Category)
navController.navigate(Screen.PlacesListScreen.name)
},
modifier = Modifier
)
}
composable(route = Screen.PlacesListScreen.name) {
ListScreen(
listItems = uiState.placesList,
onItemClicked = {
viewModel.updateCurrentPlace(it as Place)
navController.navigate(Screen.DetailScreen.name)
},
modifier = Modifier
)
}
composable(route = Screen.DetailScreen.name) {
PlaceDetail(
place = uiState.selectedPlace
)
}
} else {
composable(route = Screen.CategoriesListScreen.name) {
Row {
ListScreen(
listItems = CategoriesProvider.categories,
onItemClicked = {
viewModel.updateCurrentCategory(it as Category)
navController.navigate(Screen.PlacesListScreen.name)
},
modifier = Modifier.weight(1f)
)
ListScreen(
listItems = uiState.placesList,
onItemClicked = {
viewModel.updateCurrentPlace(it as Place)
navController.navigate(Screen.DetailScreen.name)
},
modifier = Modifier.weight(1f)
)
}
}
composable(route = Screen.PlacesListScreen.name) {
Row {
ListScreen(
listItems = uiState.placesList,
onItemClicked = {
viewModel.updateCurrentPlace(it as Place)
navController.navigate(Screen.DetailScreen.name)
},
modifier = Modifier.weight(1f)
)
PlaceDetail(
place = uiState.selectedPlace,
modifier = Modifier.weight(1f)
)
}
}
composable(route = Screen.DetailScreen.name) {
Row {
ListScreen(
listItems = uiState.placesList,
onItemClicked = {
viewModel.updateCurrentPlace(it as Place)
navController.navigate(Screen.DetailScreen.name)
},
modifier = Modifier.weight(1f)
)
PlaceDetail(
place = uiState.selectedPlace,
modifier = Modifier.weight(1f)
)
}
}
}
}
Ian Lake
03/04/2024, 10:37 PMPablo
03/04/2024, 10:44 PMPablo
03/04/2024, 10:44 PMPablo
03/04/2024, 10:46 PMenum class Screen {
CategoriesListScreen,
PlacesListScreen,
DetailScreen
}
enum class ExpandedScreen {
CategoriesAndPlacesScreen,
PlacesAndDetailScreen
}
Pablo
03/04/2024, 10:46 PMPablo
03/04/2024, 10:47 PMPablo
03/04/2024, 10:48 PMIan Lake
03/04/2024, 10:49 PMBackHandler
to handle system back separately from the NavHost's back handling to return to the list pane), but on larger devices it shows both panes side by side: Pablo
03/04/2024, 10:52 PMPablo
03/04/2024, 10:52 PMPablo
03/04/2024, 10:53 PMPablo
03/04/2024, 10:53 PMenum class Screen {
CategoriesListScreen,
PlacesListScreen,
DetailScreen
}
Ian Lake
03/04/2024, 10:53 PMPablo
03/04/2024, 10:53 PMCategoriesListScreen,
PlacesListScreen,
and
PlacesListScreen,
DetailScreen
Ian Lake
03/04/2024, 10:54 PMPablo
03/04/2024, 10:54 PMPablo
03/04/2024, 10:54 PMPablo
03/04/2024, 10:54 PMPablo
03/04/2024, 10:55 PMPlacesListScreen,
DetailScreen
The second screen should have the second and the third routes combined
PlacesListScreen,
DetailScreen
Pablo
03/04/2024, 10:55 PMPablo
03/04/2024, 10:56 PMPablo
03/04/2024, 10:57 PMPablo
03/04/2024, 10:57 PMPablo
03/04/2024, 10:57 PMIan Lake
03/04/2024, 11:00 PMPablo
03/04/2024, 11:03 PMPablo
03/04/2024, 11:03 PMCategoriesListScreen,
PlacesListScreen,
The second screen should have the second and the third routes combined
PlacesListScreen,
DetailScreen
Ian Lake
03/04/2024, 11:04 PMPablo
03/04/2024, 11:04 PMIan Lake
03/04/2024, 11:04 PMIan Lake
03/04/2024, 11:05 PMCategoriesListScreen
slides out to the left, PlacesListScreen
moves over, DetailScreen
slides in, etc. - that is the only way that the state of PlaceesListScreen
is going to be stable and kept as you move back and forthIan Lake
03/04/2024, 11:06 PMPablo
03/04/2024, 11:06 PMPablo
03/04/2024, 11:07 PMPablo
03/04/2024, 11:07 PMIan Lake
03/04/2024, 11:10 PMPablo
03/04/2024, 11:10 PMPablo
03/04/2024, 11:11 PMPablo
03/04/2024, 11:11 PMPablo
03/04/2024, 11:12 PMIan Lake
03/04/2024, 11:14 PMIan Lake
03/04/2024, 11:16 PMPablo
03/04/2024, 11:17 PMPablo
03/04/2024, 11:17 PMPablo
03/04/2024, 11:17 PMPablo
03/04/2024, 11:18 PMPablo
03/04/2024, 11:18 PMNavHost(
navController = navController,
startDestination = Screen.CategoriesListScreen.name,
modifier = modifier.fillMaxHeight()
) {
composable(route = Screen.CategoriesListScreen.name) {
ListScreen(
listItems = CategoriesProvider.categories,
onItemClicked = { onCategoryClicked(it as Category) },
modifier = Modifier
)
}
composable(route = Screen.PlacesListScreen.name) {
ListScreen(
listItems = uiState.placesList,
onItemClicked = { onPlaceClicked(it as Place) },
modifier = Modifier
)
}
composable(route = Screen.DetailScreen.name) {
PlaceDetail(
place = uiState.selectedPlace,
onPlaceBackPressed
)
}
}
Pablo
03/04/2024, 11:18 PMIan Lake
03/04/2024, 11:18 PMPlacesListScreen
to have the same state whether you are in `CategoriesListScreen`+`PlacesListScreen` or `PlacesListScreen`+`DetailScreen`, then that all needs to be in one routeIan Lake
03/04/2024, 11:19 PMPablo
03/04/2024, 11:19 PMPablo
03/04/2024, 11:19 PMPablo
03/04/2024, 11:19 PMPablo
03/04/2024, 11:19 PMPablo
03/04/2024, 11:20 PMPablo
03/04/2024, 11:20 PMIan Lake
03/04/2024, 11:24 PMPlacesListScreen
from the right half of the screen to the left to be `PlacesListScreen`+`DetailScreen`. That's one route. You don't even need Navigation if that's your entire app (but maybe you have a photo viewer that takes the full screen - that would be a good example of where you need a second route)
Now that you've gotten your tablet layout working, your problem is much easier: how does your three pane layout adapt to screen sizes that don't fit two panes side by side. Easy: it only displays one pane at a time. Nothing else changes, your three pane layout just adapts to smaller screen sizesPablo
03/04/2024, 11:27 PMNavHost(
navController = navController,
startDestination = Screen.CategoriesListScreen.name,
modifier = modifier.fillMaxHeight()
) {
composable(route = Screen.PlacesListScreen.name) {
ListScreen(
listItems = uiState.placesList,
onItemClicked = { onPlaceClicked(it as Place) },
modifier = Modifier
)
}
composable(route = Screen.DetailScreen.name) {
PlaceDetail(
place = uiState.selectedPlace,
onPlaceBackPressed
)
}
}
how can I fill that navigation component when the app is in expanded device?Pablo
03/04/2024, 11:31 PMIan Lake
03/04/2024, 11:31 PMPablo
03/04/2024, 11:31 PMPablo
03/04/2024, 11:32 PMIan Lake
03/04/2024, 11:32 PMPablo
03/04/2024, 11:33 PMPablo
03/04/2024, 11:33 PMPablo
03/04/2024, 11:33 PMPablo
03/04/2024, 11:33 PMPablo
03/04/2024, 11:34 PMPablo
03/04/2024, 11:35 PMPablo
03/04/2024, 11:35 PMPablo
03/04/2024, 11:35 PMPablo
03/04/2024, 11:35 PMPablo
03/04/2024, 11:36 PMPablo
03/04/2024, 11:37 PMPablo
03/04/2024, 11:38 PMPablo
03/04/2024, 11:44 PMPablo
03/04/2024, 11:45 PMIan Lake
03/04/2024, 11:45 PMPablo
03/04/2024, 11:47 PMStylianos Gakis
03/04/2024, 11:48 PMin a compact device a list detail is perfect for two screens and for using navigation
Yes, but I feel like you gotta think of this from both perspectives and then work with that. If you only had phone UI yes two routes makes sense. In tablet it does not make sense to have two routes, it's not possible in fact. So you're in this situation where you gotta find what's the common denominator between the two. You can't have two routes on the tablet UI. But you can absolutely make do with one route and some internal navigation with a BackHandler on your phone UI. So there you have it, you choose the common denominator and go with that solution. And the video shows how that BackHandler would be used only in that phone case, and only when you are on the detail screen. I feel like that's what Ian is trying to convey to you.
Pablo
03/04/2024, 11:50 PMPablo
03/04/2024, 11:51 PMStylianos Gakis
03/04/2024, 11:54 PMPablo
03/04/2024, 11:54 PMPablo
03/04/2024, 11:54 PMStylianos Gakis
03/04/2024, 11:55 PMPablo
03/04/2024, 11:56 PMPablo
03/04/2024, 11:57 PMStylianos Gakis
03/04/2024, 11:57 PMPablo
03/04/2024, 11:57 PMPablo
03/04/2024, 11:58 PMPablo
03/04/2024, 11:59 PMPablo
03/04/2024, 11:59 PMStylianos Gakis
03/05/2024, 12:08 AM