Revert "Use motion scheme for scaffold animations"

This reverts commit 76a2766b071246027d4d693e7f15256175e655be.
This commit is contained in:
MM20 2025-06-01 18:45:28 +02:00
parent c7a66821ac
commit 7abff7998e
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.absoluteOffset
import androidx.compose.foundation.layout.add
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.exclude
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.ime
@ -38,6 +39,7 @@ import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.statusBarsPadding
@ -46,7 +48,6 @@ import androidx.compose.foundation.layout.waterfall
import androidx.compose.foundation.shape.CutCornerShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MotionScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
@ -223,7 +224,6 @@ enum class Gesture(val orientation: Orientation?) {
internal class LauncherScaffoldState(
private val config: ScaffoldConfiguration,
val size: Size,
val motionScheme: MotionScheme,
private val touchSlop: Float,
/**
* The threshold (in px) where a rubberband gesture is considered to be over the threshold
@ -241,16 +241,14 @@ internal class LauncherScaffoldState(
initialIsLocked: Boolean = false,
initialIsSearchBarHidden: Boolean = false,
) {
var currentOffset by mutableStateOf(
when {
initialGesture == null || initialGesture.orientation == null || config[initialGesture]?.animation == ScaffoldAnimation.Rubberband -> Offset.Zero
initialGesture == Gesture.SwipeRight -> Offset(-size.width, 0f)
initialGesture == Gesture.SwipeLeft -> Offset(size.width, 0f)
initialGesture == Gesture.SwipeUp -> Offset(0f, -size.height)
initialGesture == Gesture.SwipeDown -> Offset(0f, size.height)
else -> Offset.Zero
}
)
var currentOffset by mutableStateOf(when {
initialGesture == null || initialGesture.orientation == null || config[initialGesture]?.animation == ScaffoldAnimation.Rubberband -> Offset.Zero
initialGesture == Gesture.SwipeRight -> Offset(-size.width, 0f)
initialGesture == Gesture.SwipeLeft -> Offset(size.width, 0f)
initialGesture == Gesture.SwipeUp -> Offset(0f, -size.height)
initialGesture == Gesture.SwipeDown -> Offset(0f, size.height)
else -> Offset.Zero
})
private set
var currentZOffset by mutableFloatStateOf(
if (initialGesture != null && initialGesture.orientation == null) 1f else 0f
@ -662,7 +660,6 @@ internal class LauncherScaffoldState(
offsetAnimatable.animateTo(
Offset.Zero,
initialVelocity = Offset(velocity.x, velocity.y),
animationSpec = motionScheme.defaultSpatialSpec(),
) {
currentOffset = this.value
}
@ -740,7 +737,6 @@ internal class LauncherScaffoldState(
offsetAnimatable.animateTo(
targetOffset,
initialVelocity = Offset(velocity.x, velocity.y),
animationSpec = motionScheme.defaultSpatialSpec(),
) {
currentOffset = this.value
}
@ -830,10 +826,7 @@ internal class LauncherScaffoldState(
if (gesture.orientation == null) {
zAnimatable.snapTo(currentZOffset)
zAnimatable.animateTo(
1f,
animationSpec = motionScheme.defaultSpatialSpec(),
) {
zAnimatable.animateTo(1f, animationSpec = tween(100)) {
currentZOffset = this.value
}
} else {
@ -850,10 +843,7 @@ internal class LauncherScaffoldState(
}
offsetAnimatable.snapTo(currentOffset)
offsetAnimatable.animateTo(
targetOffset,
animationSpec = motionScheme.defaultSpatialSpec(),
) {
offsetAnimatable.animateTo(targetOffset) {
currentOffset = this.value
}
}
@ -878,17 +868,14 @@ internal class LauncherScaffoldState(
if (gesture.orientation == null) {
zAnimatable.snapTo(currentZOffset)
zAnimatable.animateTo(
0f,
animationSpec = motionScheme.defaultSpatialSpec()
) {
zAnimatable.animateTo(0f, animationSpec = tween(100)) {
currentZOffset = this.value
}
} else {
offsetAnimatable.snapTo(currentOffset)
offsetAnimatable.animateTo(
Offset.Zero,
animationSpec = if (fast) tween(150) else motionScheme.defaultSpatialSpec()
animationSpec = if (fast) tween(150) else spring()
) {
currentOffset = this.value
}
@ -1001,17 +988,11 @@ internal class LauncherScaffoldState(
}
offsetAnimatable.snapTo(currentOffset)
offsetAnimatable.animateTo(
targetOffset,
animationSpec = motionScheme.defaultSpatialSpec(),
) {
offsetAnimatable.animateTo(targetOffset) {
currentOffset = this.value
}
isSettledOnSecondaryPage = true
offsetAnimatable.animateTo(
Offset.Zero,
animationSpec = motionScheme.defaultSpatialSpec(),
) {
offsetAnimatable.animateTo(Offset.Zero) {
currentOffset = this.value
}
} else {
@ -1023,10 +1004,7 @@ internal class LauncherScaffoldState(
else -> Offset.Zero
}
offsetAnimatable.snapTo(currentOffset)
offsetAnimatable.animateTo(
targetOffset,
animationSpec = motionScheme.defaultSpatialSpec(),
) {
offsetAnimatable.animateTo(targetOffset) {
currentOffset = this.value
}
isSettledOnSecondaryPage = true
@ -1066,7 +1044,7 @@ internal class LauncherScaffoldState(
searchBarAnimatable.snapTo(currentSearchBarOffset)
searchBarAnimatable.animateTo(
if (config.searchBarPosition == SearchBarPosition.Bottom) maxSearchBarOffset else -maxSearchBarOffset,
animationSpec = motionScheme.defaultSpatialSpec(),
tween(500)
) {
if (isSettledOnSecondaryPage) {
secondaryPageSearchBarOffset = this.value
@ -1084,7 +1062,7 @@ internal class LauncherScaffoldState(
searchBarAnimatable.snapTo(currentSearchBarOffset)
searchBarAnimatable.animateTo(
0f,
animationSpec = motionScheme.defaultSpatialSpec(),
tween(500)
) {
if (isSettledOnSecondaryPage) {
secondaryPageSearchBarOffset = this.value
@ -1141,17 +1119,10 @@ internal fun LauncherScaffold(
) + 128.dp.toPixels()
val hapticFeedback = LocalHapticFeedback.current
val motionScheme = MaterialTheme.motionScheme
val state =
rememberSaveable(
widthPx,
heightPx,
touchSlop,
rubberbandThreshold,
minFlingVelocity,
config,
motionScheme,
widthPx, heightPx, touchSlop, rubberbandThreshold, minFlingVelocity, config,
saver = listSaver(
save = {
listOf(
@ -1162,7 +1133,6 @@ internal fun LauncherScaffold(
},
restore = {
LauncherScaffoldState(
motionScheme = motionScheme,
config = config,
size = Size(widthPx, heightPx),
touchSlop = touchSlop,
@ -1182,7 +1152,6 @@ internal fun LauncherScaffold(
LauncherScaffoldState(
config = config,
size = Size(widthPx, heightPx),
motionScheme = motionScheme,
touchSlop = touchSlop,
rubberbandThreshold = rubberbandThreshold,
velocityThreshold = minFlingVelocity,
@ -1257,10 +1226,8 @@ internal fun LauncherScaffold(
if (config.wallpaperBlurRadius > 0.dp) {
val wallpaperBlur by animateIntAsState(
if (state.currentProgress >= 0.5f && (state.currentComponent?.drawBackground
?: config.homeComponent.drawBackground)
|| state.currentProgress < 0.5f && config.homeComponent.drawBackground
) {
if (state.currentProgress >= 0.5f && (state.currentComponent?.drawBackground ?: config.homeComponent.drawBackground)
|| state.currentProgress < 0.5f && config.homeComponent.drawBackground) {
8.dp.toPixels().toInt()
} else {
0
@ -1654,16 +1621,12 @@ private fun Modifier.homePageAnimation(
.background(backgroundColor)
}
return this then component.homePageModifier(
state,
Modifier
.background(backgroundColor)
.absoluteOffset {
IntOffset(
x = if (dir.orientation == Orientation.Horizontal) state.currentOffset.x.toInt() else 0,
y = if (dir.orientation == Orientation.Vertical) state.currentOffset.y.toInt() else 0
)
})
return this then component.homePageModifier(state, Modifier.background(backgroundColor).absoluteOffset {
IntOffset(
x = if (dir.orientation == Orientation.Horizontal) state.currentOffset.x.toInt() else 0,
y = if (dir.orientation == Orientation.Vertical) state.currentOffset.y.toInt() else 0
)
})
}
private fun Modifier.secondaryPageAnimation(