Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee4a5667 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't interpolate the STL size when overscrolling" into main

parents 47b9d6aa 28c272fe
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -293,7 +293,15 @@ private class LayoutNode(var layoutImpl: SceneTransitionLayoutImpl) :
                width = fromSize.width
                height = fromSize.height
            } else {
                val size = lerp(fromSize, toSize, transition.progress)
                val overscrollSpec = transition.currentOverscrollSpec
                val progress =
                    when {
                        overscrollSpec == null -> transition.progress
                        overscrollSpec.scene == transition.toScene -> 1f
                        else -> 0f
                    }

                val size = lerp(fromSize, toSize, progress)
                width = size.width.coerceAtLeast(0)
                height = size.height.coerceAtLeast(0)
            }
+37 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
@@ -332,6 +333,42 @@ class SceneTransitionLayoutTest {
        }
    }

    @Test
    fun layoutSizeDoesNotOverscrollWhenOverscrollIsSpecified() {
        val state =
            rule.runOnUiThread {
                MutableSceneTransitionLayoutStateImpl(
                    SceneA,
                    transitions { overscroll(SceneB, Orientation.Horizontal) }
                )
            }

        val layoutTag = "layout"
        rule.setContent {
            SceneTransitionLayout(state, Modifier.testTag(layoutTag)) {
                scene(SceneA) { Box(Modifier.size(50.dp)) }
                scene(SceneB) { Box(Modifier.size(70.dp)) }
            }
        }

        // Overscroll on A at -100%: size should be interpolated given that there is no overscroll
        // defined for scene A.
        var progress by mutableStateOf(-1f)
        rule.runOnIdle {
            state.startTransition(transition(from = SceneA, to = SceneB, progress = { progress }))
        }
        rule.onNodeWithTag(layoutTag).assertSizeIsEqualTo(30.dp)

        // Middle of the transition.
        progress = 0.5f
        rule.onNodeWithTag(layoutTag).assertSizeIsEqualTo(60.dp)

        // Overscroll on B at 200%: size should not be interpolated given that there is an
        // overscroll defined for scene B.
        progress = 2f
        rule.onNodeWithTag(layoutTag).assertSizeIsEqualTo(70.dp)
    }

    @Test
    fun multipleTransitionsWillComposeMultipleScenes() {
        val duration = 10 * 16L