-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHomeNavHost.kt
More file actions
160 lines (149 loc) · 6.44 KB
/
HomeNavHost.kt
File metadata and controls
160 lines (149 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.threegap.bitnagil.navigation.home
import android.annotation.SuppressLint
import android.app.Activity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.LocalActivity
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.threegap.bitnagil.designsystem.BitnagilTheme
import com.threegap.bitnagil.designsystem.R
import com.threegap.bitnagil.designsystem.component.atom.BitnagilFloatingActionMenu
import com.threegap.bitnagil.designsystem.component.atom.FloatingActionItem
import com.threegap.bitnagil.designsystem.modifier.clickableWithoutRipple
import com.threegap.bitnagil.presentation.screen.home.HomeScreenContainer
import com.threegap.bitnagil.presentation.screen.mypage.MyPageScreenContainer
import com.threegap.bitnagil.presentation.screen.recommendroutine.RecommendRoutineScreenContainer
import com.threegap.bitnagil.presentation.util.toast.GlobalBitnagilToast
import com.threegap.bitnagil.util.setStatusBarContentColor
@Composable
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
fun HomeNavHost(
modifier: Modifier = Modifier,
navigateToSetting: () -> Unit,
navigateToOnBoarding: () -> Unit,
navigateToNotice: () -> Unit,
navigateToQnA: () -> Unit,
navigateToGuide: () -> Unit,
navigateToRegisterRoutine: (String?) -> Unit,
navigateToEmotion: () -> Unit,
navigateToRoutineList: (String) -> Unit,
navigateToReport: () -> Unit,
navigateToReportHistory: () -> Unit,
) {
val navigator = rememberHomeNavigator()
var showFloatingOverlay by remember { mutableStateOf(false) }
DoubleBackButtonPressedHandler()
val activity = LocalActivity.current
val isHomeTab = navigator.isHomeRoute
LaunchedEffect(isHomeTab) {
activity?.setStatusBarContentColor(isLightContent = isHomeTab)
}
val selectedBottomTab = navigator.currentHomeRoute ?: navigator.startDestination
Box(modifier = modifier.fillMaxSize()) {
Scaffold(
modifier = Modifier.fillMaxSize(),
bottomBar = {
HomeBottomNavigationBar(
selectedTab = selectedBottomTab,
onTabSelected = navigator::navigateTo,
)
},
contentWindowInsets = WindowInsets(0.dp, 0.dp, 0.dp, 0.dp),
content = { innerPadding ->
NavHost(
navController = navigator.navController,
startDestination = navigator.startDestination,
modifier = modifier.padding(innerPadding),
) {
composable<HomeRoute.Home> {
HomeScreenContainer(
navigateToGuide = navigateToGuide,
navigateToRegisterRoutine = {
navigateToRegisterRoutine(null)
},
navigateToEmotion = navigateToEmotion,
navigateToRoutineList = { selectedDate ->
navigateToRoutineList(selectedDate)
},
)
}
composable<HomeRoute.RecommendRoutine> {
RecommendRoutineScreenContainer(
navigateToEmotion = navigateToEmotion,
navigateToRegisterRoutine = navigateToRegisterRoutine,
)
}
composable<HomeRoute.MyPage> {
MyPageScreenContainer(
navigateToSetting = navigateToSetting,
navigateToOnBoarding = navigateToOnBoarding,
navigateToNotice = navigateToNotice,
navigateToQnA = navigateToQnA,
navigateToReportHistory = navigateToReportHistory,
)
}
}
},
)
if (navigator.shouldShowFloatingAction()) {
if (showFloatingOverlay) {
Box(
modifier = Modifier
.fillMaxSize()
.background(BitnagilTheme.colors.black.copy(alpha = 0.7f))
.clickableWithoutRipple { showFloatingOverlay = false },
)
}
BitnagilFloatingActionMenu(
actions = listOf(
FloatingActionItem(
icon = R.drawable.ic_complaint,
text = "제보하기",
onClick = { navigateToReport() },
),
FloatingActionItem(
icon = R.drawable.ic_routine_add,
text = "루틴 등록",
onClick = { navigateToRegisterRoutine(null) },
),
),
isExpanded = showFloatingOverlay,
onToggle = { expanded -> showFloatingOverlay = expanded },
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(end = 16.dp, bottom = 80.dp),
)
}
}
}
@Composable
fun DoubleBackButtonPressedHandler() {
val context = LocalContext.current
var backPressedTimeMillis by remember { mutableLongStateOf(0L) }
BackHandler {
if (System.currentTimeMillis() - backPressedTimeMillis < 2000) {
backPressedTimeMillis = 0
(context as? Activity)?.finish()
} else {
backPressedTimeMillis = System.currentTimeMillis()
GlobalBitnagilToast.showWarning("버튼을 한 번 더 누르면 종료됩니다.")
}
}
}