Skip to content

Commit

Permalink
fix: 路由动画卡顿
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Nov 18, 2023
1 parent 4d020c9 commit f182706
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/src/main/java/li/songe/gkd/util/ProfileTransitions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}

0 comments on commit f182706

Please sign in to comment.