mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-25 10:37:51 +02:00
Revert "Implement predictive back animation (#10273)"
This reverts commit 9c120e6231
.
Potentially too buggy for a stable release for now.
This commit is contained in:
@ -1,11 +1,7 @@
|
||||
package tachiyomi.presentation.core.components
|
||||
|
||||
import androidx.activity.compose.PredictiveBackHandler
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.animate
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.AnchoredDraggableState
|
||||
@ -30,7 +26,6 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@ -39,11 +34,8 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.composed
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.TransformOrigin
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
||||
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
@ -53,14 +45,14 @@ import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.Velocity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.util.lerp
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
private val sheetAnimationSpec = tween<Float>(durationMillis = 350)
|
||||
|
||||
@Composable
|
||||
fun AdaptiveSheet(
|
||||
isTabletUi: Boolean,
|
||||
@ -99,11 +91,6 @@ fun AdaptiveSheet(
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.predictiveBackAnimation(
|
||||
enabled = remember { derivedStateOf { alpha > 0f } }.value,
|
||||
transformOrigin = TransformOrigin.Center,
|
||||
onBack = internalOnDismissRequest,
|
||||
)
|
||||
.requiredWidthIn(max = 460.dp)
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
@ -116,6 +103,7 @@ fun AdaptiveSheet(
|
||||
shape = MaterialTheme.shapes.extraLarge,
|
||||
tonalElevation = tonalElevation,
|
||||
content = {
|
||||
BackHandler(enabled = alpha > 0f, onBack = internalOnDismissRequest)
|
||||
content()
|
||||
},
|
||||
)
|
||||
@ -157,11 +145,6 @@ fun AdaptiveSheet(
|
||||
) {
|
||||
Surface(
|
||||
modifier = Modifier
|
||||
.predictiveBackAnimation(
|
||||
enabled = anchoredDraggableState.targetValue == 0,
|
||||
transformOrigin = TransformOrigin(0.5f, 1f),
|
||||
onBack = internalOnDismissRequest,
|
||||
)
|
||||
.widthIn(max = 460.dp)
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
@ -201,6 +184,10 @@ fun AdaptiveSheet(
|
||||
shape = MaterialTheme.shapes.extraLarge,
|
||||
tonalElevation = tonalElevation,
|
||||
content = {
|
||||
BackHandler(
|
||||
enabled = anchoredDraggableState.targetValue == 0,
|
||||
onBack = internalOnDismissRequest,
|
||||
)
|
||||
content()
|
||||
},
|
||||
)
|
||||
@ -270,37 +257,3 @@ private fun <T> AnchoredDraggableState<T>.preUpPostDownNestedScrollConnection()
|
||||
@JvmName("offsetToFloat")
|
||||
private fun Offset.toFloat(): Float = this.y
|
||||
}
|
||||
|
||||
private fun Modifier.predictiveBackAnimation(
|
||||
enabled: Boolean,
|
||||
transformOrigin: TransformOrigin,
|
||||
onBack: () -> Unit,
|
||||
) = composed {
|
||||
var scale by remember { mutableFloatStateOf(1f) }
|
||||
PredictiveBackHandler(enabled = enabled) { progress ->
|
||||
try {
|
||||
progress.collect { backEvent ->
|
||||
scale = lerp(1f, 0.85f, LinearOutSlowInEasing.transform(backEvent.progress))
|
||||
}
|
||||
// Completion
|
||||
onBack()
|
||||
} catch (e: CancellationException) {
|
||||
// Cancellation
|
||||
} finally {
|
||||
animate(
|
||||
initialValue = scale,
|
||||
targetValue = 1f,
|
||||
animationSpec = spring(stiffness = Spring.StiffnessLow),
|
||||
) { value, _ ->
|
||||
scale = value
|
||||
}
|
||||
}
|
||||
}
|
||||
Modifier.graphicsLayer {
|
||||
this.scaleX = scale
|
||||
this.scaleY = scale
|
||||
this.transformOrigin = transformOrigin
|
||||
}
|
||||
}
|
||||
|
||||
private val sheetAnimationSpec = tween<Float>(durationMillis = 350)
|
||||
|
Reference in New Issue
Block a user