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

Commit c9d14bbb authored by Omar Miatello's avatar Omar Miatello Committed by Android (Google) Code Review
Browse files

Merge "New naming for NestedScrollBehavior" into main

parents 0cd0ff84 aa6bc87d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -44,22 +44,22 @@ enum class NestedScrollBehavior(val canStartOnPostFling: Boolean) {
     * 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
     * can no longer be consumed). If the gesture is partially consumed by the scrollable component,
     * there will be NO overscroll effect between scenes.
     * there will be NO preview of the next scene.
     *
     * In addition, during scene transitions, scroll events are consumed by the
     * [SceneTransitionLayout] instead of the scrollable component.
     */
    EdgeNoOverscroll(canStartOnPostFling = false),
    EdgeNoPreview(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. If the gesture is partially consumed
     * by the scrollable component, there will be an overscroll effect between scenes.
     * by the scrollable component, there will be a preview of the next scene.
     *
     * In addition, during scene transitions, scroll events are consumed by the
     * [SceneTransitionLayout] instead of the scrollable component.
     */
    EdgeWithOverscroll(canStartOnPostFling = true),
    EdgeWithPreview(canStartOnPostFling = true),

    /**
     * Any overscroll will be used by the [SceneTransitionLayout] to move to the next scene.
@@ -67,7 +67,7 @@ enum class NestedScrollBehavior(val canStartOnPostFling: Boolean) {
     * In addition, during scene transitions, scroll events are consumed by the
     * [SceneTransitionLayout] instead of the scrollable component.
     */
    Always(canStartOnPostFling = true),
    EdgeAlways(canStartOnPostFling = true),
}

