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
26 changes: 11 additions & 15 deletions feature/src/main/java/com/terning/feature/main/MainNavigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ 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
val navController: NavHostController,
) {
private val currentDestination: NavDestination?
@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.MY_PAGE -> navController.navigateMyPage(navOptions)
}
}

fun navigateToFirst() {
navController.navigateFirst()
}

fun navigateToMock() {
navController.navigateMock()
}

private fun navigateUp() {
navController.navigateUp()
}
Expand Down
44 changes: 39 additions & 5 deletions feature/src/main/java/com/terning/feature/main/MainScreen.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package com.terning.feature.main

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.interaction.Interaction
import androidx.compose.foundation.interaction.MutableInteractionSource
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.Grey300
import com.terning.core.designsystem.theme.TerningMain
import com.terning.core.designsystem.theme.White
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
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow

@Composable
fun MainScreen(
Expand All @@ -42,8 +54,10 @@ fun MainScreen(
navController = navigator.navController,
startDestination = navigator.startDestination
) {
firstNavGraph()
mockNavGraph()
homeNavGraph()
calendarNavGraph()
searchNavGraph()
myPageNavGraph()
}
}
}
Expand All @@ -59,9 +73,10 @@ private fun MainBottomBar(
AnimatedVisibility(
visible = isVisible,
) {
NavigationBar {
NavigationBar(containerColor = White) {
tabs.forEach { itemType ->
NavigationBarItem(
interactionSource = NoRippleInteractionSource,
selected = currentTab == itemType,
onClick = {
onTabSelected(itemType)
Expand All @@ -78,8 +93,27 @@ private fun MainBottomBar(
fontSize = 9.sp
)
},
colors = androidx.compose.material3.NavigationBarItemDefaults
.colors(
selectedIconColor = TerningMain,
selectedTextColor = TerningMain,
unselectedIconColor = Grey300,
unselectedTextColor = Grey300,
indicatorColor = White
)

)
}
}
}
}


private object NoRippleInteractionSource : MutableInteractionSource {

override val interactions: Flow<Interaction> = emptyFlow()

override suspend fun emit(interaction: Interaction) {}

override fun tryEmit(interaction: Interaction) = true
}
33 changes: 22 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,35 @@ 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

import com.terning.feature.calendar.navigation.Calendar
import com.terning.feature.home.navigation.Home
import com.terning.feature.mypage.navigation.MyPage
import com.terning.feature.search.navigation.Search

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 = Home
),
CALENDAR(
icon = R.drawable.ic_nav_calendar,
contentDescription = R.string.bottom_nav_calendar,
route = Calendar
),
SEARCH(
icon = R.drawable.ic_nav_search,
contentDescription = R.string.bottom_nav_search,
route = Search
),
MOCK(
icon = R.drawable.ic_home,
contentDescription = R.string.mock,
route = Mock
MY_PAGE(
icon = R.drawable.ic_nav_my_page,
contentDescription = R.string.bottom_nav_my_page,
route = 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 Expand Up @@ -53,7 +53,7 @@ fun MockRoute(

@Composable
fun MockScreen(
mockList: List<MockResponseModel>
mockList: List<MockResponseModel>,
) {
LazyColumn(
modifier = Modifier
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
Loading
Loading