mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
optimize animations
This commit is contained in:
@@ -48,7 +48,6 @@ import com.bintianqi.owndroid.ui.theme.bgColor
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
var backToHome = false
|
||||
lateinit var displayMetrics: DisplayMetrics
|
||||
@ExperimentalMaterial3Api
|
||||
class MainActivity : ComponentActivity() {
|
||||
private fun registerActivityResult(){
|
||||
@@ -75,7 +74,6 @@ class MainActivity : ComponentActivity() {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
super.onCreate(savedInstanceState)
|
||||
registerActivityResult()
|
||||
displayMetrics = applicationContext.resources.displayMetrics
|
||||
setContent {
|
||||
OwnDroidTheme {
|
||||
MyScaffold()
|
||||
|
||||
@@ -1,56 +1,50 @@
|
||||
package com.bintianqi.owndroid.ui
|
||||
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.animation.core.FiniteAnimationSpec
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.VisibilityThreshold
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.*
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import com.bintianqi.owndroid.displayMetrics
|
||||
|
||||
class Animations{
|
||||
private val fade: FiniteAnimationSpec<Float> = spring(stiffness = Spring.StiffnessMediumLow)
|
||||
private val spring:FiniteAnimationSpec<IntOffset> = spring(stiffness = Spring.StiffnessMediumLow, visibilityThreshold = IntOffset.VisibilityThreshold)
|
||||
|
||||
val animateListSize:FiniteAnimationSpec<IntSize> = spring(stiffness = Spring.StiffnessMediumLow, visibilityThreshold = IntSize.VisibilityThreshold)
|
||||
|
||||
private val screenWidth = displayMetrics.widthPixels
|
||||
private val initialOffsetValue = screenWidth/10
|
||||
private val targetOffsetValue = screenWidth/10
|
||||
|
||||
private val initialOffsetValue = 96
|
||||
private val targetOffsetValue = 96
|
||||
|
||||
private val bezier = CubicBezierEasing(0.3f, 0f, 0f, 1f)
|
||||
|
||||
private val tween: FiniteAnimationSpec<IntOffset> = tween(450, easing = bezier)
|
||||
|
||||
val navHostEnterTransition: AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition = {
|
||||
fadeIn(animationSpec = fade) +
|
||||
fadeIn(tween(83, easing = LinearEasing)) +
|
||||
slideIntoContainer(
|
||||
animationSpec = spring,
|
||||
animationSpec = tween,
|
||||
towards = AnimatedContentTransitionScope.SlideDirection.End,
|
||||
initialOffset = {initialOffsetValue}
|
||||
)
|
||||
}
|
||||
|
||||
val navHostExitTransition: AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition = {
|
||||
fadeOut(animationSpec = fade) +
|
||||
slideOutOfContainer(
|
||||
animationSpec = spring,
|
||||
animationSpec = tween,
|
||||
towards = AnimatedContentTransitionScope.SlideDirection.Start,
|
||||
targetOffset = {-targetOffsetValue}
|
||||
)
|
||||
}
|
||||
|
||||
val navHostPopEnterTransition: AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition = {
|
||||
fadeIn(animationSpec = fade) +
|
||||
slideIntoContainer(
|
||||
animationSpec = spring,
|
||||
animationSpec = tween,
|
||||
towards = AnimatedContentTransitionScope.SlideDirection.End,
|
||||
initialOffset = {-initialOffsetValue}
|
||||
)
|
||||
}
|
||||
|
||||
val navHostPopExitTransition: AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition = {
|
||||
fadeOut(animationSpec = fade) +
|
||||
fadeOut(tween(83, easing = LinearEasing)) +
|
||||
slideOutOfContainer(
|
||||
animationSpec = spring,
|
||||
animationSpec = tween,
|
||||
towards = AnimatedContentTransitionScope.SlideDirection.Start,
|
||||
targetOffset = {targetOffsetValue}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user