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

[ADD/#8] 바텀 네비게이션 추가 #10

Merged
merged 9 commits into from
Jul 6, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.terning.feature.calendar

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
fun CalendarRoute() {
CalendarScreen()
}

@Composable
fun CalendarScreen() {
Column(modifier = Modifier.fillMaxSize()) {
Text(text = "캘린더 스크린")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.terning.feature.calendar.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.terning.core.navigation.MainTabRoute
import com.terning.feature.calendar.CalendarRoute
import kotlinx.serialization.Serializable


fun NavController.navigateCalendar(navOptions: NavOptions? = null) {
navigate(
route = Calendar,
navOptions = navOptions
)
}

fun NavGraphBuilder.calendarNavGraph() {
composable<Calendar> {
CalendarRoute()
}
}

@Serializable
data object Calendar : MainTabRoute
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.feature.first
package com.terning.feature.home

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -7,13 +7,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
fun FirstRoute() {
FirstScreen()
fun HomeRoute() {
HomeScreen()
}

@Composable
fun FirstScreen() {
fun HomeScreen() {
Column(modifier = Modifier.fillMaxSize()) {
Text(text = "This is FirstScreen")
Text(text = "홈 스크린")
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.terning.feature.mock.navigation
package com.terning.feature.home.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.terning.core.navigation.MainTabRoute
import com.terning.feature.mock.MockRoute
import com.terning.feature.home.HomeRoute
import kotlinx.serialization.Serializable

fun NavController.navigateMock(navOptions: NavOptions? = null) {
fun NavController.navigateHome(navOptions: NavOptions? = null) {
navigate(
route = Mock,
route = Home,
navOptions = navOptions
)
}

fun NavGraphBuilder.mockNavGraph() {
composable<Mock> {
MockRoute()
fun NavGraphBuilder.homeNavGraph() {
composable<Home> {
HomeRoute()
}
}

@Serializable
data object Mock : MainTabRoute
data object Home : MainTabRoute
24 changes: 10 additions & 14 deletions feature/src/main/java/com/terning/feature/main/MainNavigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.terning.feature.first.navigation.First
import com.terning.feature.first.navigation.navigateFirst
import com.terning.feature.mock.navigation.navigateMock
import com.terning.feature.calendar.navigation.navigateCalendar
import com.terning.feature.home.navigation.Home
import com.terning.feature.home.navigation.navigateHome
import com.terning.feature.myPage.navigation.navigateMyPage
import com.terning.feature.search.navigation.navigateSearch

class MainNavigator(
val navController: NavHostController
Expand All @@ -20,7 +22,7 @@ class MainNavigator(
@Composable get() = navController
.currentBackStackEntryAsState().value?.destination

val startDestination = First
val startDestination = Home

val currentTab: MainTab?
@Composable get() = MainTab.find { tab ->
Expand All @@ -37,19 +39,13 @@ class MainNavigator(
}

when (tab) {
MainTab.FIRST -> navController.navigateFirst(navOptions)
MainTab.MOCK -> navController.navigateMock(navOptions)
MainTab.Home -> navController.navigateHome(navOptions)
MainTab.Calendar -> navController.navigateCalendar(navOptions)
MainTab.Search -> navController.navigateSearch(navOptions)
MainTab.MyPage -> navController.navigateMyPage(navOptions)
}
}

fun navigateToFirst() {
navController.navigateFirst()
}

fun navigateToMock() {
navController.navigateMock()
}

private fun navigateUp() {
navController.navigateUp()
}
Expand Down
24 changes: 20 additions & 4 deletions feature/src/main/java/com/terning/feature/main/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalAbsoluteTonalElevation
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.compose.NavHost
import com.terning.feature.first.navigation.firstNavGraph
import com.terning.feature.mock.navigation.mockNavGraph
import com.terning.core.designsystem.theme.TerningMain
import com.terning.feature.calendar.navigation.calendarNavGraph
import com.terning.feature.home.navigation.homeNavGraph
import com.terning.feature.myPage.navigation.myPageNavGraph
import com.terning.feature.search.navigation.searchNavGraph

@Composable
fun MainScreen(
Expand All @@ -42,8 +48,10 @@ fun MainScreen(
navController = navigator.navController,
startDestination = navigator.startDestination
) {
firstNavGraph()
mockNavGraph()
homeNavGraph()
calendarNavGraph()
searchNavGraph()
myPageNavGraph()
}
}
}
Expand Down Expand Up @@ -78,6 +86,14 @@ private fun MainBottomBar(
fontSize = 9.sp
)
},
colors = androidx.compose.material3.NavigationBarItemDefaults
.colors(
selectedIconColor = TerningMain,
selectedTextColor = TerningMain,
indicatorColor = MaterialTheme.colorScheme.surfaceColorAtElevation(
LocalAbsoluteTonalElevation.current
)
)
)
}
}
Expand Down
29 changes: 18 additions & 11 deletions feature/src/main/java/com/terning/feature/main/MainTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@ import androidx.compose.runtime.Composable
import com.terning.core.navigation.MainTabRoute
import com.terning.core.navigation.Route
import com.terning.feature.R
import com.terning.feature.first.navigation.First
import com.terning.feature.mock.navigation.Mock


enum class MainTab(
@DrawableRes val icon: Int,
@StringRes val contentDescription: Int,
val route: MainTabRoute,
) {
FIRST(
icon = R.drawable.ic_home,
contentDescription = R.string.first,
route = First
Home(
icon = R.drawable.ic_nav_home,
contentDescription = R.string.bottom_nav_home,
route = com.terning.feature.home.navigation.Home
Copy link
Member

@leeeyubin leeeyubin Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 import 할 때 import com.terning.feature.home.navigation.Home 으로 해두면
route = Home으로만 작성해줄 수 있어요!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

훨씬 깔끔해졌읍니다.

),
Calendar(
icon = R.drawable.ic_nav_calendar,
contentDescription = R.string.bottom_nav_calendar,
route = com.terning.feature.calendar.navigation.Calendar
),
Search(
icon = R.drawable.ic_nav_search,
contentDescription = R.string.bottom_nav_search,
route = com.terning.feature.search.navigation.Search
),
MOCK(
icon = R.drawable.ic_home,
contentDescription = R.string.mock,
route = Mock
MyPage(
icon = R.drawable.ic_nav_my_page,
contentDescription = R.string.bottom_nav_my_page,
route = com.terning.feature.myPage.navigation.MyPage
);

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.feature.mock
package com.terning.feature.myPage

import androidx.compose.foundation.Image
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

패키징 관련해서도 컨벤션 맞추는 게 좋을 것 같은데 소문자로 가는 거 어때용,,?
보통은 mypage로 작성해주는 것 같아요!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오홍 좋아요!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

바로 변경했읍니다.

import androidx.compose.foundation.layout.Row
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.feature.mock
package com.terning.feature.myPage

import androidx.annotation.StringRes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.feature.mock
package com.terning.feature.myPage

import com.terning.core.state.UiState
import com.terning.domain.entity.response.MockResponseModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.feature.mock
package com.terning.feature.myPage

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
Expand All @@ -19,8 +19,8 @@ import com.terning.core.state.UiState
import com.terning.domain.entity.response.MockResponseModel

@Composable
fun MockRoute(
viewModel: MockViewModel = hiltViewModel()
fun MyPageRoute(
viewModel: MyPageViewModel = hiltViewModel()
) {

val context = LocalContext.current
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.feature.mock
package com.terning.feature.myPage

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand All @@ -16,7 +16,7 @@ import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MockViewModel @Inject constructor(private val repository: MockRepository) : ViewModel() {
class MyPageViewModel @Inject constructor(private val repository: MockRepository) : ViewModel() {

private val _state: MutableStateFlow<MockState> =
MutableStateFlow(MockState())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.terning.feature.first.navigation
package com.terning.feature.myPage.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.terning.core.navigation.MainTabRoute
import com.terning.feature.first.FirstRoute
import com.terning.feature.myPage.MyPageRoute
import kotlinx.serialization.Serializable

fun NavController.navigateFirst(navOptions: NavOptions? = null) {
fun NavController.navigateMyPage(navOptions: NavOptions? = null) {
navigate(
route = First,
route = MyPage,
navOptions = navOptions
)
}

fun NavGraphBuilder.firstNavGraph() {
composable<First> {
FirstRoute()
fun NavGraphBuilder.myPageNavGraph() {
composable<MyPage> {
MyPageRoute()
}
}

@Serializable
data object First : MainTabRoute
data object MyPage : MainTabRoute
19 changes: 19 additions & 0 deletions feature/src/main/java/com/terning/feature/search/SearchRouth.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.terning.feature.search

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier

@Composable
fun SearchRoute() {
SearchScreen()
}

@Composable
fun SearchScreen() {
Column(modifier = Modifier.fillMaxSize()) {
Text(text = "탐색 스크린")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.terning.feature.search.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.terning.core.navigation.MainTabRoute
import com.terning.feature.search.SearchRoute
import kotlinx.serialization.Serializable

fun NavController.navigateSearch(navOptions: NavOptions? = null) {
navigate(
route = Search,
navOptions = navOptions
)
}

fun NavGraphBuilder.searchNavGraph() {
composable<Search> {
SearchRoute()
}
}

@Serializable
data object Search : MainTabRoute
Loading
Loading