Skip to content

Commit

Permalink
Merge pull request #18 from Infomaniak/feat-navigation-transition
Browse files Browse the repository at this point in the history
feat: Disable navigation transitions
  • Loading branch information
LunarX authored Aug 15, 2024
2 parents e0bcf6b + 397885b commit 322851f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import kotlin.reflect.KClass
*/
@Serializable
sealed class MainNavigation : NavigationDestination() {
var enableTransition = true

@Serializable
data object SentDestination : MainNavigation()
@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,8 +41,15 @@ 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 = navController,
startDestination = MainNavigation.startDestination,
modifier = Modifier.safeDrawingPadding(),
enterTransition = { if (currentDestination.enableTransition) fadeIn() else EnterTransition.None },
exitTransition = { if (currentDestination.enableTransition) fadeOut() else ExitTransition.None },
) {
composable<SentDestination> {
SentScreen(
navigateToDetails = { navController.navigate(TransferDetailsDestination(it)) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fun MainScreen() {
}

MainScaffold(navController, currentDestination, windowAdaptiveInfo) {
MainNavHost(navController, windowAdaptiveInfo)
MainNavHost(navController, windowAdaptiveInfo, currentDestination)
}
}

Expand Down

0 comments on commit 322851f

Please sign in to comment.