Skip to content

Commit

Permalink
Prevent crash when going back to home screen and then tapping home ic…
Browse files Browse the repository at this point in the history
…on fast
  • Loading branch information
AleksandarIlic committed Jan 7, 2025
1 parent 0444d03 commit 10706d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.primal.android.navigation

import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.slideInHorizontally
Expand All @@ -13,3 +14,5 @@ val primalSlideOutHorizontallyToEnd = slideOutHorizontally(animationSpec = tween
val primalScaleIn = scaleIn(animationSpec = tween(), initialScale = 0.9f)

val primalScaleOut = scaleOut(animationSpec = tween(), targetScale = 0.9f)

val mainScreenOut = fadeOut(animationSpec = tween(durationMillis = 250))
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.background
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NamedNavArgument
Expand Down Expand Up @@ -125,6 +127,7 @@ import net.primal.android.profile.qr.ProfileQrCodeViewModel
import net.primal.android.profile.qr.ui.ProfileQrCodeViewerScreen
import net.primal.android.stats.reactions.ReactionsViewModel
import net.primal.android.stats.reactions.ui.ReactionsScreen
import net.primal.android.theme.AppTheme
import net.primal.android.theme.PrimalTheme
import net.primal.android.theme.domain.PrimalTheme
import net.primal.android.thread.articles.details.ArticleDetailsScreen
Expand Down Expand Up @@ -427,6 +430,7 @@ fun SharedTransitionScope.PrimalAppNavigation() {
}

NavHost(
modifier = Modifier.background(AppTheme.colorScheme.background),
navController = navController,
startDestination = "splash",
) {
Expand Down Expand Up @@ -832,7 +836,7 @@ private fun NavGraphBuilder.home(
enterTransition = { null },
exitTransition = {
when {
targetState.destination.route.isMainScreenRoute() -> null
targetState.destination.route.isMainScreenRoute() -> mainScreenOut
else -> primalScaleOut
}
},
Expand All @@ -844,7 +848,7 @@ private fun NavGraphBuilder.home(
},
popExitTransition = {
when {
targetState.destination.route.isMainScreenRoute() -> null
targetState.destination.route.isMainScreenRoute() -> mainScreenOut
else -> primalScaleOut
}
},
Expand Down Expand Up @@ -874,7 +878,7 @@ private fun NavGraphBuilder.reads(
enterTransition = { null },
exitTransition = {
when {
targetState.destination.route.isMainScreenRoute() -> null
targetState.destination.route.isMainScreenRoute() -> mainScreenOut
else -> primalScaleOut
}
},
Expand All @@ -886,7 +890,7 @@ private fun NavGraphBuilder.reads(
},
popExitTransition = {
when {
targetState.destination.route.isMainScreenRoute() -> null
targetState.destination.route.isMainScreenRoute() -> mainScreenOut
else -> primalScaleOut
}
},
Expand Down Expand Up @@ -936,7 +940,7 @@ private fun NavGraphBuilder.explore(
enterTransition = { null },
exitTransition = {
when {
targetState.destination.route.isMainScreenRoute() -> null
targetState.destination.route.isMainScreenRoute() -> mainScreenOut
else -> primalScaleOut
}
},
Expand All @@ -948,7 +952,7 @@ private fun NavGraphBuilder.explore(
},
popExitTransition = {
when {
targetState.destination.route.isMainScreenRoute() -> null
targetState.destination.route.isMainScreenRoute() -> mainScreenOut
else -> primalScaleOut
}
},
Expand Down Expand Up @@ -1464,7 +1468,7 @@ private fun NavGraphBuilder.notifications(
enterTransition = { null },
exitTransition = {
when {
targetState.destination.route.isMainScreenRoute() -> null
targetState.destination.route.isMainScreenRoute() -> mainScreenOut
else -> primalScaleOut
}
},
Expand All @@ -1476,7 +1480,7 @@ private fun NavGraphBuilder.notifications(
},
popExitTransition = {
when {
targetState.destination.route.isMainScreenRoute() -> null
targetState.destination.route.isMainScreenRoute() -> mainScreenOut
else -> primalScaleOut
}
},
Expand Down Expand Up @@ -1609,7 +1613,7 @@ private fun NavGraphBuilder.mediaItem(
sharedTransitionScope = sharedTransitionScope,
animatedVisibilityScope = this@composable,

)
)
}
}

Expand Down

0 comments on commit 10706d7

Please sign in to comment.