Skip to content
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@ package androidx.navigation3.ui

import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.ContentTransform
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleOut
import androidx.compose.animation.unveilIn
import androidx.compose.animation.veilOut
import androidx.navigation3.scene.Scene
import androidx.navigationevent.NavigationEvent.Companion.EDGE_LEFT
import androidx.navigationevent.NavigationEvent.SwipeEdge

private const val DEFAULT_TRANSITION_DURATION_MILLISECOND = 500
private val IosTransitionEasing = CubicBezierEasing(0.2833f, 0.99f, 0.31833f, 0.99f)

@OptIn(ExperimentalAnimationApi::class)
public actual fun <T : Any> defaultTransitionSpec():
AnimatedContentTransitionScope<Scene<T>>.() -> ContentTransform = {
ContentTransform(
Expand All @@ -43,17 +47,22 @@ public actual fun <T : Any> defaultTransitionSpec():
towards = AnimatedContentTransitionScope.SlideDirection.Left,
targetOffset = { it / 4 },
animationSpec = tween(DEFAULT_TRANSITION_DURATION_MILLISECOND, easing = IosTransitionEasing),
) + veilOut(
animationSpec = tween(DEFAULT_TRANSITION_DURATION_MILLISECOND, easing = IosTransitionEasing),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we share animationSpec object between multiple transforms?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. there are different types: FiniteAnimationSpec<Color> and FiniteAnimationSpec<IntOffset>

),
)
}

@OptIn(ExperimentalAnimationApi::class)
public actual fun <T : Any> defaultPopTransitionSpec():
AnimatedContentTransitionScope<Scene<T>>.() -> ContentTransform = {
ContentTransform(
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Right,
initialOffset = { it / 4 },
animationSpec = tween(DEFAULT_TRANSITION_DURATION_MILLISECOND, easing = IosTransitionEasing),
) + unveilIn(
animationSpec = tween(DEFAULT_TRANSITION_DURATION_MILLISECOND, easing = IosTransitionEasing)
),
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Right,
Expand All @@ -62,6 +71,7 @@ public actual fun <T : Any> defaultPopTransitionSpec():
)
}

@OptIn(ExperimentalAnimationApi::class)
public actual fun <T : Any> defaultPredictivePopTransitionSpec():
AnimatedContentTransitionScope<Scene<T>>.(@SwipeEdge Int) -> ContentTransform = { edge ->
val towards = if (edge == EDGE_LEFT) {
Expand All @@ -74,6 +84,8 @@ public actual fun <T : Any> defaultPredictivePopTransitionSpec():
towards = towards,
initialOffset = { it / 4 },
animationSpec = tween(DEFAULT_TRANSITION_DURATION_MILLISECOND, easing = LinearEasing),
) + unveilIn(
animationSpec = tween(DEFAULT_TRANSITION_DURATION_MILLISECOND, easing = LinearEasing),
),
slideOutOfContainer(
towards = towards,
Expand Down