fix: 路由动画卡顿

This commit is contained in:
lisonge 2023-11-18 15:20:24 +08:00
parent 4d020c9ed7
commit f182706e0e

View File

@ -4,26 +4,37 @@ import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.navigation.NavBackStackEntry
import com.blankj.utilcode.util.ScreenUtils
import com.ramcosta.composedestinations.spec.DestinationStyle
object ProfileTransitions : DestinationStyle.Animated {
private const val durationMillis = 400
override fun AnimatedContentTransitionScope<NavBackStackEntry>.enterTransition(): EnterTransition? {
return slideInHorizontally(tween()) { it }
return slideInHorizontally(
initialOffsetX = { ScreenUtils.getScreenWidth() }, animationSpec = tween(durationMillis)
)
}
override fun AnimatedContentTransitionScope<NavBackStackEntry>.exitTransition(): ExitTransition? {
return slideOutHorizontally(tween()) { -it } + fadeOut(tween())
return slideOutHorizontally(
targetOffsetX = { -ScreenUtils.getScreenWidth() / 2 },
animationSpec = tween(durationMillis)
)
}
override fun AnimatedContentTransitionScope<NavBackStackEntry>.popEnterTransition(): EnterTransition? {
return slideInHorizontally(tween()) { -it }
return slideInHorizontally(
initialOffsetX = { -ScreenUtils.getScreenWidth() / 2 },
animationSpec = tween(durationMillis)
)
}
override fun AnimatedContentTransitionScope<NavBackStackEntry>.popExitTransition(): ExitTransition? {
return slideOutHorizontally(tween()) { it }
return slideOutHorizontally(
targetOffsetX = { ScreenUtils.getScreenWidth() }, animationSpec = tween(durationMillis)
)
}
}