Skip to content

Commit

Permalink
Merge pull request #34 from everymeals/feature/bottom
Browse files Browse the repository at this point in the history
[feature/bottom] BottomNavigation 및 4개 메인 Screen 생성
  • Loading branch information
SsongSik authored Jul 31, 2023
2 parents b3622cc + 80fe083 commit feb2f03
Show file tree
Hide file tree
Showing 17 changed files with 352 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name="com.everymeal.presentation.MainActivity"
android:name="com.everymeal.presentation.ui.main.MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.EveryMeal_Android">

Expand Down
6 changes: 6 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ kotlin-serilization = "1.0.0"

lottie = "6.0.0"

compose-navigation = "2.4.2"

[libraries]
agp = { module = "com.android.tools.build:gradle", version.ref = "agp" }
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
Expand Down Expand Up @@ -62,6 +64,10 @@ kotlin-serilization = { module = "com.jakewharton.retrofit:retrofit2-kotlinx-ser
#Lottie
compose-lottie = { module = "com.airbnb.android:lottie-compose", version.ref = "lottie" }

#Compose-Navigation
compose-navigation = { module = "androidx.navigation:navigation-compose", version.ref = "compose-navigation" }


[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Expand Down
3 changes: 3 additions & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ dependencies {

// Lottie
implementation(libs.compose.lottie)

// Navigation
implementation(libs.compose.navigation)
}
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"),
}
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 = {}
)
}
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()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.everymeal.presentation
package com.everymeal.presentation.ui.main

import android.content.Context
import android.content.Intent
Expand All @@ -19,15 +19,14 @@ import dagger.hilt.android.AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setMainScreen()
}

private fun setMainScreen() {
setContent {
EveryMeal_AndroidTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
MainScreen()
}
}
}
Expand All @@ -38,20 +37,4 @@ class MainActivity : ComponentActivity() {
context.startActivity(intent)
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
EveryMeal_AndroidTheme {
Greeting("Android")
}
}
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()
}
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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import com.everymeal.presentation.MainActivity
import com.everymeal.presentation.ui.main.MainActivity
import com.everymeal.presentation.ui.theme.EveryMeal_AndroidTheme
import dagger.hilt.android.AndroidEntryPoint

Expand Down
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()
}
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()
}
Loading

0 comments on commit feb2f03

Please sign in to comment.