|
1 | 1 | package com.meet.dev.analyzer.presentation.navigation |
2 | 2 |
|
3 | | -import androidx.compose.animation.AnimatedVisibility |
4 | | -import androidx.compose.animation.slideInHorizontally |
5 | | -import androidx.compose.animation.slideOutHorizontally |
6 | | -import androidx.compose.foundation.background |
7 | | -import androidx.compose.material3.MaterialTheme |
8 | | -import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo |
9 | | -import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffoldDefaults |
10 | 3 | import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffoldLayout |
| 4 | +import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffoldValue |
11 | 5 | import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteType |
| 6 | +import androidx.compose.material3.adaptive.navigationsuite.rememberNavigationSuiteScaffoldState |
12 | 7 | import androidx.compose.runtime.Composable |
| 8 | +import androidx.compose.runtime.LaunchedEffect |
13 | 9 | import androidx.compose.runtime.derivedStateOf |
14 | 10 | import androidx.compose.runtime.getValue |
15 | 11 | import androidx.compose.runtime.remember |
16 | | -import androidx.compose.ui.Modifier |
17 | 12 | import androidx.navigation.compose.NavHost |
18 | 13 | import androidx.navigation.compose.composable |
19 | 14 | import androidx.navigation.compose.currentBackStackEntryAsState |
@@ -43,39 +38,32 @@ fun AppNavigation( |
43 | 38 | } |
44 | 39 | } |
45 | 40 | } |
46 | | - |
47 | | - val currentWindowAdaptiveInfo = currentWindowAdaptiveInfo() |
48 | | - val layoutType by remember(currentNavigationItem, currentWindowAdaptiveInfo) { |
49 | | - derivedStateOf { |
50 | | - if (currentNavigationItem != null) { |
51 | | - NavigationSuiteScaffoldDefaults.calculateFromAdaptiveInfo(currentWindowAdaptiveInfo) |
52 | | - } else { |
53 | | - NavigationSuiteType.None |
54 | | - } |
| 41 | + val navigationSuiteState = rememberNavigationSuiteScaffoldState( |
| 42 | + initialValue = NavigationSuiteScaffoldValue.Hidden |
| 43 | + ) |
| 44 | + LaunchedEffect(currentNavigationItem) { |
| 45 | + if (currentNavigationItem != null) { |
| 46 | + navigationSuiteState.show() |
| 47 | + } else { |
| 48 | + navigationSuiteState.hide() |
55 | 49 | } |
56 | 50 | } |
57 | 51 | NavigationSuiteScaffoldLayout( |
| 52 | + state = navigationSuiteState, |
58 | 53 | navigationSuite = { |
59 | | - AnimatedVisibility( |
60 | | - visible = currentNavigationItem != null, |
61 | | - modifier = Modifier.background(MaterialTheme.colorScheme.surface), |
62 | | - enter = slideInHorizontally { -it }, |
63 | | - exit = slideOutHorizontally { it }, |
64 | | - ) { |
65 | | - NavigationRailLayout( |
66 | | - currentNavigationItem = currentNavigationItem, |
67 | | - onNavigate = { |
68 | | - navController.navigate(it.appRoute) { |
69 | | - launchSingleTop = true |
70 | | - restoreState = true |
71 | | - } |
72 | | - }, |
73 | | - isDarkTheme = isDarkMode, |
74 | | - onThemeChange = onThemeChange, |
75 | | - ) |
76 | | - } |
| 54 | + NavigationRailLayout( |
| 55 | + currentNavigationItem = currentNavigationItem, |
| 56 | + onNavigate = { |
| 57 | + navController.navigate(it.appRoute) { |
| 58 | + launchSingleTop = true |
| 59 | + restoreState = true |
| 60 | + } |
| 61 | + }, |
| 62 | + isDarkTheme = isDarkMode, |
| 63 | + onThemeChange = onThemeChange, |
| 64 | + ) |
77 | 65 | }, |
78 | | - layoutType = layoutType |
| 66 | + layoutType = NavigationSuiteType.NavigationRail |
79 | 67 | ) { |
80 | 68 | NavHost( |
81 | 69 | navController = navController, |
@@ -137,7 +125,6 @@ fun AppNavigation( |
137 | 125 | parentEntry = parentEntry |
138 | 126 | ) |
139 | 127 | } |
140 | | - |
141 | 128 | } |
142 | 129 | } |
143 | 130 | } |
|
0 commit comments