diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScaffold.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScaffold.kt index cd13f19d0..6b561b0b5 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScaffold.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScaffold.kt @@ -28,20 +28,21 @@ import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteDefaul import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffold import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffoldDefaults import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteType -import androidx.compose.runtime.Composable -import androidx.compose.runtime.derivedStateOf -import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember +import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.NavHostController import com.infomaniak.swisstransfer.ui.navigation.MainNavigation import com.infomaniak.swisstransfer.ui.navigation.NavigationItem +import com.infomaniak.swisstransfer.ui.theme.LocalCustomTypography import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme +import com.infomaniak.swisstransfer.ui.theme.Typography import com.infomaniak.swisstransfer.ui.utils.PreviewMobile import com.infomaniak.swisstransfer.ui.utils.PreviewTablet +val LocalNavType = staticCompositionLocalOf { NavigationSuiteType.None } + @Composable fun MainScaffold( navController: NavHostController, @@ -50,23 +51,11 @@ fun MainScaffold( content: @Composable () -> Unit = {}, ) { - val showNavigation by remember(currentDestination) { - derivedStateOf { - NavigationItem.entries.any { it.destination == currentDestination } - } - } + val navType by rememberNavType(currentDestination, windowAdaptiveInfo) - val navType by remember(showNavigation, windowAdaptiveInfo) { - derivedStateOf { - if (showNavigation) { - NavigationSuiteScaffoldDefaults.calculateFromAdaptiveInfo(windowAdaptiveInfo) - } else { - NavigationSuiteType.None - } - } + CompositionLocalProvider(LocalNavType provides navType) { + MainScaffold(navType, currentDestination, navController::navigateToSelectedItem, content) } - - MainScaffold(navType, currentDestination, navController::navigateToSelectedItem, content) } @Composable @@ -123,6 +112,29 @@ private fun NavigationLabel(isNavigationBar: Boolean, navigationItem: Navigation } } +@Composable +private fun rememberNavType( + currentDestination: MainNavigation, + windowAdaptiveInfo: WindowAdaptiveInfo, +): State { + + val showNavigation by remember(currentDestination) { + derivedStateOf { + NavigationItem.entries.any { it.destination == currentDestination } + } + } + + return remember(showNavigation, windowAdaptiveInfo) { + derivedStateOf { + if (showNavigation) { + NavigationSuiteScaffoldDefaults.calculateFromAdaptiveInfo(windowAdaptiveInfo) + } else { + NavigationSuiteType.None + } + } + } +} + private fun NavHostController.navigateToSelectedItem(destination: MainNavigation) { navigate(destination) { // Pop up to the start destination of the graph to avoid building up a large stack of destinations diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt index 7cc8a4fcd..937ea0cca 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt @@ -20,8 +20,11 @@ package com.infomaniak.swisstransfer.ui.screen.main.sent import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import com.infomaniak.swisstransfer.ui.screen.main.LocalNavType @Composable fun SentScreen(navigateToDetails: (transferId: Int) -> Unit) { - Text("Sent screen") + val navType = LocalNavType.current + + Text("Sent screen $navType") }