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

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

Merge "STL: Removed DuringTransitionBetweenScenes from NestedScrollBehavior" into main

parents 221ae24e cad4255a
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -1024,10 +1024,6 @@ internal class NestedScrollHandlerImpl(

                val canStart =
                    when (behavior) {
                        NestedScrollBehavior.DuringTransitionBetweenScenes -> {
                            canChangeScene = false // unused: added for consistency
                            false
                        }
                        NestedScrollBehavior.EdgeNoPreview -> {
                            canChangeScene = isZeroOffset
                            isZeroOffset && hasNextScene(offsetAvailable)
+0 −7
Original line number Diff line number Diff line
@@ -34,13 +34,6 @@ import androidx.compose.ui.platform.InspectorInfo
 * [nestedScrollToScene].
 */
enum class NestedScrollBehavior(val canStartOnPostFling: Boolean) {
    /**
     * During scene transitions, if we are within
     * [SceneTransitionLayoutImpl.transitionInterceptionThreshold], the [SceneTransitionLayout]
     * consumes scroll events instead of the scrollable component.
     */
    DuringTransitionBetweenScenes(canStartOnPostFling = false),

    /**
     * Overscroll will only be used by the [SceneTransitionLayout] to move to the next scene if the
     * gesture begins at the edge of the scrollable component (so that a scroll in that direction
+0 −15
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.Velocity
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.compose.animation.scene.NestedScrollBehavior.DuringTransitionBetweenScenes
import com.android.compose.animation.scene.NestedScrollBehavior.EdgeAlways
import com.android.compose.animation.scene.NestedScrollBehavior.EdgeNoPreview
import com.android.compose.animation.scene.NestedScrollBehavior.EdgeWithPreview
@@ -729,13 +728,6 @@ class DraggableHandlerTest {
        nestedScroll.preFling(available = Velocity(0f, velocityThreshold))
    }

    @Test
    fun flingAfterScroll_DuringTransitionBetweenScenes_doNothing() = runGestureTest {
        flingAfterScroll(use = DuringTransitionBetweenScenes, idleAfterScroll = true)

        assertIdle(currentScene = SceneA)
    }

    @Test
    fun flingAfterScroll_EdgeNoOverscroll_goToNextScene() = runGestureTest {
        flingAfterScroll(use = EdgeNoPreview, idleAfterScroll = false)
@@ -788,13 +780,6 @@ class DraggableHandlerTest {
        nestedScroll.preFling(available = Velocity(0f, velocityThreshold))
    }

    @Test
    fun flingAfterScrollStartedInScene_DuringTransitionBetweenScenes_doNothing() = runGestureTest {
        flingAfterScrollStartedInScene(use = DuringTransitionBetweenScenes, idleAfterScroll = true)

        assertIdle(currentScene = SceneA)
    }

    @Test
    fun flingAfterScrollStartedInScene_EdgeNoOverscroll_doNothing() = runGestureTest {
        flingAfterScrollStartedInScene(use = EdgeNoPreview, idleAfterScroll = true)
+10 −32
Original line number Diff line number Diff line
@@ -132,33 +132,6 @@ class NestedScrollToSceneTest {
        assertThat(transition).hasProgress(1.5f)
    }

    @Test
    fun customizeStlNestedScrollBehavior_DuringTransitionBetweenScenes() {
        var canScroll = true
        val state = setup2ScenesAndScrollTouchSlop {
            Modifier.verticalNestedScrollToScene(
                    bottomBehavior = NestedScrollBehavior.DuringTransitionBetweenScenes
                )
                .scrollable(rememberScrollableState { if (canScroll) it else 0f }, Vertical)
        }

        scrollUp(percent = 0.5f)
        assertThat(state.transitionState).isIdle()

        // Reach the end of the scrollable element
        canScroll = false
        scrollUp(percent = 0.5f)
        assertThat(state.transitionState).isIdle()

        pointerUp()
        assertThat(state.transitionState).isIdle()

        // Start a new gesture
        pointerDownAndScrollTouchSlop()
        scrollUp(percent = 0.5f)
        assertThat(state.transitionState).isIdle()
    }

    @Test
    fun customizeStlNestedScrollBehavior_EdgeNoPreview() {
        var canScroll = true
@@ -253,19 +226,24 @@ class NestedScrollToSceneTest {

    @Test
    fun customizeStlNestedScrollBehavior_multipleRequests() {
        var canScroll = true
        val state = setup2ScenesAndScrollTouchSlop {
            Modifier
                // This verticalNestedScrollToScene is closer the STL (an ancestor node)
                .verticalNestedScrollToScene(bottomBehavior = NestedScrollBehavior.EdgeAlways)
                // Another verticalNestedScrollToScene modifier
                .verticalNestedScrollToScene(
                    bottomBehavior = NestedScrollBehavior.DuringTransitionBetweenScenes
                )
                .scrollable(rememberScrollableState { 0f }, Vertical)
                .verticalNestedScrollToScene(bottomBehavior = NestedScrollBehavior.EdgeNoPreview)
                .scrollable(rememberScrollableState { if (canScroll) it else 0f }, Vertical)
        }

        scrollUp(percent = 0.5f)
        // EdgeAlways always consume the remaining scroll, DuringTransitionBetweenScenes does not.
        assertThat(state.transitionState).isIdle()

        // Reach the end of the scrollable element
        canScroll = false

        scrollUp(percent = 0.5f)
        // EdgeAlways always consume the remaining scroll, EdgeNoPreview does not.
        val transition = assertThat(state.transitionState).isTransition()
        assertThat(transition).hasProgress(0.5f)
    }