Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions app/src/main/java/to/bitkit/ui/utils/Transitions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.animation.AnimatedContentScope
import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand Down Expand Up @@ -35,21 +36,43 @@ object Transitions {
/**
* Adds the [Composable] to the [NavGraphBuilder] with the default screen transitions.
*/
@Suppress("LongParameterList")
@Suppress("LongParameterList", "MagicNumber")
inline fun <reified T : Any> NavGraphBuilder.composableWithDefaultTransitions(
typeMap: Map<KType, NavType<*>> = emptyMap(),
deepLinks: List<NavDeepLink> = emptyList(),
noinline enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?)? = {
Transitions.slideInHorizontally
// New screen slides in from the right
slideInHorizontally(
initialOffsetX = { fullWidth -> fullWidth },
animationSpec = tween(300, easing = FastOutSlowInEasing)
)
},
noinline exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition?)? = {
Transitions.scaleOut
// Current screen slides out to the left (partially visible behind new screen)
slideOutHorizontally(
targetOffsetX = { fullWidth -> -fullWidth / 3 },
animationSpec = tween(300, easing = FastOutSlowInEasing)
) + fadeOut(
animationSpec = tween(300, easing = FastOutSlowInEasing),
targetAlpha = 0.8f
)
},
noinline popEnterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?)? = {
Transitions.scaleIn
// Previous screen slides in from the left (was partially visible)
slideInHorizontally(
initialOffsetX = { fullWidth -> -fullWidth / 3 },
animationSpec = tween(300, easing = FastOutSlowInEasing)
) + fadeIn(
animationSpec = tween(300, easing = FastOutSlowInEasing),
initialAlpha = 0.8f
)
},
noinline popExitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition?)? = {
Transitions.slideOutHorizontally
// Current screen slides out to the right
slideOutHorizontally(
targetOffsetX = { fullWidth -> fullWidth },
animationSpec = tween(300, easing = FastOutSlowInEasing)
)
},
noinline content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit,
) {
Expand Down