From 0bb5f0a19cac8e66ce9485f96825dabfdb2f0c1e Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Wed, 14 Aug 2024 16:18:30 +0200 Subject: [PATCH] feat: Disable navigation transitions --- .../ui/navigation/NavigationDestination.kt | 2 ++ .../swisstransfer/ui/screen/main/MainNavHost.kt | 11 ++++++++++- .../swisstransfer/ui/screen/main/MainScaffold.kt | 1 + .../swisstransfer/ui/screen/main/MainScreen.kt | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt index 521fbfac2..eade0d0b7 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt @@ -28,6 +28,8 @@ import kotlin.reflect.KClass */ @Serializable sealed class MainNavigation : NavigationDestination() { + var enableTransition = true + @Serializable data object SentDestination : MainNavigation() @Serializable diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainNavHost.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainNavHost.kt index 61604bfa7..897ceeadb 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainNavHost.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainNavHost.kt @@ -18,6 +18,10 @@ package com.infomaniak.swisstransfer.ui.screen.main +import androidx.compose.animation.EnterTransition +import androidx.compose.animation.ExitTransition +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.material3.adaptive.WindowAdaptiveInfo import androidx.compose.runtime.Composable @@ -37,8 +41,13 @@ import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.TransferDetai fun MainNavHost( navController: NavHostController, windowAdaptiveInfo: WindowAdaptiveInfo, + currentDestination: MainNavigation, ) { - NavHost(navController, MainNavigation.startDestination, modifier = Modifier.safeDrawingPadding()) { + NavHost( + navController, MainNavigation.startDestination, modifier = Modifier.safeDrawingPadding(), + enterTransition = { if (currentDestination.enableTransition) fadeIn() else EnterTransition.None }, + exitTransition = { if (currentDestination.enableTransition) fadeOut() else ExitTransition.None }, + ) { composable { SentScreen( navigateToDetails = { navController.navigate(TransferDetailsDestination(it)) }, 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 f070580bb..fbaf6c487 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 @@ -97,6 +97,7 @@ private fun rememberNavType( } private fun NavHostController.navigateToSelectedItem(destination: MainNavigation) { + destination.enableTransition = false navigate(destination) { // Pop up to the start destination of the graph to avoid building up a large stack of destinations // on the back stack as users select items diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt index 39e89a9b1..d4cfc4ec3 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/MainScreen.kt @@ -45,7 +45,7 @@ fun MainScreen() { } MainScaffold(navController, currentDestination, windowAdaptiveInfo) { - MainNavHost(navController, windowAdaptiveInfo) + MainNavHost(navController, windowAdaptiveInfo, currentDestination) } }