Skip to content

Commit

Permalink
feat(adaptive): use navigation rail in height compact mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Jan 12, 2024
1 parent a6ad4ff commit 41d7b45
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ package org.gdglille.devfest.android.theme

import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.material3.adaptive.navigation.suite.ExperimentalMaterial3AdaptiveNavigationSuiteApi
import androidx.compose.material3.adaptive.navigation.suite.NavigationSuiteScaffold
import androidx.compose.material3.adaptive.navigation.suite.NavigationSuiteScaffoldDefaults
import androidx.compose.material3.adaptive.navigation.suite.NavigationSuiteType
import androidx.compose.material3.windowsizeclass.WindowHeightSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
Expand Down Expand Up @@ -47,7 +52,7 @@ import org.koin.androidx.compose.koinViewModel
@Suppress("LongMethod")
@OptIn(
ExperimentalMaterial3AdaptiveNavigationSuiteApi::class, ExperimentalCoroutinesApi::class,
FlowPreview::class
FlowPreview::class, ExperimentalMaterial3AdaptiveApi::class
)
@Composable
fun MainNavigation(
Expand Down Expand Up @@ -86,7 +91,15 @@ fun MainNavigation(
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
val route = currentDestination?.route ?: Screen.ScheduleList.route
val adaptiveInfo = currentWindowAdaptiveInfo()
val layoutType =
if (adaptiveInfo.windowSizeClass.heightSizeClass == WindowHeightSizeClass.Compact && adaptiveInfo.windowPosture.isTabletop.not()) {
NavigationSuiteType.NavigationRail
} else {
NavigationSuiteScaffoldDefaults.calculateFromAdaptiveInfo(adaptiveInfo)
}
NavigationSuiteScaffold(
layoutType = layoutType,
modifier = modifier,
navigationSuiteItems = {
when (uiState.value) {
Expand Down

0 comments on commit 41d7b45

Please sign in to comment.