This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Home
Suhas Dissanayake edited this page May 30, 2023
·
1 revision
I created this wiki to help contributors easily understand my code :)
+---app
| \---src
| \---main
| +---assets
| | \---databases # Contains the main database
| +---java
| | \---app
| | \---suhasdissa
| | \---foode
| | +---backend # Files Related to databases/repositories/viewmodels
| | | +---database
| | | | +---dao # Data access objects for Room
| | | | \---entities # Database Entities (Represents a single row in the database)
| | | +---repositories # Repositories get data from database and pass them to viewmodels with additional processing
| | | \---viewmodels # Viewmodels expose data to the ui elements. Data is persisted across recompositions
| | | \---states
| | +---ui # Ui elements
| | | +---components # Reusable components that can go inside main screens
| | | +---screens # Main Screens
| | | \---theme
| | \---utils # Small utility functions and objects
| \---res
| +---drawable
| +---mipmap-anydpi-v26
| +---mipmap-hdpi
| +---mipmap-mdpi
| +---mipmap-xhdpi
| +---mipmap-xxhdpi
| +---mipmap-xxxhdpi
| \---values # Mainly contains the string values with translations
\---screenshots
AppContainer.kt # Contains code for DI
Destinations.kt # Navigation Destinations
FoodeApplication.kt # Main Application class that also creates the app contaienr
NavHost.kt # Navigation Graph
I couldn't find good documentation about this feature. So I took my own approach at this.
I created TwoPane.kt
component that can hold two composable screens side by side
@Composable
fun TwoPaneScreen(
PaneOne: @Composable () -> Unit,
PaneTwo: @Composable () -> Unit
) {
Row(Modifier.fillMaxSize()) {
Column(
Modifier
.weight(0.5f)
.fillMaxHeight()
) {
PaneOne()
}
Column(
Modifier
.weight(0.5f)
.fillMaxHeight()
) {
PaneTwo()
}
}
}
So, the two pane layout is handled by the NavHost
. For example this is what I'm doing to show two panels in home screen
composable(route = Home.route) {
var additiveID by remember { mutableStateOf(0) }
if (isLargeScreen) {
TwoPaneScreen(PaneOne = {
HomeScreen(onClickTextCard = {
additiveID = it
}, onClickSearch = {
navController.navigateTo(SearchView.route)
}, onClickSettings = {
navController.navigateTo(Settings.route)
})
}, PaneTwo = {
AdditiveDetailScreen(additiveID)
})
} else {
HomeScreen(onClickTextCard = { id ->
navController.navigateTo("${AdditiveDetail.route}/$id")
}, onClickSearch = {
navController.navigateTo(SearchView.route)
}, onClickSettings = {
navController.navigateTo(Settings.route)
})
}
}