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

Commit da8d6bb9 authored by omarmt's avatar omarmt
Browse files

STL remove Overscroll DSL [1/2]

New behavior: progress is always in [0, 1]

Typically, a transaction's value falls between 0 and 1. However, if a
transition or animation needs to go beyond these limits, the extra value
or speed is passed on to the OverscrollEffect or the parent elements in
the SceneTransitionLayout.

Test: atest DraggableHandlerTest
Test: atest ElementTest
Test: atest NestedScrollToSceneTest
Test: atest SwipeToSceneTest
Bug: 378470603
Flag: com.android.systemui.scene_container
Change-Id: Ic1b77b99fb7ff3af8085d3d7a67a07bacefd0c7c
parent b353840b
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.focusable
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
@@ -128,9 +127,6 @@ val sceneTransitions = transitions {
            fade(Communal.Elements.Grid)
        }
    }
    // Disable horizontal overscroll. If the scene is overscrolled too soon after showing, this
    // can lead to inconsistent KeyguardState changes.
    overscrollDisabled(CommunalScenes.Communal, Orientation.Horizontal)
}

/**
+0 −10
Original line number Diff line number Diff line
package com.android.systemui.scene.ui.composable

import androidx.compose.animation.core.spring
import androidx.compose.foundation.gestures.Orientation
import com.android.compose.animation.scene.ProgressConverter
import com.android.compose.animation.scene.TransitionKey
import com.android.compose.animation.scene.transitions
@@ -131,13 +130,4 @@ val SceneContainerTransitions = transitions {
    from(Scenes.Lockscreen, to = Overlays.QuickSettingsShade, key = SlightlyFasterShadeCollapse) {
        toQuickSettingsShadeTransition(durationScale = 0.9)
    }

    // Scene overscroll
    // TODO(b/382477212) Remove STL Overscroll DSL
    overscrollDisabled(Scenes.Gone, Orientation.Vertical)
    overscrollDisabled(Scenes.Lockscreen, Orientation.Vertical)
    overscrollDisabled(Scenes.Bouncer, Orientation.Vertical)
    overscrollDisabled(Scenes.Shade, Orientation.Vertical)
    overscrollDisabled(Overlays.NotificationsShade, Orientation.Vertical)
    overscrollDisabled(Overlays.QuickSettingsShade, Orientation.Vertical)
}
+4 −8
Original line number Diff line number Diff line
@@ -418,15 +418,11 @@ private class AnimatedStateImpl<T, Delta>(
            return fromValue
        }

        val overscrollSpec = transition.currentOverscrollSpec
        val progress =
            when {
                overscrollSpec == null -> {
                    if (canOverflow) transition.progress
                    else transition.progress.fastCoerceIn(0f, 1f)
                }
                overscrollSpec.content == transition.toContent -> 1f
                else -> 0f
            if (canOverflow) {
                transition.progress
            } else {
                transition.progress.fastCoerceIn(0f, 1f)
            }

        return sharedValue.type.lerp(fromValue, toValue, progress)
+0 −53
Original line number Diff line number Diff line
@@ -20,9 +20,7 @@ import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.Easing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.SpringSpec
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.android.compose.animation.scene.content.state.TransitionState
@@ -103,28 +101,6 @@ interface SceneTransitionsBuilder {
        reversePreview: (TransitionBuilder.() -> Unit)? = null,
        builder: TransitionBuilder.() -> Unit = {},
    )

    /**
     * Define the animation to be played when the [content] is overscrolled in the given
     * [orientation].
     *
     * The overscroll animation always starts from a progress of 0f, and reaches 1f when moving the
     * [distance] down/right, -1f when moving in the opposite direction.
     */
    @Deprecated(
        "Use verticalOverscrollEffect (or horizontalOverscrollEffect) directly from SceneScope."
    )
    fun overscroll(
        content: ContentKey,
        orientation: Orientation,
        builder: OverscrollBuilder.() -> Unit,
    )

    /**
     * Prevents overscroll the [content] in the given [orientation], allowing ancestors to
     * eventually consume the remaining gesture.
     */
    fun overscrollDisabled(content: ContentKey, orientation: Orientation)
}

