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

Commit 240d0255 authored by omarmt's avatar omarmt
Browse files

STL clean-up DraggableHandler

Test: Just a refactor.
Bug: 378470603
Flag: com.android.systemui.scene_container
Change-Id: I47e25dab76ac33eccd40d079f3f4d41d8f7db433
parent 4fb46342
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -530,16 +530,12 @@ internal class Swipes(val upOrLeft: Swipe.Resolved, val downOrRight: Swipe.Resol
}

internal class NestedScrollHandlerImpl(
    private val layoutImpl: SceneTransitionLayoutImpl,
    private val orientation: Orientation,
    private val draggableHandler: DraggableHandlerImpl,
    internal var topOrLeftBehavior: NestedScrollBehavior,
    internal var bottomOrRightBehavior: NestedScrollBehavior,
    internal var isExternalOverscrollGesture: () -> Boolean,
    private val pointersInfoOwner: PointersInfoOwner,
) {
    private val layoutState = layoutImpl.state
    private val draggableHandler = layoutImpl.draggableHandler(orientation)

    val connection: PriorityNestedScrollConnection = nestedScrollConnection()

    private fun nestedScrollConnection(): PriorityNestedScrollConnection {
@@ -550,13 +546,15 @@ internal class NestedScrollHandlerImpl(
        var lastPointersDown: PointersInfo.PointersDown? = null

        fun shouldEnableSwipes(): Boolean {
            return layoutImpl.contentForUserActions().shouldEnableSwipes(orientation)
            return draggableHandler.layoutImpl
                .contentForUserActions()
                .shouldEnableSwipes(draggableHandler.orientation)
        }

        var isIntercepting = false

        return PriorityNestedScrollConnection(
            orientation = orientation,
            orientation = draggableHandler.orientation,
            canStartPreScroll = { offsetAvailable, offsetBeforeStart, _ ->
                val pointersDown: PointersInfo.PointersDown? =
                    when (val info = pointersInfoOwner.pointersInfo()) {
@@ -578,8 +576,9 @@ internal class NestedScrollHandlerImpl(
                        draggableHandler.shouldImmediatelyIntercept(pointersDown)
                if (!canInterceptSwipeTransition) return@PriorityNestedScrollConnection false

                val layoutImpl = draggableHandler.layoutImpl
                val threshold = layoutImpl.transitionInterceptionThreshold
                val hasSnappedToIdle = layoutState.snapToIdleIfClose(threshold)
                val hasSnappedToIdle = layoutImpl.state.snapToIdleIfClose(threshold)
                if (hasSnappedToIdle) {
                    // If the current swipe transition is closed to 0f or 1f, then we want to
                    // interrupt the transition (snapping it to Idle) and scroll the list.
+11 −25
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.compose.animation.scene

import androidx.compose.foundation.gestures.Orientation
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
@@ -69,32 +68,28 @@ enum class NestedScrollBehavior(val canStartOnPostFling: Boolean) {
}

internal fun Modifier.nestedScrollToScene(
    layoutImpl: SceneTransitionLayoutImpl,
    orientation: Orientation,
    draggableHandler: DraggableHandlerImpl,
    topOrLeftBehavior: NestedScrollBehavior,
    bottomOrRightBehavior: NestedScrollBehavior,
    isExternalOverscrollGesture: () -> Boolean,
) =
    this then
        NestedScrollToSceneElement(
            layoutImpl = layoutImpl,
            orientation = orientation,
            draggableHandler = draggableHandler,
            topOrLeftBehavior = topOrLeftBehavior,
            bottomOrRightBehavior = bottomOrRightBehavior,
            isExternalOverscrollGesture = isExternalOverscrollGesture,
        )

private data class NestedScrollToSceneElement(
    private val layoutImpl: SceneTransitionLayoutImpl,
    private val orientation: Orientation,
    private val draggableHandler: DraggableHandlerImpl,
    private val topOrLeftBehavior: NestedScrollBehavior,
    private val bottomOrRightBehavior: NestedScrollBehavior,
    private val isExternalOverscrollGesture: () -> Boolean,
) : ModifierNodeElement<NestedScrollToSceneNode>() {
    override fun create() =
        NestedScrollToSceneNode(
            layoutImpl = layoutImpl,
            orientation = orientation,
            draggableHandler = draggableHandler,
            topOrLeftBehavior = topOrLeftBehavior,
            bottomOrRightBehavior = bottomOrRightBehavior,
            isExternalOverscrollGesture = isExternalOverscrollGesture,
@@ -102,8 +97,7 @@ private data class NestedScrollToSceneElement(

    override fun update(node: NestedScrollToSceneNode) {
        node.update(
            layoutImpl = layoutImpl,
            orientation = orientation,
            draggableHandler = draggableHandler,
            topOrLeftBehavior = topOrLeftBehavior,
            bottomOrRightBehavior = bottomOrRightBehavior,
            isExternalOverscrollGesture = isExternalOverscrollGesture,
@@ -112,16 +106,14 @@ private data class NestedScrollToSceneElement(

    override fun InspectorInfo.inspectableProperties() {
        name = "nestedScrollToScene"
        properties["layoutImpl"] = layoutImpl
        properties["orientation"] = orientation
        properties["draggableHandler"] = draggableHandler
        properties["topOrLeftBehavior"] = topOrLeftBehavior
        properties["bottomOrRightBehavior"] = bottomOrRightBehavior
    }
}

private class NestedScrollToSceneNode(
    private var layoutImpl: SceneTransitionLayoutImpl,
    private var orientation: Orientation,
    private var draggableHandler: DraggableHandlerImpl,
    private var topOrLeftBehavior: NestedScrollBehavior,
    private var bottomOrRightBehavior: NestedScrollBehavior,
    private var isExternalOverscrollGesture: () -> Boolean,
@@ -129,12 +121,8 @@ private class NestedScrollToSceneNode(
    private var scrollBehaviorOwner: ScrollBehaviorOwner? = null

    private fun findScrollBehaviorOwner(): ScrollBehaviorOwner? {
        var behaviorOwner = scrollBehaviorOwner
        if (behaviorOwner == null) {
            behaviorOwner = findScrollBehaviorOwner(layoutImpl.draggableHandler(orientation))
            scrollBehaviorOwner = behaviorOwner
        }
        return behaviorOwner
        return scrollBehaviorOwner
            ?: findScrollBehaviorOwner(draggableHandler).also { scrollBehaviorOwner = it }
    }

    private val updateScrollBehaviorsConnection =
@@ -177,14 +165,12 @@ private class NestedScrollToSceneNode(
    }

    fun update(
        layoutImpl: SceneTransitionLayoutImpl,
        orientation: Orientation,
        draggableHandler: DraggableHandlerImpl,
        topOrLeftBehavior: NestedScrollBehavior,
        bottomOrRightBehavior: NestedScrollBehavior,
        isExternalOverscrollGesture: () -> Boolean,
    ) {
        this.layoutImpl = layoutImpl
        this.orientation = orientation
        this.draggableHandler = draggableHandler
        this.topOrLeftBehavior = topOrLeftBehavior
        this.bottomOrRightBehavior = bottomOrRightBehavior
        this.isExternalOverscrollGesture = isExternalOverscrollGesture
+2 −8
Original line number Diff line number Diff line
@@ -125,8 +125,8 @@ internal class SceneTransitionLayoutImpl(
                }

    // TODO(b/317958526): Lazily allocate scene gesture handlers the first time they are needed.
    private val horizontalDraggableHandler: DraggableHandlerImpl
    private val verticalDraggableHandler: DraggableHandlerImpl
    internal val horizontalDraggableHandler: DraggableHandlerImpl
    internal val verticalDraggableHandler: DraggableHandlerImpl

    internal val elementStateScope = ElementStateScopeImpl(this)
    internal val propertyTransformationScope = PropertyTransformationScopeImpl(this)
@@ -163,12 +163,6 @@ internal class SceneTransitionLayoutImpl(
        state.checkThread()
    }

    internal fun draggableHandler(orientation: Orientation): DraggableHandlerImpl =
        when (orientation) {
            Orientation.Vertical -> verticalDraggableHandler
            Orientation.Horizontal -> horizontalDraggableHandler
        }

    internal fun scene(key: SceneKey): Scene {
        return scenes[key] ?: error("Scene $key is not configured")
    }
+1 −2
Original line number Diff line number Diff line
@@ -165,8 +165,7 @@ private class SwipeToSceneNode(

    private val nestedScrollHandlerImpl =
        NestedScrollHandlerImpl(
            layoutImpl = draggableHandler.layoutImpl,
            orientation = draggableHandler.orientation,
            draggableHandler = draggableHandler,
            topOrLeftBehavior = NestedScrollBehavior.Default,
            bottomOrRightBehavior = NestedScrollBehavior.Default,
            isExternalOverscrollGesture = { false },
+4 −5
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.compose.animation.scene.content

import androidx.compose.foundation.gestures.Orientation
import android.annotation.SuppressLint
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
@@ -72,6 +72,7 @@ internal sealed class Content(
    var targetSize by mutableStateOf(IntSize.Zero)
    var userActions by mutableStateOf(actions)

    @SuppressLint("NotConstructor")
    @Composable
    fun Content(modifier: Modifier = Modifier) {
        Box(
@@ -151,8 +152,7 @@ internal class ContentScopeImpl(
        isExternalOverscrollGesture: () -> Boolean,
    ): Modifier {
        return nestedScrollToScene(
            layoutImpl = layoutImpl,
            orientation = Orientation.Horizontal,
            draggableHandler = layoutImpl.horizontalDraggableHandler,
            topOrLeftBehavior = leftBehavior,
            bottomOrRightBehavior = rightBehavior,
            isExternalOverscrollGesture = isExternalOverscrollGesture,
@@ -165,8 +165,7 @@ internal class ContentScopeImpl(
        isExternalOverscrollGesture: () -> Boolean,
    ): Modifier {
        return nestedScrollToScene(
            layoutImpl = layoutImpl,
            orientation = Orientation.Vertical,
            draggableHandler = layoutImpl.verticalDraggableHandler,
            topOrLeftBehavior = topBehavior,
            bottomOrRightBehavior = bottomBehavior,
            isExternalOverscrollGesture = isExternalOverscrollGesture,
Loading