@@ -23,7 +23,6 @@ import androidx.compose.material3.DrawerValue
2323import androidx.compose.material3.HorizontalDivider
2424import androidx.compose.material3.Icon
2525import androidx.compose.material3.Text
26- import androidx.compose.material3.rememberDrawerState
2726import androidx.compose.runtime.Composable
2827import androidx.compose.runtime.remember
2928import androidx.compose.runtime.rememberCoroutineScope
@@ -38,14 +37,9 @@ import androidx.compose.ui.tooling.preview.Preview
3837import androidx.compose.ui.unit.dp
3938import androidx.compose.ui.unit.sp
4039import androidx.compose.ui.zIndex
41- import androidx.navigation.NavController
42- import androidx.navigation.NavDestination.Companion.hasRoute
43- import androidx.navigation.compose.rememberNavController
4440import kotlinx.coroutines.launch
4541import to.bitkit.R
46- import to.bitkit.ui.Routes
47- import to.bitkit.ui.navigateIfNotCurrent
48- import to.bitkit.ui.navigateToHome
42+ import to.bitkit.ui.nav.Navigator
4943import to.bitkit.ui.shared.modifiers.clickableAlpha
5044import to.bitkit.ui.shared.util.blockPointerInputPassthrough
5145import to.bitkit.ui.theme.AppThemeSurface
@@ -61,7 +55,7 @@ private val drawerWidth = 200.dp
6155@Composable
6256fun DrawerMenu (
6357 drawerState : DrawerState ,
64- rootNavController : NavController ,
58+ navigator : Navigator ,
6559 hasSeenWidgetsIntro : Boolean ,
6660 hasSeenShopIntro : Boolean ,
6761 modifier : Modifier = Modifier ,
@@ -95,36 +89,57 @@ fun DrawerMenu(
9589 .blockPointerInputPassthrough()
9690 )
9791 ) {
98- Menu (
99- rootNavController = rootNavController,
100- drawerState = drawerState,
101- onClickAddWidget = {
92+ MenuContent (
93+ onWalletClick = {
94+ if (! navigator.isAtHome()) navigator.navigateToHome()
95+ scope.launch { drawerState.close() }
96+ },
97+ onActivityClick = {
98+ navigator.navigateToAllActivity()
99+ scope.launch { drawerState.close() }
100+ },
101+ onContactsClick = null , // TODO IMPLEMENT CONTACTS
102+ onProfileClick = null , // TODO IMPLEMENT PROFILE
103+ onWidgetsClick = {
102104 if (! hasSeenWidgetsIntro) {
103- rootNavController.navigateIfNotCurrent( Routes . WidgetsIntro )
105+ navigator.navigateToWidgetsIntro( )
104106 } else {
105- rootNavController.navigateIfNotCurrent( Routes . AddWidget )
107+ navigator.navigateToAddWidget( )
106108 }
109+ scope.launch { drawerState.close() }
107110 },
108- onClickShop = {
111+ onShopClick = {
109112 if (! hasSeenShopIntro) {
110- rootNavController.navigateIfNotCurrent( Routes . ShopIntro )
113+ navigator.navigateToShopIntro( )
111114 } else {
112- rootNavController.navigateIfNotCurrent( Routes . ShopDiscover )
115+ navigator.navigateToShopDiscover( )
113116 }
117+ scope.launch { drawerState.close() }
118+ },
119+ onSettingsClick = {
120+ navigator.navigateToSettings()
121+ scope.launch { drawerState.close() }
122+ },
123+ onAppStatusClick = {
124+ navigator.navigateToAppStatus()
125+ scope.launch { drawerState.close() }
114126 },
115127 )
116128 }
117129}
118130
131+ @Suppress(" LongParameterList" )
119132@Composable
120- private fun Menu (
121- rootNavController : NavController ,
122- drawerState : DrawerState ,
123- onClickAddWidget : () -> Unit ,
124- onClickShop : () -> Unit ,
133+ private fun MenuContent (
134+ onWalletClick : () -> Unit ,
135+ onActivityClick : () -> Unit ,
136+ onContactsClick : (() -> Unit )? ,
137+ onProfileClick : (() -> Unit )? ,
138+ onWidgetsClick : () -> Unit ,
139+ onShopClick : () -> Unit ,
140+ onSettingsClick : () -> Unit ,
141+ onAppStatusClick : () -> Unit ,
125142) {
126- val scope = rememberCoroutineScope()
127-
128143 Column (
129144 modifier = Modifier
130145 .width(drawerWidth)
@@ -137,65 +152,49 @@ private fun Menu(
137152 DrawerItem (
138153 label = stringResource(R .string.wallet__drawer__wallet),
139154 iconRes = R .drawable.ic_coins,
140- onClick = {
141- val isInHome = rootNavController.currentBackStackEntry?.destination?.hasRoute<Routes .Home >() ? : false
142- if (! isInHome) rootNavController.navigateToHome()
143- scope.launch { drawerState.close() }
144- },
155+ onClick = onWalletClick,
145156 modifier = Modifier .testTag(" DrawerWallet" )
146157 )
147158
148159 DrawerItem (
149160 label = stringResource(R .string.wallet__drawer__activity),
150161 iconRes = R .drawable.ic_heartbeat,
151- onClick = {
152- rootNavController.navigateIfNotCurrent(Routes .AllActivity )
153- scope.launch { drawerState.close() }
154- },
162+ onClick = onActivityClick,
155163 modifier = Modifier .testTag(" DrawerActivity" )
156164 )
157165
158166 DrawerItem (
159167 label = stringResource(R .string.wallet__drawer__contacts),
160168 iconRes = R .drawable.ic_users,
161- onClick = null , // TODO IMPLEMENT CONTACTS
169+ onClick = onContactsClick,
162170 modifier = Modifier .testTag(" DrawerContacts" )
163171 )
164172
165173 DrawerItem (
166174 label = stringResource(R .string.wallet__drawer__profile),
167175 iconRes = R .drawable.ic_user_square,
168- onClick = null , // TODO IMPLEMENT PROFILE
176+ onClick = onProfileClick,
169177 modifier = Modifier .testTag(" DrawerProfile" )
170178 )
171179
172180 DrawerItem (
173181 label = stringResource(R .string.wallet__drawer__widgets),
174182 iconRes = R .drawable.ic_stack,
175- onClick = {
176- onClickAddWidget()
177- scope.launch { drawerState.close() }
178- },
183+ onClick = onWidgetsClick,
179184 modifier = Modifier .testTag(" DrawerWidgets" )
180185 )
181186
182187 DrawerItem (
183188 label = stringResource(R .string.wallet__drawer__shop),
184189 iconRes = R .drawable.ic_store_front,
185- onClick = {
186- onClickShop()
187- scope.launch { drawerState.close() }
188- },
190+ onClick = onShopClick,
189191 modifier = Modifier .testTag(" DrawerShop" )
190192 )
191193
192194 DrawerItem (
193195 label = stringResource(R .string.wallet__drawer__settings),
194196 iconRes = R .drawable.ic_settings,
195- onClick = {
196- rootNavController.navigateIfNotCurrent(Routes .Settings )
197- scope.launch { drawerState.close() }
198- },
197+ onClick = onSettingsClick,
199198 modifier = Modifier .testTag(" DrawerSettings" )
200199 )
201200
@@ -205,10 +204,7 @@ private fun Menu(
205204 contentAlignment = Alignment .Center ,
206205 modifier = Modifier
207206 .fillMaxWidth()
208- .clickableAlpha {
209- rootNavController.navigateIfNotCurrent(Routes .AppStatus )
210- scope.launch { drawerState.close() }
211- }
207+ .clickableAlpha(onClick = onAppStatusClick)
212208 ) {
213209 AppStatus (
214210 showText = true ,
@@ -297,14 +293,16 @@ private fun DrawerItem(
297293@Composable
298294private fun Preview () {
299295 AppThemeSurface {
300- val navController = rememberNavController()
301296 Box {
302- DrawerMenu (
303- rootNavController = navController,
304- drawerState = rememberDrawerState(initialValue = DrawerValue .Open ),
305- hasSeenWidgetsIntro = false ,
306- hasSeenShopIntro = false ,
307- modifier = Modifier .align(Alignment .TopEnd ),
297+ MenuContent (
298+ onWalletClick = {},
299+ onActivityClick = {},
300+ onContactsClick = null ,
301+ onProfileClick = null ,
302+ onWidgetsClick = {},
303+ onShopClick = {},
304+ onSettingsClick = {},
305+ onAppStatusClick = {},
308306 )
309307 }
310308 }
0 commit comments