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

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

Merge changes from topic "stl_remove_overscrolldsl" into main

* changes:
  STL remove unused symbols in SwipeAnimation
  STL remove Overscroll DSL [1/2]
parents 5f12aedf 752e6267
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
@@ -126,13 +125,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)
+17 −81
Original line number Diff line number Diff line
@@ -116,7 +116,6 @@ private fun createSwipeAnimation(
            val fromScene = layoutState.currentScene
            val toScene = result.toScene
            ChangeSceneSwipeTransition(
                    layoutState = layoutState,
                swipeAnimation = swipeAnimation(fromContent = fromScene, toContent = toScene),
                key = result.transitionKey,
                replacedTransition = null,
@@ -127,10 +126,9 @@ private fun createSwipeAnimation(
            val fromScene = layoutState.currentScene
            val overlay = result.overlay
            ShowOrHideOverlaySwipeTransition(
                    layoutState = layoutState,
                    fromOrToScene = fromScene,
                    overlay = overlay,
                swipeAnimation = swipeAnimation(fromContent = fromScene, toContent = overlay),
                overlay = overlay,
                fromOrToScene = fromScene,
                key = result.transitionKey,
                replacedTransition = null,
                )
@@ -140,10 +138,9 @@ private fun createSwipeAnimation(
            val toScene = layoutState.currentScene
            val overlay = result.overlay
            ShowOrHideOverlaySwipeTransition(
                    layoutState = layoutState,
                    fromOrToScene = toScene,
                    overlay = overlay,
                swipeAnimation = swipeAnimation(fromContent = overlay, toContent = toScene),
                overlay = overlay,
                fromOrToScene = toScene,
                key = result.transitionKey,
                replacedTransition = null,
                )
@@ -159,7 +156,6 @@ private fun createSwipeAnimation(

            val toOverlay = result.overlay
            ReplaceOverlaySwipeTransition(
                    layoutState = layoutState,
                swipeAnimation =
                    swipeAnimation(fromContent = fromOverlay, toContent = toOverlay),
                key = result.transitionKey,
@@ -170,22 +166,6 @@ private fun createSwipeAnimation(
    }
}

internal fun createSwipeAnimation(old: SwipeAnimation<*>): SwipeAnimation<*> {
    return when (val transition = old.contentTransition) {
        is TransitionState.Transition.ChangeScene -> {
            ChangeSceneSwipeTransition(transition as ChangeSceneSwipeTransition).swipeAnimation
        }
        is TransitionState.Transition.ShowOrHideOverlay -> {
            ShowOrHideOverlaySwipeTransition(transition as ShowOrHideOverlaySwipeTransition)
                .swipeAnimation
        }
        is TransitionState.Transition.ReplaceOverlay -> {
            ReplaceOverlaySwipeTransition(transition as ReplaceOverlaySwipeTransition)
                .swipeAnimation
        }
    }
}

/** A helper class that contains the main logic for swipe transitions. */
internal class SwipeAnimation<T : ContentKey>(
    val layoutState: MutableSceneTransitionLayoutStateImpl,
@@ -279,20 +259,6 @@ internal class SwipeAnimation<T : ContentKey>(
    override val absoluteDistance: Float
        get() = distance().absoluteValue

    constructor(
        other: SwipeAnimation<T>
    ) : this(
        layoutState = other.layoutState,
        fromContent = other.fromContent,
        toContent = other.toContent,
        orientation = other.orientation,
        isUpOrLeft = other.isUpOrLeft,
        requiresFullDistanceSwipe = other.requiresFullDistanceSwipe,
        distance = other.distance,
        currentContent = other.currentContent,
        dragOffset = other.offsetAnimation?.value ?: other.dragOffset,
    )

    suspend fun run() {
        // This animation will first be driven by finger, then when the user lift their finger we
        // start an animation to the target offset (progress = 1f or progress = 0f). We await() for
@@ -514,7 +480,6 @@ private object DefaultSwipeDistance : UserActionDistance {
}

private class ChangeSceneSwipeTransition(
    val layoutState: MutableSceneTransitionLayoutStateImpl,
    val swipeAnimation: SwipeAnimation<SceneKey>,
    override val key: TransitionKey?,
    replacedTransition: ChangeSceneSwipeTransition?,
@@ -526,15 +491,6 @@ private class ChangeSceneSwipeTransition(
    ),
    TransitionState.DirectionProperties by swipeAnimation {

    constructor(
        other: ChangeSceneSwipeTransition
    ) : this(
        layoutState = other.layoutState,
        swipeAnimation = SwipeAnimation(other.swipeAnimation),
        key = other.key,
        replacedTransition = other,
    )

    init {
        swipeAnimation.contentTransition = this
    }
@@ -572,7 +528,6 @@ private class ChangeSceneSwipeTransition(
}

private class ShowOrHideOverlaySwipeTransition(
    val layoutState: MutableSceneTransitionLayoutStateImpl,
    val swipeAnimation: SwipeAnimation<ContentKey>,
    overlay: OverlayKey,
    fromOrToScene: SceneKey,
@@ -587,16 +542,6 @@ private class ShowOrHideOverlaySwipeTransition(
        replacedTransition,
    ),
    TransitionState.DirectionProperties by swipeAnimation {
    constructor(
        other: ShowOrHideOverlaySwipeTransition
    ) : this(
        layoutState = other.layoutState,
        swipeAnimation = SwipeAnimation(other.swipeAnimation),
        overlay = other.overlay,
        fromOrToScene = other.fromOrToScene,
        key = other.key,
        replacedTransition = other,
    )

    init {
        swipeAnimation.contentTransition = this
@@ -635,7 +580,6 @@ private class ShowOrHideOverlaySwipeTransition(
}

private class ReplaceOverlaySwipeTransition(
    val layoutState: MutableSceneTransitionLayoutStateImpl,
    val swipeAnimation: SwipeAnimation<OverlayKey>,
    override val key: TransitionKey?,
    replacedTransition: ReplaceOverlaySwipeTransition?,
@@ -646,14 +590,6 @@ private class ReplaceOverlaySwipeTransition(
        replacedTransition,
    ),
    TransitionState.DirectionProperties by swipeAnimation {
    constructor(
        other: ReplaceOverlaySwipeTransition
    ) : this(
        layoutState = other.layoutState,
        swipeAnimation = SwipeAnimation(other.swipeAnimation),
        key = other.key,
        replacedTransition = other,
    )

    init {
        swipeAnimation.contentTransition = this
+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.
 *
Loading