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

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

Merge "Split nestedScrollToScene into horizontal and vertical variants" into main

parents ee6fc181 8bb6dbff
Loading
Loading
Loading
Loading
+24 −24
Original line number Diff line number Diff line
@@ -73,37 +73,37 @@ enum class NestedScrollBehavior(val canStartOnPostFling: Boolean) {
internal fun Modifier.nestedScrollToScene(
    layoutImpl: SceneTransitionLayoutImpl,
    orientation: Orientation,
    startBehavior: NestedScrollBehavior,
    endBehavior: NestedScrollBehavior,
    topOrLeftBehavior: NestedScrollBehavior,
    bottomOrRightBehavior: NestedScrollBehavior,
) =
    this then
        NestedScrollToSceneElement(
            layoutImpl = layoutImpl,
            orientation = orientation,
            startBehavior = startBehavior,
            endBehavior = endBehavior,
            topOrLeftBehavior = topOrLeftBehavior,
            bottomOrRightBehavior = bottomOrRightBehavior,
        )

private data class NestedScrollToSceneElement(
    private val layoutImpl: SceneTransitionLayoutImpl,
    private val orientation: Orientation,
    private val startBehavior: NestedScrollBehavior,
    private val endBehavior: NestedScrollBehavior,
    private val topOrLeftBehavior: NestedScrollBehavior,
    private val bottomOrRightBehavior: NestedScrollBehavior,
) : ModifierNodeElement<NestedScrollToSceneNode>() {
    override fun create() =
        NestedScrollToSceneNode(
            layoutImpl = layoutImpl,
            orientation = orientation,
            startBehavior = startBehavior,
            endBehavior = endBehavior,
            topOrLeftBehavior = topOrLeftBehavior,
            bottomOrRightBehavior = bottomOrRightBehavior,
        )

    override fun update(node: NestedScrollToSceneNode) {
        node.update(
            layoutImpl = layoutImpl,
            orientation = orientation,
            startBehavior = startBehavior,
            endBehavior = endBehavior,
            topOrLeftBehavior = topOrLeftBehavior,
            bottomOrRightBehavior = bottomOrRightBehavior,
        )
    }

@@ -111,23 +111,23 @@ private data class NestedScrollToSceneElement(
        name = "nestedScrollToScene"
        properties["layoutImpl"] = layoutImpl
        properties["orientation"] = orientation
        properties["startBehavior"] = startBehavior
        properties["endBehavior"] = endBehavior
        properties["topOrLeftBehavior"] = topOrLeftBehavior
        properties["bottomOrRightBehavior"] = bottomOrRightBehavior
    }
}

private class NestedScrollToSceneNode(
    layoutImpl: SceneTransitionLayoutImpl,
    orientation: Orientation,
    startBehavior: NestedScrollBehavior,
    endBehavior: NestedScrollBehavior,
    topOrLeftBehavior: NestedScrollBehavior,
    bottomOrRightBehavior: NestedScrollBehavior,
) : DelegatingNode() {
    private var priorityNestedScrollConnection: PriorityNestedScrollConnection =
        scenePriorityNestedScrollConnection(
            layoutImpl = layoutImpl,
            orientation = orientation,
            startBehavior = startBehavior,
            endBehavior = endBehavior,
            topOrLeftBehavior = topOrLeftBehavior,
            bottomOrRightBehavior = bottomOrRightBehavior,
        )

    private var nestedScrollNode: DelegatableNode =
@@ -148,8 +148,8 @@ private class NestedScrollToSceneNode(
    fun update(
        layoutImpl: SceneTransitionLayoutImpl,
        orientation: Orientation,
        startBehavior: NestedScrollBehavior,
        endBehavior: NestedScrollBehavior,
        topOrLeftBehavior: NestedScrollBehavior,
        bottomOrRightBehavior: NestedScrollBehavior,
    ) {
        // Clean up the old nested scroll connection
        priorityNestedScrollConnection.reset()
@@ -160,8 +160,8 @@ private class NestedScrollToSceneNode(
            scenePriorityNestedScrollConnection(
                layoutImpl = layoutImpl,
                orientation = orientation,
                startBehavior = startBehavior,
                endBehavior = endBehavior,
                topOrLeftBehavior = topOrLeftBehavior,
                bottomOrRightBehavior = bottomOrRightBehavior,
            )
        nestedScrollNode =
            nestedScrollModifierNode(
@@ -175,12 +175,12 @@ private class NestedScrollToSceneNode(
private fun scenePriorityNestedScrollConnection(
    layoutImpl: SceneTransitionLayoutImpl,
    orientation: Orientation,
    startBehavior: NestedScrollBehavior,
    endBehavior: NestedScrollBehavior,
    topOrLeftBehavior: NestedScrollBehavior,
    bottomOrRightBehavior: NestedScrollBehavior,
) =
    SceneNestedScrollHandler(
            gestureHandler = layoutImpl.gestureHandler(orientation = orientation),
            startBehavior = startBehavior,
            endBehavior = endBehavior,
            topOrLeftBehavior = topOrLeftBehavior,
            bottomOrRightBehavior = bottomOrRightBehavior,
        )
        .connection
+17 −7
Original line number Diff line number Diff line
@@ -86,16 +86,26 @@ private class SceneScopeImpl(
        return element(layoutImpl, scene, key)
    }

    override fun Modifier.nestedScrollToScene(
        orientation: Orientation,
        startBehavior: NestedScrollBehavior,
        endBehavior: NestedScrollBehavior,
    override fun Modifier.horizontalNestedScrollToScene(
        leftBehavior: NestedScrollBehavior,
        rightBehavior: NestedScrollBehavior,
    ): Modifier =
        nestedScrollToScene(
            layoutImpl = layoutImpl,
            orientation = orientation,
            startBehavior = startBehavior,
            endBehavior = endBehavior,
            orientation = Orientation.Horizontal,
            topOrLeftBehavior = leftBehavior,
            bottomOrRightBehavior = rightBehavior,
        )

    override fun Modifier.verticalNestedScrollToScene(
        topBehavior: NestedScrollBehavior,
        bottomBehavior: NestedScrollBehavior
    ): Modifier =
        nestedScrollToScene(
            layoutImpl = layoutImpl,
            orientation = Orientation.Vertical,
            topOrLeftBehavior = topBehavior,
            bottomOrRightBehavior = bottomBehavior,
        )

    @Composable
+7 −7
Original line number Diff line number Diff line
@@ -495,8 +495,8 @@ private class SceneDraggableHandler(

internal class SceneNestedScrollHandler(
        private val gestureHandler: SceneGestureHandler,
    private val startBehavior: NestedScrollBehavior,
    private val endBehavior: NestedScrollBehavior,
        private val topOrLeftBehavior: NestedScrollBehavior,
        private val bottomOrRightBehavior: NestedScrollBehavior,
) : NestedScrollHandler {
    override val connection: PriorityNestedScrollConnection = nestedScrollConnection()

@@ -565,8 +565,8 @@ internal class SceneNestedScrollHandler(
            canStartPostScroll = { offsetAvailable, offsetBeforeStart ->
                val behavior: NestedScrollBehavior =
                    when {
                        offsetAvailable > 0f -> startBehavior
                        offsetAvailable < 0f -> endBehavior
                        offsetAvailable > 0f -> topOrLeftBehavior
                        offsetAvailable < 0f -> bottomOrRightBehavior
                        else -> return@PriorityNestedScrollConnection false
                    }

@@ -594,8 +594,8 @@ internal class SceneNestedScrollHandler(
            canStartPostFling = { velocityAvailable ->
                val behavior: NestedScrollBehavior =
                    when {
                        velocityAvailable > 0f -> startBehavior
                        velocityAvailable < 0f -> endBehavior
                        velocityAvailable > 0f -> topOrLeftBehavior
                        velocityAvailable < 0f -> bottomOrRightBehavior
                        else -> return@PriorityNestedScrollConnection false
                    }

+17 −7
Original line number Diff line number Diff line
@@ -126,14 +126,24 @@ interface SceneScope {
     * Adds a [NestedScrollConnection] to intercept scroll events not handled by the scrollable
     * component.
     *
     * @param orientation is used to determine if we handle top/bottom or left/right events.
     * @param startBehavior when we should perform the overscroll animation at the top/left.
     * @param endBehavior when we should perform the overscroll animation at the bottom/right.
     * @param leftBehavior when we should perform the overscroll animation at the left.
     * @param rightBehavior when we should perform the overscroll animation at the right.
     */
    fun Modifier.nestedScrollToScene(
        orientation: Orientation,
        startBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoPreview,
        endBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoPreview,
    fun Modifier.horizontalNestedScrollToScene(
        leftBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoPreview,
        rightBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoPreview,
    ): Modifier

    /**
     * Adds a [NestedScrollConnection] to intercept scroll events not handled by the scrollable
     * component.
     *
     * @param topBehavior when we should perform the overscroll animation at the top.
     * @param bottomBehavior when we should perform the overscroll animation at the bottom.
     */
    fun Modifier.verticalNestedScrollToScene(
        topBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoPreview,
        bottomBehavior: NestedScrollBehavior = NestedScrollBehavior.EdgeNoPreview,
    ): Modifier

    /**
+2 −2
Original line number Diff line number Diff line
@@ -117,8 +117,8 @@ class SceneGestureHandlerTest {
        fun nestedScrollConnection(nestedScrollBehavior: NestedScrollBehavior) =
            SceneNestedScrollHandler(
                    gestureHandler = sceneGestureHandler,
                    startBehavior = nestedScrollBehavior,
                    endBehavior = nestedScrollBehavior,
                    topOrLeftBehavior = nestedScrollBehavior,
                    bottomOrRightBehavior = nestedScrollBehavior,
                )
                .connection