Skip to content

Commit dec839d

Browse files
authored
[FIX] 백스택 이동 시 바텀 메뉴 반영 안되는 이슈 수정 (#215)
1 parent 853e8d4 commit dec839d

3 files changed

Lines changed: 10 additions & 13 deletions

File tree

app/src/main/java/com/pomonyang/mohanyang/ui/MohaNyangApp.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ import androidx.compose.material3.SnackbarHostState
1717
import androidx.compose.material3.Text
1818
import androidx.compose.runtime.Composable
1919
import androidx.compose.runtime.getValue
20-
import androidx.compose.runtime.mutableIntStateOf
2120
import androidx.compose.runtime.mutableStateOf
2221
import androidx.compose.runtime.remember
23-
import androidx.compose.runtime.saveable.rememberSaveable
2422
import androidx.compose.runtime.setValue
2523
import androidx.compose.ui.Alignment
2624
import androidx.compose.ui.Modifier
@@ -43,7 +41,7 @@ import com.pomonyang.mohanyang.presentation.designsystem.token.MnRadius
4341
import com.pomonyang.mohanyang.presentation.designsystem.token.MnSpacing
4442
import com.pomonyang.mohanyang.presentation.screen.home.Home
4543
import com.pomonyang.mohanyang.presentation.screen.mypage.MyPage
46-
import com.pomonyang.mohanyang.presentation.screen.statistics.Statistics
44+
import com.pomonyang.mohanyang.presentation.screen.statistics.StatisticsGraph
4745
import com.pomonyang.mohanyang.presentation.theme.MnTheme
4846
import com.pomonyang.mohanyang.presentation.util.ThemePreviews
4947
import com.pomonyang.mohanyang.ui.component.MohaNyangBottomBar
@@ -70,7 +68,6 @@ private fun MohaNyangApp(
7068
) {
7169
var snackbarIconRes by remember { mutableStateOf<Int?>(null) }
7270
val navHostController = mohaNyangAppState.navHostController
73-
var selectedNavigationIndex by rememberSaveable { mutableIntStateOf(0) }
7471

7572
val items = persistentListOf(
7673
BottomNavItem(
@@ -80,7 +77,7 @@ private fun MohaNyangApp(
8077
label = stringResource(R.string.bottom_navigation_home),
8178
),
8279
BottomNavItem(
83-
route = Statistics,
80+
route = StatisticsGraph,
8481
iconRes = PresentationR.drawable.ic_chart_bar,
8582
selectedIconRes = PresentationR.drawable.ic_chart_bar_fill,
8683
label = stringResource(R.string.bottom_navigation_statistics),
@@ -112,8 +109,7 @@ private fun MohaNyangApp(
112109
MohaNyangBottomBar(
113110
navController = navHostController,
114111
items = items,
115-
selectedIndex = selectedNavigationIndex,
116-
onItemSelected = { selectedNavigationIndex = it },
112+
currentBottomRootRoute = mohaNyangAppState.currentBottomRootRoute,
117113
)
118114
}
119115
},

app/src/main/java/com/pomonyang/mohanyang/ui/MohaNyangAppState.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,7 @@ class MohaNyangAppState(
7777
}
7878
} ?: previousDestination.value
7979
}
80+
81+
val currentBottomRootRoute: String?
82+
@Composable get() = currentDestination?.parent?.route
8083
}

app/src/main/java/com/pomonyang/mohanyang/ui/component/MohaNyangBottomBar.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ import kotlinx.collections.immutable.persistentListOf
3131
internal fun MohaNyangBottomBar(
3232
navController: NavHostController,
3333
items: PersistentList<BottomNavItem>,
34-
selectedIndex: Int,
35-
onItemSelected: (index: Int) -> Unit,
34+
currentBottomRootRoute: String? = null,
3635
) {
3736
Row(
3837
verticalAlignment = Alignment.CenterVertically,
@@ -50,7 +49,6 @@ internal fun MohaNyangBottomBar(
5049
.weight(1f)
5150
.padding(vertical = MnSpacing.small)
5251
.noRippleClickable {
53-
onItemSelected(index)
5452
navController.navigate(bottomNavItem.route) {
5553
popUpTo(navController.graph.findStartDestination().id) {
5654
saveState = true
@@ -60,7 +58,8 @@ internal fun MohaNyangBottomBar(
6058
}
6159
},
6260
) {
63-
val iconRes = if (selectedIndex == index) {
61+
val isItemSelected = currentBottomRootRoute == bottomNavItem.route::class.qualifiedName
62+
val iconRes = if (isItemSelected) {
6463
bottomNavItem.selectedIconRes
6564
} else {
6665
bottomNavItem.iconRes
@@ -102,8 +101,7 @@ private fun MohaNyangBottomBarPreview() {
102101
label = "프로필",
103102
),
104103
),
105-
selectedIndex = 0,
106-
onItemSelected = {},
104+
currentBottomRootRoute = Home::class.qualifiedName,
107105
)
108106
}
109107
}

0 commit comments

Comments
 (0)