[go: up one dir, main page]

Skip to content

Commit

Permalink
Added view pager to home screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Morteza Taghdisi committed Feb 20, 2023
1 parent effade5 commit 05cc82f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ fun ComposentsDrawerMenu(
badge: @Composable ((ComposentsMenuItem) -> Unit)? = null,
content: @Composable () -> Unit,
) {
var currentSelectedItemId by remember { mutableStateOf(selectedItemId) }

val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)

ModalNavigationDrawer(
Expand All @@ -63,12 +61,11 @@ fun ComposentsDrawerMenu(
drawerTitleContent = drawerHeadlineContent,
coroutineScope = coroutineScope,
drawerState = drawerState,
selectedItemId = currentSelectedItemId,
selectedItemId = selectedItemId,
menuItems = menuItems,
badge = badge,
onDrawerItemClick = {
onMenuItemSelected(it)
currentSelectedItemId = it.id
},
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import androidx.compose.material.icons.outlined.Favorite
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import bluevelvet.composents.example.activity.auth.AuthActivity
import bluevelvet.composents.example.core.createJob
import bluevelvet.composents.foundation.*
Expand All @@ -23,6 +26,7 @@ import bluevelvet.composents.foundation.menu.ComposentsMenuItem
import bluevelvet.composents.foundation.menu.ComposentsMenuItemType
import bluevelvet.composents.ui.navigation.ComposentsDrawerMenu
import bluevelvet.composents.ui.navigation.ComposentsTopAppBar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay

class HomeActivity : ComponentActivity() {
Expand All @@ -32,17 +36,26 @@ class HomeActivity : ComponentActivity() {

setContent {
ComposentsExampleTheme {
DrawerMenuLayout()
val navController = rememberNavController()
val coroutineScope = rememberCoroutineScope()

DrawerMenuLayout(
navController = navController,
coroutineScope = coroutineScope
)
//AppbarMenuLayout()
}
}
}

@Composable
private fun DrawerMenuLayout() {
val drawerHomeMenuItem = ComposentsMenuItem(title = "Home", icon = Icons.Filled.Home, id = "home")
val drawerInboxMenuItem = ComposentsMenuItem(title = "Inbox", icon = Icons.Filled.Inbox, id = "inbox", badgeCount = 4)
val drawerSearchMenuItem = ComposentsMenuItem(title = "Search", icon = Icons.Filled.Search, id = "search")
private fun DrawerMenuLayout(
navController: NavHostController,
coroutineScope: CoroutineScope,
) {
val drawerHomeMenuItem = ComposentsMenuItem(title = "Home", icon = Icons.Filled.Home, id = Destinations.HOME)
val drawerInboxMenuItem = ComposentsMenuItem(title = "Inbox", icon = Icons.Filled.Inbox, id = Destinations.INBOX, badgeCount = 4)
val drawerSearchMenuItem = ComposentsMenuItem(title = "Search", icon = Icons.Filled.Search, id = Destinations.SEARCH)
val drawerExitMenuItem = ComposentsMenuItem(title = "Logout", icon = Icons.Filled.ExitToApp, id = "logout")
val drawerMenuItems = listOf(drawerHomeMenuItem, drawerInboxMenuItem, drawerSearchMenuItem, drawerExitMenuItem)

Expand All @@ -53,10 +66,22 @@ class HomeActivity : ComponentActivity() {
drawerHeadline = "Choose an item",
menuItems = drawerMenuItems,
selectedItemId = selectedDrawerMenuItem.id,
coroutineScope = coroutineScope,
onMenuItemSelected = {
selectedDrawerMenuItem = it
if (it.id == drawerExitMenuItem.id) {
// TODO: Log out the user
} else {
selectedDrawerMenuItem = it
navController.navigate(it.id)
}
},
) {
HomeNavGraph(
navController = navController,
selectedDrawerItem = selectedDrawerMenuItem
)

/* You also can use this approach instead of using NavHostGraph
when(selectedDrawerMenuItem.id) {
drawerHomeMenuItem.id -> HomeScreen()
drawerInboxMenuItem.id -> InboxScreen()
Expand All @@ -65,6 +90,7 @@ class HomeActivity : ComponentActivity() {
HomeScreen()
}
}
*/
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.navigation.compose.rememberNavController
import bluevelvet.composents.foundation.menu.ComposentsMenuItem
import bluevelvet.composents.example.screen.HomeScreen
import bluevelvet.composents.example.screen.InboxScreen
import bluevelvet.composents.example.screen.SearchScreen

/**
* Nav graph for the example app.
Expand All @@ -19,11 +20,12 @@ import bluevelvet.composents.example.screen.InboxScreen
object Destinations {
const val HOME = "home"
const val INBOX = "inbox"
const val SEARCH = "search"
}

@Composable
fun AppNavGraph(
navController: NavHostController = rememberNavController(),
fun HomeNavGraph(
navController: NavHostController,
selectedDrawerItem: ComposentsMenuItem
) {
NavHost(
Expand All @@ -36,5 +38,8 @@ fun AppNavGraph(
composable(Destinations.INBOX) {
InboxScreen()
}
composable(Destinations.SEARCH) {
SearchScreen()
}
}
}

0 comments on commit 05cc82f

Please sign in to comment.