Skip to content

Commit feb2f03

Browse files
authored
Merge pull request #34 from everymeals/feature/bottom
[feature/bottom] BottomNavigation 및 4개 메인 Screen 생성
2 parents b3622cc + 80fe083 commit feb2f03

17 files changed

+352
-26
lines changed

app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
android:usesCleartextTraffic="true"
1818
tools:targetApi="31">
1919
<activity
20-
android:name="com.everymeal.presentation.MainActivity"
20+
android:name="com.everymeal.presentation.ui.main.MainActivity"
2121
android:label="@string/app_name"
2222
android:theme="@style/Theme.EveryMeal_Android">
2323

gradle/libs.versions.toml

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ kotlin-serilization = "1.0.0"
1919

2020
lottie = "6.0.0"
2121

22+
compose-navigation = "2.4.2"
23+
2224
[libraries]
2325
agp = { module = "com.android.tools.build:gradle", version.ref = "agp" }
2426
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
@@ -62,6 +64,10 @@ kotlin-serilization = { module = "com.jakewharton.retrofit:retrofit2-kotlinx-ser
6264
#Lottie
6365
compose-lottie = { module = "com.airbnb.android:lottie-compose", version.ref = "lottie" }
6466

67+
#Compose-Navigation
68+
compose-navigation = { module = "androidx.navigation:navigation-compose", version.ref = "compose-navigation" }
69+
70+
6571
[plugins]
6672
androidApplication = { id = "com.android.application", version.ref = "agp" }
6773
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

presentation/build.gradle.kts

+3
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,7 @@ dependencies {
7575

7676
// Lottie
7777
implementation(libs.compose.lottie)
78+
79+
// Navigation
80+
implementation(libs.compose.navigation)
7881
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.everymeal.presentation.ui.bottom
2+
3+
import androidx.annotation.DrawableRes
4+
import androidx.annotation.StringRes
5+
import com.everymeal.presentation.R
6+
7+
enum class BottomNavigation(
8+
val route: String,
9+
@DrawableRes val icon: Int,
10+
@StringRes val title: Int,
11+
) {
12+
HOME(
13+
route = EveryMealRoute.HOME.route,
14+
icon = R.drawable.icon_store,
15+
title = R.string.bottom_nav_home
16+
),
17+
UNIV_FOOD(
18+
route = EveryMealRoute.UNIV_FOOD.route,
19+
icon = R.drawable.icon_folk,
20+
title = R.string.bottom_nav_univ_food
21+
),
22+
WHAT_FOOD(
23+
route = EveryMealRoute.WHAT_FOOD.route,
24+
icon = R.drawable.icon_chat_bubble,
25+
title = R.string.bottom_nav_what_food
26+
),
27+
MY_PAGE(
28+
route = EveryMealRoute.MY_PAGE.route,
29+
icon = R.drawable.icon_user,
30+
title = R.string.bottom_nav_my_tab
31+
)
32+
}
33+
34+
enum class EveryMealRoute(val route: String) {
35+
HOME("home"),
36+
UNIV_FOOD("univ-food"),
37+
WHAT_FOOD("what-food"),
38+
MY_PAGE("my-page"),
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.everymeal.presentation.ui.bottom
2+
3+
import androidx.compose.foundation.border
4+
import androidx.compose.foundation.layout.fillMaxWidth
5+
import androidx.compose.foundation.shape.RoundedCornerShape
6+
import androidx.compose.material3.Icon
7+
import androidx.compose.material3.NavigationBar
8+
import androidx.compose.material3.NavigationBarItem
9+
import androidx.compose.material3.NavigationBarItemDefaults
10+
import androidx.compose.material3.Text
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.Modifier
13+
import androidx.compose.ui.draw.clip
14+
import androidx.compose.ui.graphics.Color
15+
import androidx.compose.ui.graphics.vector.ImageVector
16+
import androidx.compose.ui.res.stringResource
17+
import androidx.compose.ui.res.vectorResource
18+
import androidx.compose.ui.text.TextStyle
19+
import androidx.compose.ui.tooling.preview.Preview
20+
import androidx.compose.ui.unit.dp
21+
import androidx.compose.ui.unit.sp
22+
import androidx.navigation.NavDestination
23+
import androidx.navigation.NavGraph.Companion.findStartDestination
24+
import androidx.navigation.NavHostController
25+
import com.everymeal.presentation.ui.theme.Gray300
26+
import com.everymeal.presentation.ui.theme.Gray500
27+
import com.everymeal.presentation.ui.theme.Main100
28+
import com.everymeal.presentation.ui.theme.Paddings
29+
30+
@Composable
31+
fun EveryMealBottomNavigation(
32+
currentDestination: NavDestination?,
33+
navigateToScreen: (BottomNavigation) -> Unit,
34+
) {
35+
NavigationBar(
36+
containerColor = Color.White,
37+
modifier = Modifier
38+
.fillMaxWidth()
39+
.clip(RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp))
40+
.border(
41+
width = 1.dp,
42+
color = Gray300,
43+
shape = RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp)),
44+
tonalElevation = Paddings.xextra
45+
) {
46+
BottomNavigation.values().forEach { bottomItem ->
47+
NavigationBarItem(
48+
icon = {
49+
Icon(
50+
imageVector = ImageVector.vectorResource(bottomItem.icon),
51+
contentDescription = bottomItem.route,
52+
tint = if (currentDestination?.route == bottomItem.route) {
53+
Main100
54+
} else {
55+
Gray500
56+
}
57+
)
58+
},
59+
label = {
60+
Text(
61+
text = stringResource(bottomItem.title),
62+
color = if (currentDestination?.route == bottomItem.route) {
63+
Main100
64+
} else {
65+
Gray500
66+
},
67+
style = TextStyle(
68+
fontSize = 12.sp,
69+
)
70+
)
71+
},
72+
selected = currentDestination?.route == bottomItem.route,
73+
onClick = { navigateToScreen(bottomItem) },
74+
colors = NavigationBarItemDefaults.colors(indicatorColor = Color.White),
75+
)
76+
}
77+
}
78+
}
79+
80+
fun navigateBottomNavigationScreen(
81+
navController: NavHostController,
82+
navigationItem: BottomNavigation,
83+
) {
84+
navController.navigate(navigationItem.route) {
85+
popUpTo(navController.graph.findStartDestination().id) {
86+
saveState = true
87+
}
88+
launchSingleTop = true
89+
restoreState = true
90+
}
91+
}
92+
93+
@Preview
94+
@Composable
95+
fun PreviewEveryMealBottomNavigation() {
96+
EveryMealBottomNavigation(
97+
currentDestination = null,
98+
navigateToScreen = {}
99+
)
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.everymeal.presentation.ui.home
2+
3+
import androidx.compose.material3.Text
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.tooling.preview.Preview
6+
7+
8+
@Composable
9+
fun HomeScreen(
10+
11+
) {
12+
Text(
13+
text = "HomeScreen",
14+
)
15+
}
16+
17+
@Preview
18+
@Composable
19+
fun HomeScreenPreview() {
20+
HomeScreen()
21+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.everymeal.presentation
1+
package com.everymeal.presentation.ui.main
22

33
import android.content.Context
44
import android.content.Intent
@@ -19,15 +19,14 @@ import dagger.hilt.android.AndroidEntryPoint
1919
class MainActivity : ComponentActivity() {
2020
override fun onCreate(savedInstanceState: Bundle?) {
2121
super.onCreate(savedInstanceState)
22+
23+
setMainScreen()
24+
}
25+
26+
private fun setMainScreen() {
2227
setContent {
2328
EveryMeal_AndroidTheme {
24-
// A surface container using the 'background' color from the theme
25-
Surface(
26-
modifier = Modifier.fillMaxSize(),
27-
color = MaterialTheme.colorScheme.background
28-
) {
29-
Greeting("Android")
30-
}
29+
MainScreen()
3130
}
3231
}
3332
}
@@ -38,20 +37,4 @@ class MainActivity : ComponentActivity() {
3837
context.startActivity(intent)
3938
}
4039
}
41-
}
42-
43-
@Composable
44-
fun Greeting(name: String, modifier: Modifier = Modifier) {
45-
Text(
46-
text = "Hello $name!",
47-
modifier = modifier
48-
)
49-
}
50-
51-
@Preview(showBackground = true)
52-
@Composable
53-
fun GreetingPreview() {
54-
EveryMeal_AndroidTheme {
55-
Greeting("Android")
56-
}
5740
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.everymeal.presentation.ui.main
2+
3+
import androidx.compose.foundation.layout.padding
4+
import androidx.compose.material3.Scaffold
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.runtime.getValue
7+
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.tooling.preview.Preview
9+
import androidx.navigation.NavHostController
10+
import androidx.navigation.compose.NavHost
11+
import androidx.navigation.compose.composable
12+
import androidx.navigation.compose.currentBackStackEntryAsState
13+
import androidx.navigation.compose.rememberNavController
14+
import com.everymeal.presentation.ui.bottom.BottomNavigation
15+
import com.everymeal.presentation.ui.bottom.EveryMealBottomNavigation
16+
import com.everymeal.presentation.ui.bottom.navigateBottomNavigationScreen
17+
import com.everymeal.presentation.ui.home.HomeScreen
18+
import com.everymeal.presentation.ui.mypage.MyPageScreen
19+
import com.everymeal.presentation.ui.univfood.UnivFoodScreen
20+
import com.everymeal.presentation.ui.whatfood.WhatFoodScreen
21+
22+
@Composable
23+
fun MainScreen(
24+
navController: NavHostController = rememberNavController(),
25+
) {
26+
val navBackStackEntry by navController.currentBackStackEntryAsState()
27+
val currentDestination = navBackStackEntry?.destination
28+
29+
Scaffold(
30+
bottomBar = {
31+
EveryMealBottomNavigation(
32+
currentDestination = currentDestination,
33+
navigateToScreen = { navigationItem ->
34+
navigateBottomNavigationScreen(
35+
navController = navController,
36+
navigationItem = navigationItem,
37+
)
38+
}
39+
)
40+
}
41+
) { padding ->
42+
NavHost(
43+
modifier = Modifier.padding(padding),
44+
navController = navController,
45+
startDestination = BottomNavigation.HOME.route,
46+
) {
47+
composable(route = BottomNavigation.HOME.route) {
48+
HomeScreen()
49+
}
50+
composable(route = BottomNavigation.UNIV_FOOD.route) {
51+
UnivFoodScreen()
52+
}
53+
composable(route = BottomNavigation.WHAT_FOOD.route) {
54+
WhatFoodScreen()
55+
}
56+
composable(route = BottomNavigation.MY_PAGE.route) {
57+
MyPageScreen()
58+
}
59+
}
60+
}
61+
}
62+
63+
@Preview
64+
@Composable
65+
fun MainScreenPreview() {
66+
MainScreen()
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.everymeal.presentation.ui.mypage
2+
3+
import androidx.compose.material3.Text
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.tooling.preview.Preview
6+
7+
8+
@Composable
9+
fun MyPageScreen(
10+
11+
) {
12+
Text(
13+
text = "MyPageScreen",
14+
)
15+
}
16+
17+
@Preview
18+
@Composable
19+
fun MyPageScreenPreview() {
20+
MyPageScreen()
21+
}

presentation/src/main/java/com/everymeal/presentation/ui/signup/UnivSelectActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import android.content.Intent
55
import android.os.Bundle
66
import androidx.activity.ComponentActivity
77
import androidx.activity.compose.setContent
8-
import com.everymeal.presentation.MainActivity
8+
import com.everymeal.presentation.ui.main.MainActivity
99
import com.everymeal.presentation.ui.theme.EveryMeal_AndroidTheme
1010
import dagger.hilt.android.AndroidEntryPoint
1111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.everymeal.presentation.ui.univfood
2+
3+
import androidx.compose.material3.Text
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.tooling.preview.Preview
6+
7+
@Composable
8+
fun UnivFoodScreen(
9+
10+
) {
11+
Text(
12+
text = "UnivFoodScreen",
13+
)
14+
}
15+
16+
@Preview
17+
@Composable
18+
fun UnivFoodScreenPreview() {
19+
UnivFoodScreen()
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.everymeal.presentation.ui.whatfood
2+
3+
import androidx.compose.material3.Text
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.tooling.preview.Preview
6+
7+
@Composable
8+
fun WhatFoodScreen(
9+
10+
) {
11+
Text(
12+
text = "WhatFoodScreen",
13+
)
14+
}
15+
16+
@Preview
17+
@Composable
18+
fun WhatFoodScreenPreview() {
19+
WhatFoodScreen()
20+
}

0 commit comments

Comments
 (0)