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

Commit 28c272fe authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Don't interpolate the STL size when overscrolling

This CL ensures that we don't interpolate the size of a
SceneTransitionLayout when there is an overscroll defined on the scene
that is overscrolling.

Bug: 291053278
Test: atest SceneTransitionLayoutTest
Flag: com.android.systemui.scene_container
Change-Id: I6cc69b78c806b43903eb9d033116992b457f0cbb
parent 6052526d
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