@@ -35,6 +35,7 @@ import androidx.compose.foundation.layout.padding
3535import androidx.compose.foundation.layout.size
3636import androidx.compose.foundation.layout.width
3737import androidx.compose.foundation.lazy.LazyColumn
38+ import androidx.compose.foundation.lazy.items
3839import androidx.compose.foundation.lazy.itemsIndexed
3940import androidx.compose.foundation.selection.selectable
4041import androidx.compose.foundation.shape.RoundedCornerShape
@@ -397,7 +398,9 @@ fun AppNavigation(sharedViewModel: SharedViewModel) {
397398 .fillMaxWidth()
398399 ) {
399400 Image (
400- painter = if (BuildConfig .BUILD_TYPE == " beta" || BuildConfig .BUILD_TYPE == " oss" ) painterResource(id = R .drawable.ic_launcher_beta_foreground) else painterResource(id = R .drawable.ic_launcher_foreground) ,
401+ painter = if (BuildConfig .BUILD_TYPE == " beta" || BuildConfig .BUILD_TYPE == " oss" ) painterResource(
402+ id = R .drawable.ic_launcher_beta_foreground
403+ ) else painterResource(id = R .drawable.ic_launcher_foreground),
401404 contentDescription = stringResource(R .string.app_logo_content_description),
402405 modifier = Modifier .size(64 .dp)
403406 )
@@ -410,56 +413,58 @@ fun AppNavigation(sharedViewModel: SharedViewModel) {
410413 Spacer (modifier = Modifier .height(8 .dp)) // Spacing after the header
411414
412415 // Drawer Items: Dynamically created for each main route.
413- mainRoutes.forEach { route ->
414- // Add a divider before the "Settings" item for visual separation.
415- if (route == Routes .SETTINGS ) {
416- HorizontalDivider (
417- modifier = Modifier
418- .fillMaxWidth()
419- .padding(horizontal = 16 .dp, vertical = 8 .dp)
420- )
421- }
416+ LazyColumn () {
417+ items(mainRoutes, key = {it}) { route ->
418+ // Add a divider before the "Settings" item for visual separation.
419+ if (route == Routes .SETTINGS ) {
420+ HorizontalDivider (
421+ modifier = Modifier
422+ .fillMaxWidth()
423+ .padding(horizontal = 16 .dp, vertical = 8 .dp)
424+ )
425+ }
422426
423- val titleResId = Routes .getTitleResourceId(route)
424- val titleText = if (titleResId != Routes .NO_TITLE_RESOURCE_ID ) {
425- stringResource(id = titleResId)
426- } else {
427- route // Fallback to the raw route string if no title resource ID is defined.
428- }
427+ val titleResId = Routes .getTitleResourceId(route)
428+ val titleText = if (titleResId != Routes .NO_TITLE_RESOURCE_ID ) {
429+ stringResource(id = titleResId)
430+ } else {
431+ route // Fallback to the raw route string if no title resource ID is defined.
432+ }
429433
430- NavigationDrawerItem (
431- icon = {
432- Icon (
433- imageVector = getIconForRoute(route),
434- contentDescription = titleText // Provides accessibility for the icon.
435- )
436- },
437- label = { Text (titleText) },
438- selected = currentRoute == route, // Highlights the item if it's the current route.
439- onClick = {
440- navController.navigate(route) {
441- // Pop up to the start destination of the graph to avoid building up a large back stack.
442- popUpTo(navController.graph.startDestinationId) {
443- saveState = true // Save the state of popped destinations.
434+ NavigationDrawerItem (
435+ icon = {
436+ Icon (
437+ imageVector = getIconForRoute(route),
438+ contentDescription = titleText // Provides accessibility for the icon.
439+ )
440+ },
441+ label = { Text (titleText) },
442+ selected = currentRoute == route, // Highlights the item if it's the current route.
443+ onClick = {
444+ navController.navigate(route) {
445+ // Pop up to the start destination of the graph to avoid building up a large back stack.
446+ popUpTo(navController.graph.startDestinationId) {
447+ saveState = true // Save the state of popped destinations.
448+ }
449+ // Avoid multiple copies of the same destination when reselecting the same item.
450+ launchSingleTop = true
451+ // Restore state when reselecting a previously visited item.
452+ restoreState = true
444453 }
445- // Avoid multiple copies of the same destination when reselecting the same item.
446- launchSingleTop = true
447- // Restore state when reselecting a previously visited item.
448- restoreState = true
449- }
450- scope.launch { drawerState.close() } // Close the drawer after selection.
451- },
452- colors = NavigationDrawerItemDefaults .colors(
453- // Custom colors for selected and unselected drawer items.
454- selectedIconColor = Blue ,
455- selectedTextColor = Blue ,
456- selectedContainerColor = Color .Transparent , // No background for the selected item itself.
457-
458- unselectedIconColor = White ,
459- unselectedTextColor = White ,
460- unselectedContainerColor = Color .Transparent
454+ scope.launch { drawerState.close() } // Close the drawer after selection.
455+ },
456+ colors = NavigationDrawerItemDefaults .colors(
457+ // Custom colors for selected and unselected drawer items.
458+ selectedIconColor = Blue ,
459+ selectedTextColor = Blue ,
460+ selectedContainerColor = Color .Transparent , // No background for the selected item itself.
461+
462+ unselectedIconColor = White ,
463+ unselectedTextColor = White ,
464+ unselectedContainerColor = Color .Transparent
465+ )
461466 )
462- )
467+ }
463468 }
464469 }
465470 }
0 commit comments