pref: 调整动画速度

This commit is contained in:
HuanCheng65 2023-01-26 13:10:20 +08:00
parent 4b1a2e084b
commit 383758d779
No known key found for this signature in database
GPG Key ID: E9031EF91A805148
1 changed files with 22 additions and 5 deletions

View File

@ -13,12 +13,16 @@ import android.os.Handler
import android.os.Looper import android.os.Looper
import androidx.compose.animation.AnimatedContentScope import androidx.compose.animation.AnimatedContentScope
import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.VisibilityThreshold
import androidx.compose.animation.core.spring
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Surface import androidx.compose.material.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
@ -174,33 +178,46 @@ class MainActivityV2 : BaseComposeActivity() {
Surface( Surface(
color = ExtendedTheme.colors.background color = ExtendedTheme.colors.background
) { ) {
val animationSpec = spring(
stiffness = Spring.StiffnessMediumLow,
visibilityThreshold = IntOffset.VisibilityThreshold
)
val engine = rememberAnimatedNavHostEngine( val engine = rememberAnimatedNavHostEngine(
navHostContentAlignment = Alignment.TopStart, navHostContentAlignment = Alignment.TopStart,
rootDefaultAnimations = RootNavGraphDefaultAnimations( rootDefaultAnimations = RootNavGraphDefaultAnimations(
enterTransition = { enterTransition = {
slideIntoContainer( slideIntoContainer(
AnimatedContentScope.SlideDirection.Start, AnimatedContentScope.SlideDirection.Start,
initialOffset = { it }) animationSpec = animationSpec,
initialOffset = { it }
)
}, },
exitTransition = { exitTransition = {
slideOutOfContainer( slideOutOfContainer(
AnimatedContentScope.SlideDirection.End, AnimatedContentScope.SlideDirection.End,
targetOffset = { -it }) animationSpec = animationSpec,
targetOffset = { -it }
)
}, },
popEnterTransition = { popEnterTransition = {
slideIntoContainer( slideIntoContainer(
AnimatedContentScope.SlideDirection.Start, AnimatedContentScope.SlideDirection.Start,
initialOffset = { -it }) animationSpec = animationSpec,
initialOffset = { -it }
)
}, },
popExitTransition = { popExitTransition = {
slideOutOfContainer( slideOutOfContainer(
AnimatedContentScope.SlideDirection.End, AnimatedContentScope.SlideDirection.End,
targetOffset = { it }) animationSpec = animationSpec,
targetOffset = { it }
)
}, },
), ),
) )
val navController = rememberAnimatedNavController() val navController = rememberAnimatedNavController()
val bottomSheetNavigator = rememberBottomSheetNavigator() val bottomSheetNavigator =
rememberBottomSheetNavigator(animationSpec = spring(stiffness = Spring.StiffnessMediumLow))
navController.navigatorProvider += bottomSheetNavigator navController.navigatorProvider += bottomSheetNavigator
ModalBottomSheetLayout( ModalBottomSheetLayout(
bottomSheetNavigator = bottomSheetNavigator, bottomSheetNavigator = bottomSheetNavigator,