internal fun Modifier.nestedScrollToScene(
+3 −3
Original line number Diff line number Diff line
@@ -577,15 +577,15 @@ internal class SceneNestedScrollHandler(
                        canChangeScene = false // unused: added for consistency
                        false
                    }
                    NestedScrollBehavior.EdgeNoOverscroll -> {
                    NestedScrollBehavior.EdgeNoPreview -> {
                        canChangeScene = isZeroOffset
                        isZeroOffset && hasNextScene(offsetAvailable)
                    }
                    NestedScrollBehavior.EdgeWithOverscroll -> {
                    NestedScrollBehavior.EdgeWithPreview -> {
                        canChangeScene = isZeroOffset
                        hasNextScene(offsetAvailable)
                    }
                    NestedScrollBehavior.Always -> {
                    NestedScrollBehavior.EdgeAlways -> {
                        canChangeScene = true
                        hasNextScene(offsetAvailable)
                    }
+2 −2
Original line number Diff line number Diff line
@@ -132,8 +132,8 @@ interface SceneScope {
     */
    fun Modifier.nestedScrollToScene(
        orientation: Orientation,
        startBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoOverscroll,
        endBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoOverscroll,
        startBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoPreview,
        endBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoPreview,
    ): Modifier

    /**
+17 −17
Original line number Diff line number Diff line
@@ -29,10 +29,10 @@ import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.Velocity
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.compose.animation.scene.NestedScrollBehavior.Always
import com.android.compose.animation.scene.NestedScrollBehavior.DuringTransitionBetweenScenes
import com.android.compose.animation.scene.NestedScrollBehavior.EdgeNoOverscroll
import com.android.compose.animation.scene.NestedScrollBehavior.EdgeWithOverscroll
import com.android.compose.animation.scene.NestedScrollBehavior.EdgeAlways
import com.android.compose.animation.scene.NestedScrollBehavior.EdgeNoPreview
import com.android.compose.animation.scene.NestedScrollBehavior.EdgeWithPreview
import com.android.compose.animation.scene.TestScenes.SceneA
import com.android.compose.animation.scene.TestScenes.SceneB
import com.android.compose.animation.scene.TestScenes.SceneC
@@ -439,14 +439,14 @@ class SceneGestureHandlerTest {

    @Test
    fun onInitialPreScroll_EdgeWithOverscroll_doNotChangeState() = runGestureTest {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
        nestedScroll.onPreScroll(available = offsetY10, source = NestedScrollSource.Drag)
        assertIdle(currentScene = SceneA)
    }

    @Test
    fun onPostScrollWithNothingAvailable_EdgeWithOverscroll_doNotChangeState() = runGestureTest {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
        val consumed =
            nestedScroll.onPostScroll(
                consumed = Offset.Zero,
@@ -460,7 +460,7 @@ class SceneGestureHandlerTest {

    @Test
    fun onPostScrollWithSomethingAvailable_startSceneTransition() = runGestureTest {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
        val consumed =
            nestedScroll.onPostScroll(
                consumed = Offset.Zero,
@@ -489,7 +489,7 @@ class SceneGestureHandlerTest {

    @Test
    fun afterSceneTransitionIsStarted_interceptPreScrollEvents() = runGestureTest {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
        nestedScroll.scroll(available = offsetY10)
        assertTransition(currentScene = SceneA)

@@ -517,7 +517,7 @@ class SceneGestureHandlerTest {
        firstScroll: Float,
        secondScroll: Float
    ) {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
        // start scene transition
        nestedScroll.scroll(available = Offset(0f, SCREEN_SIZE * firstScroll))

@@ -570,7 +570,7 @@ class SceneGestureHandlerTest {

    @Test
    fun onPreFling_velocityLowerThanThreshold_remainSameScene() = runGestureTest {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
        nestedScroll.scroll(available = offsetY10)
        assertTransition(currentScene = SceneA)

@@ -602,7 +602,7 @@ class SceneGestureHandlerTest {

    @Test
    fun flingAfterScroll_EdgeNoOverscroll_goToNextScene() = runGestureTest {
        flingAfterScroll(use = EdgeNoOverscroll, idleAfterScroll = false)
        flingAfterScroll(use = EdgeNoPreview, idleAfterScroll = false)

        assertTransition(currentScene = SceneC)

@@ -613,7 +613,7 @@ class SceneGestureHandlerTest {

    @Test
    fun flingAfterScroll_EdgeWithOverscroll_goToNextScene() = runGestureTest {
        flingAfterScroll(use = EdgeWithOverscroll, idleAfterScroll = false)
        flingAfterScroll(use = EdgeWithPreview, idleAfterScroll = false)

        assertTransition(currentScene = SceneC)

@@ -624,7 +624,7 @@ class SceneGestureHandlerTest {

    @Test
    fun flingAfterScroll_Always_goToNextScene() = runGestureTest {
        flingAfterScroll(use = Always, idleAfterScroll = false)
        flingAfterScroll(use = EdgeAlways, idleAfterScroll = false)

        assertTransition(currentScene = SceneC)

@@ -658,14 +658,14 @@ class SceneGestureHandlerTest {

    @Test
    fun flingAfterScrollStartedInScene_EdgeNoOverscroll_doNothing() = runGestureTest {
        flingAfterScrollStartedInScene(use = EdgeNoOverscroll, idleAfterScroll = true)
        flingAfterScrollStartedInScene(use = EdgeNoPreview, idleAfterScroll = true)

        assertIdle(currentScene = SceneA)
    }

    @Test
    fun flingAfterScrollStartedInScene_EdgeWithOverscroll_doOverscrollAnimation() = runGestureTest {
        flingAfterScrollStartedInScene(use = EdgeWithOverscroll, idleAfterScroll = false)
        flingAfterScrollStartedInScene(use = EdgeWithPreview, idleAfterScroll = false)

        assertTransition(currentScene = SceneA)

@@ -676,7 +676,7 @@ class SceneGestureHandlerTest {

    @Test
    fun flingAfterScrollStartedInScene_Always_goToNextScene() = runGestureTest {
        flingAfterScrollStartedInScene(use = Always, idleAfterScroll = false)
        flingAfterScrollStartedInScene(use = EdgeAlways, idleAfterScroll = false)

        assertTransition(currentScene = SceneC)

@@ -699,14 +699,14 @@ class SceneGestureHandlerTest {

    @Test
    fun beforeNestedScrollStart_stop_shouldBeIgnored() = runGestureTest {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithOverscroll)
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
        nestedScroll.onPreFling(Velocity(0f, velocityThreshold))
        assertIdle(currentScene = SceneA)
    }

    @Test
    fun startNestedScrollWhileDragging() = runGestureTest {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = Always)
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeAlways)
        draggable.onDragStarted()
        assertTransition(currentScene = SceneA)