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