interface BaseTransitionBuilder : PropertyTransformationBuilder {
@@ -228,35 +204,6 @@ interface TransitionBuilder : BaseTransitionBuilder {
    fun reversed(builder: TransitionBuilder.() -> Unit)
}

@TransitionDsl
interface OverscrollBuilder : BaseTransitionBuilder {
    /**
     * Function that takes a linear overscroll progress value ranging from 0 to +/- infinity and
     * outputs the desired **overscroll progress value**.
     *
     * When the progress value is:
     * - 0, the user is not overscrolling.
     * - 1, the user overscrolled by exactly the [distance].
     * - Greater than 1, the user overscrolled more than the [distance].
     */
    var progressConverter: ProgressConverter?

    /** Translate the element(s) matching [matcher] by ([x], [y]) pixels. */
    fun translate(
        matcher: ElementMatcher,
        x: OverscrollScope.() -> Float = { 0f },
        y: OverscrollScope.() -> Float = { 0f },
    )
}

interface OverscrollScope : Density {
    /**
     * Return the absolute distance between fromScene and toScene, if available, otherwise
     * [DistanceUnspecified].
     */
    val absoluteDistance: Float
}

/**
 * An interface to decide where we should draw shared Elements or compose MovableElements.
 *
+0 −54
Original line number Diff line number Diff line
@@ -22,9 +22,7 @@ import androidx.compose.animation.core.Easing
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.SpringSpec
import androidx.compose.animation.core.VectorConverter
import androidx.compose.animation.core.snap
import androidx.compose.animation.core.spring
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.unit.Dp
import com.android.compose.animation.scene.content.state.TransitionState
@@ -33,7 +31,6 @@ import com.android.compose.animation.scene.transformation.AnchoredTranslate
import com.android.compose.animation.scene.transformation.DrawScale
import com.android.compose.animation.scene.transformation.EdgeTranslate
import com.android.compose.animation.scene.transformation.Fade
import com.android.compose.animation.scene.transformation.OverscrollTranslate
import com.android.compose.animation.scene.transformation.ScaleSize
import com.android.compose.animation.scene.transformation.SharedElementTransformation
import com.android.compose.animation.scene.transformation.Transformation
@@ -81,45 +78,6 @@ private class SceneTransitionsBuilderImpl : SceneTransitionsBuilder {
        transition(from = from, to = to, key = key, preview, reversePreview, builder)
    }

    override fun overscroll(
        content: ContentKey,
        orientation: Orientation,
        builder: OverscrollBuilder.() -> Unit,
    ) {
        val impl = OverscrollBuilderImpl().apply(builder)
        check(impl.transformationMatchers.isNotEmpty()) {
            "This method does not allow empty transformations. " +
                "Use overscrollDisabled($content, $orientation) instead."
        }
        overscrollSpec(content, orientation, impl)
    }

    override fun overscrollDisabled(content: ContentKey, orientation: Orientation) {
        overscrollSpec(content, orientation, OverscrollBuilderImpl())
    }

    private fun overscrollSpec(
        content: ContentKey,
        orientation: Orientation,
        impl: OverscrollBuilderImpl,
    ): OverscrollSpec {
        val spec =
            OverscrollSpecImpl(
                content = content,
                orientation = orientation,
                transformationSpec =
                    TransformationSpecImpl(
                        progressSpec = snap(),
                        swipeSpec = null,
                        distance = impl.distance,
                        transformationMatchers = impl.transformationMatchers,
                    ),
                progressConverter = impl.progressConverter,
            )
        transitionOverscrollSpecs.add(spec)
        return spec
    }

    private fun transition(
        from: ContentKey?,
        to: ContentKey?,
@@ -295,15 +253,3 @@ internal class TransitionBuilderImpl(override val transition: TransitionState.Tr
        fractionRange(start, end, easing, builder)
    }
}

internal open class OverscrollBuilderImpl : BaseTransitionBuilderImpl(), OverscrollBuilder {
    override var progressConverter: ProgressConverter? = null

    override fun translate(
        matcher: ElementMatcher,
        x: OverscrollScope.() -> Float,
        y: OverscrollScope.() -> Float,
    ) {
        addTransformation(matcher, OverscrollTranslate.Factory(x, y))
    }
}
Loading