-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from everymeals/feature/bottom
[feature/bottom] BottomNavigation 및 4개 메인 Screen 생성
- Loading branch information
Showing
17 changed files
with
352 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
presentation/src/main/java/com/everymeal/presentation/ui/bottom/BottomNavigation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.everymeal.presentation.ui.bottom | ||
|
||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.StringRes | ||
import com.everymeal.presentation.R | ||
|
||
enum class BottomNavigation( | ||
val route: String, | ||
@DrawableRes val icon: Int, | ||
@StringRes val title: Int, | ||
) { | ||
HOME( | ||
route = EveryMealRoute.HOME.route, | ||
icon = R.drawable.icon_store, | ||
title = R.string.bottom_nav_home | ||
), | ||
UNIV_FOOD( | ||
route = EveryMealRoute.UNIV_FOOD.route, | ||
icon = R.drawable.icon_folk, | ||
title = R.string.bottom_nav_univ_food | ||
), | ||
WHAT_FOOD( | ||
route = EveryMealRoute.WHAT_FOOD.route, | ||
icon = R.drawable.icon_chat_bubble, | ||
title = R.string.bottom_nav_what_food | ||
), | ||
MY_PAGE( | ||
route = EveryMealRoute.MY_PAGE.route, | ||
icon = R.drawable.icon_user, | ||
title = R.string.bottom_nav_my_tab | ||
) | ||
} | ||
|
||
enum class EveryMealRoute(val route: String) { | ||
HOME("home"), | ||
UNIV_FOOD("univ-food"), | ||
WHAT_FOOD("what-food"), | ||
MY_PAGE("my-page"), | ||
} |
100 changes: 100 additions & 0 deletions
100
presentation/src/main/java/com/everymeal/presentation/ui/bottom/BottomNavigationScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.everymeal.presentation.ui.bottom | ||
|
||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.NavigationBar | ||
import androidx.compose.material3.NavigationBarItem | ||
import androidx.compose.material3.NavigationBarItemDefaults | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.res.vectorResource | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.navigation.NavDestination | ||
import androidx.navigation.NavGraph.Companion.findStartDestination | ||
import androidx.navigation.NavHostController | ||
import com.everymeal.presentation.ui.theme.Gray300 | ||
import com.everymeal.presentation.ui.theme.Gray500 | ||
import com.everymeal.presentation.ui.theme.Main100 | ||
import com.everymeal.presentation.ui.theme.Paddings | ||
|
||
@Composable | ||
fun EveryMealBottomNavigation( | ||
currentDestination: NavDestination?, | ||
navigateToScreen: (BottomNavigation) -> Unit, | ||
) { | ||
NavigationBar( | ||
containerColor = Color.White, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.clip(RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp)) | ||
.border( | ||
width = 1.dp, | ||
color = Gray300, | ||
shape = RoundedCornerShape(topStart = 14.dp, topEnd = 14.dp)), | ||
tonalElevation = Paddings.xextra | ||
) { | ||
BottomNavigation.values().forEach { bottomItem -> | ||
NavigationBarItem( | ||
icon = { | ||
Icon( | ||
imageVector = ImageVector.vectorResource(bottomItem.icon), | ||
contentDescription = bottomItem.route, | ||
tint = if (currentDestination?.route == bottomItem.route) { | ||
Main100 | ||
} else { | ||
Gray500 | ||
} | ||
) | ||
}, | ||
label = { | ||
Text( | ||
text = stringResource(bottomItem.title), | ||
color = if (currentDestination?.route == bottomItem.route) { | ||
Main100 | ||
} else { | ||
Gray500 | ||
}, | ||
style = TextStyle( | ||
fontSize = 12.sp, | ||
) | ||
) | ||
}, | ||
selected = currentDestination?.route == bottomItem.route, | ||
onClick = { navigateToScreen(bottomItem) }, | ||
colors = NavigationBarItemDefaults.colors(indicatorColor = Color.White), | ||
) | ||
} | ||
} | ||
} | ||
|
||
fun navigateBottomNavigationScreen( | ||
navController: NavHostController, | ||
navigationItem: BottomNavigation, | ||
) { | ||
navController.navigate(navigationItem.route) { | ||
popUpTo(navController.graph.findStartDestination().id) { | ||
saveState = true | ||
} | ||
launchSingleTop = true | ||
restoreState = true | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun PreviewEveryMealBottomNavigation() { | ||
EveryMealBottomNavigation( | ||
currentDestination = null, | ||
navigateToScreen = {} | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
presentation/src/main/java/com/everymeal/presentation/ui/home/HomeScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.everymeal.presentation.ui.home | ||
|
||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
|
||
@Composable | ||
fun HomeScreen( | ||
|
||
) { | ||
Text( | ||
text = "HomeScreen", | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun HomeScreenPreview() { | ||
HomeScreen() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
presentation/src/main/java/com/everymeal/presentation/ui/main/MainScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.everymeal.presentation.ui.main | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
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.everymeal.presentation.ui.bottom.BottomNavigation | ||
import com.everymeal.presentation.ui.bottom.EveryMealBottomNavigation | ||
import com.everymeal.presentation.ui.bottom.navigateBottomNavigationScreen | ||
import com.everymeal.presentation.ui.home.HomeScreen | ||
import com.everymeal.presentation.ui.mypage.MyPageScreen | ||
import com.everymeal.presentation.ui.univfood.UnivFoodScreen | ||
import com.everymeal.presentation.ui.whatfood.WhatFoodScreen | ||
|
||
@Composable | ||
fun MainScreen( | ||
navController: NavHostController = rememberNavController(), | ||
) { | ||
val navBackStackEntry by navController.currentBackStackEntryAsState() | ||
val currentDestination = navBackStackEntry?.destination | ||
|
||
Scaffold( | ||
bottomBar = { | ||
EveryMealBottomNavigation( | ||
currentDestination = currentDestination, | ||
navigateToScreen = { navigationItem -> | ||
navigateBottomNavigationScreen( | ||
navController = navController, | ||
navigationItem = navigationItem, | ||
) | ||
} | ||
) | ||
} | ||
) { padding -> | ||
NavHost( | ||
modifier = Modifier.padding(padding), | ||
navController = navController, | ||
startDestination = BottomNavigation.HOME.route, | ||
) { | ||
composable(route = BottomNavigation.HOME.route) { | ||
HomeScreen() | ||
} | ||
composable(route = BottomNavigation.UNIV_FOOD.route) { | ||
UnivFoodScreen() | ||
} | ||
composable(route = BottomNavigation.WHAT_FOOD.route) { | ||
WhatFoodScreen() | ||
} | ||
composable(route = BottomNavigation.MY_PAGE.route) { | ||
MyPageScreen() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun MainScreenPreview() { | ||
MainScreen() | ||
} |
21 changes: 21 additions & 0 deletions
21
presentation/src/main/java/com/everymeal/presentation/ui/mypage/MyPageScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.everymeal.presentation.ui.mypage | ||
|
||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
|
||
@Composable | ||
fun MyPageScreen( | ||
|
||
) { | ||
Text( | ||
text = "MyPageScreen", | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun MyPageScreenPreview() { | ||
MyPageScreen() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
presentation/src/main/java/com/everymeal/presentation/ui/univfood/UnivFoodScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.everymeal.presentation.ui.univfood | ||
|
||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
@Composable | ||
fun UnivFoodScreen( | ||
|
||
) { | ||
Text( | ||
text = "UnivFoodScreen", | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun UnivFoodScreenPreview() { | ||
UnivFoodScreen() | ||
} |
20 changes: 20 additions & 0 deletions
20
presentation/src/main/java/com/everymeal/presentation/ui/whatfood/WhatFoodScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.everymeal.presentation.ui.whatfood | ||
|
||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
@Composable | ||
fun WhatFoodScreen( | ||
|
||
) { | ||
Text( | ||
text = "WhatFoodScreen", | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun WhatFoodScreenPreview() { | ||
WhatFoodScreen() | ||
} |
Oops, something went wrong.