Skip to content

Commit

Permalink
⚡️ :: BottomNavigation Route
Browse files Browse the repository at this point in the history
  • Loading branch information
100Seung-Min committed Aug 10, 2022
1 parent 3c4584a commit b743462
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.moizaandroid.moiza.ui.board

import androidx.compose.runtime.Composable

@Composable
fun BoardScreen() {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.moizaandroid.moiza.ui.home

import androidx.compose.runtime.Composable

@Composable
fun HomeScreen() {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,118 @@ package com.moizaandroid.moiza.ui.main


import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.moizaandroid.moiza.R
import com.moizaandroid.moiza.databinding.ActivityMainBinding
import com.moizaandroid.moiza.ui.base.BaseActivity
import androidx.compose.foundation.layout.height
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.moiza_design.icon.MoizaIcons
import com.moiza_design.theme.Blue
import com.moiza_design.theme.Gray500
import com.moizaandroid.moiza.ui.board.BoardScreen
import com.moizaandroid.moiza.ui.home.HomeScreen
import com.moizaandroid.moiza.ui.notification.NotificationScreen
import com.moizaandroid.moiza.ui.profile.ProfileScreen
import com.moizaandroid.moiza.utils.NavDestination
import com.moizaandroid.moiza.viewmodel.MainViewModel

class MainActivity : BaseActivity<ActivityMainBinding>(
R.layout.activity_main
) {
class MainActivity : ComponentActivity() {
private val mainViewModel by viewModels<MainViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

initBottomNavBar()
setContent {
val navController = rememberNavController()
Scaffold(
bottomBar = {
BottomNavigationBar(
itemList = listOf(
BottomNavItem(
route = NavDestination.BottomNav.HOME,
icon = MoizaIcons.home
),
BottomNavItem(
route = NavDestination.BottomNav.BOARD,
icon = MoizaIcons.board
),
BottomNavItem(
route = NavDestination.BottomNav.NOTIFICATION,
icon = MoizaIcons.notification
),
BottomNavItem(
route = NavDestination.BottomNav.PROFILE,
icon = MoizaIcons.profile
)
),
modifier = Modifier,
navController = navController,
onItemClick = {
navController.navigate(it.route)
})
}
) {
Navigation(navController = navController)
}
}
}
}

private fun initBottomNavBar() {
val navController =
supportFragmentManager.findFragmentById(R.id.fragmentView)?.findNavController()
val nav = binding.bottomNav as BottomNavigationView
navController?.let {
nav.setupWithNavController(navController)
@Composable
fun Navigation(navController: NavHostController) {
NavHost(navController = navController, startDestination = NavDestination.BottomNav.HOME) {
composable(route = NavDestination.BottomNav.HOME) {
HomeScreen()
}
composable(route = NavDestination.BottomNav.BOARD) {
BoardScreen()
}
composable(route = NavDestination.BottomNav.NOTIFICATION) {
NotificationScreen()
}
composable(route = NavDestination.BottomNav.PROFILE) {
ProfileScreen()
}
}
}

override fun initView() {}

override fun observeEvent() {}
}
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun BottomNavigationBar(
itemList: List<BottomNavItem>,
navController: NavHostController,
modifier: Modifier,
onItemClick: (BottomNavItem) -> Unit
) {
val backStackEntry = navController.currentBackStackEntryAsState()
BottomNavigation(
modifier = modifier,
backgroundColor = Color.White
) {
itemList.forEach{ item ->
val selected = item.route == backStackEntry.value?.destination?.route
BottomNavigationItem(
selected = selected,
onClick = { onItemClick(item) },
selectedContentColor = Blue,
unselectedContentColor = Gray500,
icon = {
Icon(
painter = painterResource(id = item.icon),
contentDescription = item.route,
modifier = Modifier.height(20.dp)
)
}
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.moizaandroid.moiza.ui.notification

import androidx.compose.runtime.Composable

@Composable
fun NotificationScreen() {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.moizaandroid.moiza.ui.profile

import androidx.compose.runtime.Composable

@Composable
fun ProfileScreen() {

}
41 changes: 0 additions & 41 deletions presentation/src/main/res/layout/activity_main.xml

This file was deleted.

19 changes: 0 additions & 19 deletions presentation/src/main/res/menu/bottom_nav_menu.xml

This file was deleted.

28 changes: 0 additions & 28 deletions presentation/src/main/res/navigation/bottom_nav_graph.xml

This file was deleted.

0 comments on commit b743462

Please sign in to comment.