Skip to content

Commit

Permalink
[ADD/#8] bottom navigation route add
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Jul 5, 2024
1 parent 6e7ce11 commit 993df86
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 60 deletions.
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
12 changes: 8 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 @@ -16,8 +16,10 @@ 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.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 +44,10 @@ fun MainScreen(
navController = navigator.navController,
startDestination = navigator.startDestination
) {
firstNavGraph()
mockNavGraph()
homeNavGraph()
calendarNavGraph()
searchNavGraph()
myPageNavGraph()
}
}
}
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_false,
contentDescription = R.string.bottom_nav_home,
route = com.terning.feature.home.navigation.Home
),
Calendar(
icon = R.drawable.ic_nav_calendar_false,
contentDescription = R.string.bottom_nav_calendar,
route = com.terning.feature.calendar.navigation.Calendar
),
Search(
icon = R.drawable.ic_nav_search_false,
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_true,
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
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.calendar.CalendarRoute
import kotlinx.serialization.Serializable

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

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

@Serializable
data object Search : MainTabRoute
6 changes: 4 additions & 2 deletions feature/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<string name="server_success">μ„œλ²„ν†΅μ‹  성곡</string>
<string name="server_failure">μ„œλ²„ν†΅μ‹  μ‹€νŒ¨</string>

<string name="first">first</string>
<string name="mock">mock</string>
<string name="bottom_nav_home">ν™ˆ</string>
<string name="bottom_nav_calendar">μΊ˜λ¦°λ”</string>
<string name="bottom_nav_search">검색</string>
<string name="bottom_nav_my_page">λ§ˆμ΄νŽ˜μ΄μ§€</string>

</resources>

0 comments on commit 993df86

Please sign in to comment.