Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”€ :: (#71) bottom nav compose #72

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ object MoizaIcons {
val CreateImage = R.drawable.ic_create_image
val WhitePlus = R.drawable.ic_plus_white
val WhiteClose = R.drawable.ic_close_white
val home = R.drawable.ic_home
val board = R.drawable.ic_board
val notification = R.drawable.ic_notification
val profile = R.drawable.ic_profile
}
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
@@ -0,0 +1,6 @@
package com.moizaandroid.moiza.ui.main

data class BottomNavItem(
val route: String,
val icon: Int
)
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() {

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ sealed class NavDestination(val title: String) {
const val FIND_PASSWORD_VERTIFICATION_CODE = "์ธ์ฆ๋ฒˆํ˜ธ ํ™•์ธ"
const val FIND_PASSWORD_RESET_PASSWORD = "๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌ์ž…๋ ฅ"
const val FIND_PASSWORD_FINISH_RESET = "๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌ๋“ฑ๋ก ์™„๋ฃŒ"
}

object BottomNav: NavDestination("BottomNav") {
const val HOME = "ํ™ˆ"
const val BOARD = "๊ฒŒ์‹œ๊ธ€"
const val NOTIFICATION = "์•Œ๋ฆผ"
const val PROFILE = "ํ”„๋กœํ•„"
}
}
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.