-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHomeNavHost.kt
More file actions
136 lines (127 loc) · 5.46 KB
/
HomeNavHost.kt
File metadata and controls
136 lines (127 loc) · 5.46 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
package com.threegap.bitnagil.navigation.home
import android.annotation.SuppressLint
import android.app.Activity
import androidx.activity.compose.BackHandler
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.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.common.toast.GlobalBitnagilToast
import com.threegap.bitnagil.presentation.home.HomeScreenContainer
import com.threegap.bitnagil.presentation.mypage.MyPageScreenContainer
import com.threegap.bitnagil.presentation.recommendroutine.RecommendRoutineScreenContainer
@Composable
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
fun HomeNavHost(
modifier: Modifier = Modifier,
navigateToSetting: () -> Unit,
navigateToOnBoarding: () -> Unit,
navigateToNotice: () -> Unit,
navigateToQnA: () -> Unit,
navigateToRegisterRoutine: (String?) -> Unit,
navigateToEmotion: () -> Unit,
navigateToRoutineList: (String) -> Unit,
) {
val navigator = rememberHomeNavigator()
var showFloatingOverlay by remember { mutableStateOf(false) }
DoubleBackButtonPressedHandler()
Box(modifier = modifier.fillMaxSize()) {
Scaffold(
modifier = Modifier.fillMaxSize(),
bottomBar = {
HomeBottomNavigationBar(navController = navigator.navController)
},
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.route) {
HomeScreenContainer(
navigateToRegisterRoutine = {
navigateToRegisterRoutine(null)
},
navigateToEmotion = navigateToEmotion,
navigateToRoutineList = { selectedDate ->
navigateToRoutineList(selectedDate)
},
)
}
composable(HomeRoute.RecommendRoutine.route) {
RecommendRoutineScreenContainer(
navigateToEmotion = navigateToEmotion,
navigateToRegisterRoutine = navigateToRegisterRoutine,
)
}
composable(HomeRoute.MyPage.route) {
MyPageScreenContainer(
navigateToSetting = navigateToSetting,
navigateToOnBoarding = navigateToOnBoarding,
navigateToNotice = navigateToNotice,
navigateToQnA = navigateToQnA,
)
}
}
},
)
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_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("버튼을 한 번 더 누르면 종료됩니다.")
}
}
}