Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.currentBackStackEntryAsState
import com.threegap.bitnagil.designsystem.BitnagilTheme
import com.threegap.bitnagil.designsystem.component.atom.BitnagilIcon

@Composable
fun HomeBottomNavigationBar(
navController: NavController,
selectedTab: HomeRoute,
onTabSelected: (HomeRoute) -> Unit,
modifier: Modifier = Modifier,
) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route

Column {
Column(modifier = modifier) {
HorizontalDivider(
modifier = Modifier.fillMaxWidth(),
thickness = 1.dp,
Expand All @@ -47,19 +44,13 @@ fun HomeBottomNavigationBar(
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalAlignment = Alignment.CenterVertically,
) {
HomeRoute.entries.map { homeRoute ->
homeTabList.forEach { homeTab ->
HomeBottomNavigationItem(
modifier = Modifier.weight(1f),
icon = homeRoute.icon,
title = homeRoute.title,
onClick = {
if (currentRoute != homeRoute.route) {
navController.navigate(homeRoute.route) {
popUpTo(0) { inclusive = true }
}
}
},
selected = currentRoute == homeRoute.route,
icon = homeTab.icon,
title = homeTab.title,
selected = selectedTab == homeTab.route,
onClick = { onTabSelected(homeTab.route) },
)
}
}
Expand All @@ -71,8 +62,8 @@ private fun HomeBottomNavigationItem(
modifier: Modifier = Modifier,
icon: Int,
title: String,
onClick: () -> Unit,
selected: Boolean,
onClick: () -> Unit,
) {
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
Expand Down Expand Up @@ -111,9 +102,8 @@ private fun HomeBottomNavigationItem(
@Composable
@Preview
private fun HomeBottomNavigationBarPreview() {
val navigator = rememberHomeNavigator()

HomeBottomNavigationBar(
navController = navigator.navController,
selectedTab = HomeRoute.Home,
onTabSelected = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ fun HomeNavHost(
activity?.setStatusBarContentColor(isLightContent = isHomeTab)
}

val selectedBottomTab = navigator.currentHomeRoute ?: navigator.startDestination

Box(modifier = modifier.fillMaxSize()) {
Scaffold(
modifier = Modifier.fillMaxSize(),
bottomBar = {
HomeBottomNavigationBar(navController = navigator.navController)
HomeBottomNavigationBar(
selectedTab = selectedBottomTab,
onTabSelected = navigator::navigateTo,
)
},
contentWindowInsets = WindowInsets(0.dp, 0.dp, 0.dp, 0.dp),
content = { innerPadding ->
Expand All @@ -73,7 +78,7 @@ fun HomeNavHost(
startDestination = navigator.startDestination,
modifier = modifier.padding(innerPadding),
) {
composable(HomeRoute.Home.route) {
composable<HomeRoute.Home> {
HomeScreenContainer(
navigateToGuide = navigateToGuide,
navigateToRegisterRoutine = {
Expand All @@ -86,14 +91,14 @@ fun HomeNavHost(
)
}

composable(HomeRoute.RecommendRoutine.route) {
composable<HomeRoute.RecommendRoutine> {
RecommendRoutineScreenContainer(
navigateToEmotion = navigateToEmotion,
navigateToRegisterRoutine = navigateToRegisterRoutine,
)
}

composable(HomeRoute.MyPage.route) {
composable<HomeRoute.MyPage> {
MyPageScreenContainer(
navigateToSetting = navigateToSetting,
navigateToOnBoarding = navigateToOnBoarding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,38 @@ package com.threegap.bitnagil.navigation.home

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.navigation.NavDestination.Companion.hasRoute
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController

class HomeNavigator(
val navController: NavHostController,
) {
val startDestination = HomeRoute.Home.route
val startDestination: HomeRoute = HomeRoute.Home

val currentRoute: String?
@Composable get() = navController.currentBackStackEntryAsState().value?.destination?.route
val currentHomeRoute: HomeRoute?
@Composable get() {
val destination = navController.currentBackStackEntryAsState().value?.destination
return when {
destination?.hasRoute(HomeRoute.Home::class) == true -> HomeRoute.Home
destination?.hasRoute(HomeRoute.RecommendRoutine::class) == true -> HomeRoute.RecommendRoutine
destination?.hasRoute(HomeRoute.MyPage::class) == true -> HomeRoute.MyPage
else -> null
}
}

val isHomeRoute: Boolean
@Composable get() = currentRoute == HomeRoute.Home.route
@Composable get() = currentHomeRoute == HomeRoute.Home

@Composable
fun shouldShowFloatingAction(): Boolean =
currentRoute in setOf(HomeRoute.Home.route, HomeRoute.RecommendRoutine.route)
fun shouldShowFloatingAction(): Boolean = currentHomeRoute?.showFloatingButton == true

fun navigateTo(route: HomeRoute) {
navController.navigate(route) {
popUpTo(0) { inclusive = true }
}
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
package com.threegap.bitnagil.navigation.home

import com.threegap.bitnagil.R
import kotlinx.serialization.Serializable

enum class HomeRoute(
val route: String,
val title: String,
val icon: Int,
) {
Home(
route = "home/home",
title = "홈",
icon = R.drawable.ic_home,
),
@Serializable
sealed interface HomeRoute {
val showFloatingButton: Boolean

RecommendRoutine(
route = "home/recommend_routine",
title = "추천 루틴",
icon = R.drawable.ic_routine_recommend,
),
@Serializable
data object Home : HomeRoute {
override val showFloatingButton: Boolean = true
}

MyPage(
route = "home/my_page",
title = "마이페이지",
icon = R.drawable.ic_profile,
),
;
@Serializable
data object RecommendRoutine : HomeRoute {
override val showFloatingButton: Boolean = true
}

@Serializable
data object MyPage : HomeRoute {
override val showFloatingButton: Boolean = false
}
}

data class HomeTab(
val route: HomeRoute,
val title: String,
val icon: Int,
)

val homeTabList = listOf(
HomeTab(HomeRoute.Home, "홈", R.drawable.ic_home),
HomeTab(HomeRoute.RecommendRoutine, "추천 루틴", R.drawable.ic_routine_recommend),
HomeTab(HomeRoute.MyPage, "마이페이지", R.drawable.ic_profile),
)
Loading