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

Commit 0a8d9937 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Android (Google) Code Review
Browse files

Merge "STL remove Overscroll DSL implementation 1/2" into main

parents 81a64690 5d7eaaa6
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
package com.android.systemui.scene.ui.composable

import androidx.compose.animation.core.spring
import com.android.compose.animation.scene.ProgressConverter
import com.android.compose.animation.scene.TransitionKey
import com.android.compose.animation.scene.transitions
import com.android.systemui.notifications.ui.composable.Notifications
@@ -49,7 +48,6 @@ val SceneContainerTransitions = transitions {
    interruptionHandler = SceneContainerInterruptionHandler

    // Overscroll progress starts linearly with some resistance (3f) and slowly approaches 0.2f
    defaultOverscrollProgressConverter = ProgressConverter.tanh(maxProgress = 0.2f, tilt = 3f)
    defaultSwipeSpec = spring(stiffness = 300f, dampingRatio = 0.8f, visibilityThreshold = 0.5f)

    // Scene transitions
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.round
import androidx.compose.ui.util.fastCoerceIn
import com.android.compose.animation.scene.content.Content
import com.android.compose.animation.scene.content.state.TransitionState.DirectionProperties.Companion.DistanceUnspecified
import com.android.compose.animation.scene.content.state.TransitionState.Companion.DistanceUnspecified
import com.android.compose.nestedscroll.OnStopScope
import com.android.compose.nestedscroll.PriorityNestedScrollConnection
import com.android.compose.nestedscroll.ScrollController
+0 −73
Original line number Diff line number Diff line
@@ -388,32 +388,6 @@ internal class ElementNode(

        val transition = elementState as? TransitionState.Transition

        // If this element is not supposed to be laid out now, either because it is not part of any
        // ongoing transition or the other content of its transition is overscrolling, then lay out
        // the element normally and don't place it.
        val overscrollContent = transition?.currentOverscrollSpec?.content
        if (overscrollContent != null && overscrollContent != content.key) {
            when (transition) {
                is TransitionState.Transition.ChangeScene ->
                    return doNotPlace(measurable, constraints)

                // If we are overscrolling an overlay that does not contain an element that is in
                // the current scene, place it in that scene otherwise the element won't be placed
                // at all.
                is TransitionState.Transition.ShowOrHideOverlay,
                is TransitionState.Transition.ReplaceOverlay -> {
                    if (
                        content.key == transition.currentScene &&
                            overscrollContent !in element.stateByContent
                    ) {
                        return placeNormally(measurable, constraints)
                    } else {
                        return doNotPlace(measurable, constraints)
                    }
                }
            }
        }

        val placeable =
            measure(layoutImpl, element, transition, stateInContent, measurable, constraints)
        stateInContent.lastSize = placeable.size()
@@ -1257,53 +1231,6 @@ private inline fun <T> computeValue(
    }

    val currentContent = currentContentState.content
    if (transition is TransitionState.DirectionProperties) {
        val overscroll = transition.currentOverscrollSpec
        if (overscroll?.content == currentContent) {
            val elementSpec =
                overscroll.transformationSpec.transformations(element.key, currentContent)
            val propertySpec = transformation(elementSpec) ?: return currentValue()
            val overscrollState =
                checkNotNull(if (currentContent == toContent) toState else fromState)
            val idleValue = contentValue(overscrollState)
            val targetValue =
                with(
                    propertySpec.transformation.requireInterpolatedTransformation(
                        element,
                        transition,
                    ) {
                        "Custom transformations in overscroll specs should not be possible"
                    }
                ) {
                    layoutImpl.propertyTransformationScope.transform(
                        currentContent,
                        element.key,
                        transition,
                        idleValue,
                    )
                }

            // Make sure we don't read progress if values are the same and we don't need to
            // interpolate, so we don't invalidate the phase where this is read.
            if (targetValue == idleValue) {
                return targetValue
            }

            // TODO(b/290184746): Make sure that we don't overflow transformations associated to a
            // range.
            val directionSign = if (transition.isUpOrLeft) -1 else 1
            val isToContent = overscroll.content == transition.toContent
            val linearProgress = transition.progress.let { if (isToContent) it - 1f else it }
            val progressConverter =
                overscroll.progressConverter
                    ?: layoutImpl.state.transitions.defaultProgressConverter
            val progress = directionSign * progressConverter.convert(linearProgress)
            val rangeProgress = propertySpec.range?.progress(progress) ?: progress

            // Interpolate between the value at rest and the over scrolled value.
            return lerp(idleValue, targetValue, rangeProgress)
        }
    }

    // The element is shared: interpolate between the value in fromContent and the value in
    // toContent.
+1 −26
Original line number Diff line number Diff line
@@ -196,13 +196,7 @@ private fun shouldComposeMovableElement(
        is TransitionState.Transition -> {
            // During transitions, always compose movable elements in the scene picked by their
            // content picker.
            shouldComposeMoveableElement(
                layoutImpl,
                content,
                element,
                elementState,
                element.contentPicker.contents,
            )
            shouldComposeMoveableElement(layoutImpl, content, element, elementState)
        }
    }
}
@@ -212,26 +206,7 @@ private fun shouldComposeMoveableElement(
    content: ContentKey,
    elementKey: ElementKey,
    transition: TransitionState.Transition,
    containingContents: Set<ContentKey>,
): Boolean {
    val overscrollContent = transition.currentOverscrollSpec?.content
    if (overscrollContent != null) {
        return when (transition) {
            // If we are overscrolling between scenes, only place/compose the element in the
            // overscrolling scene.
            is TransitionState.Transition.ChangeScene -> content == overscrollContent

            // If we are overscrolling an overlay, place/compose the element if [content] is the
            // overscrolling content or if [content] is the current scene and the overscrolling
            // overlay does not contain the element.
            is TransitionState.Transition.ReplaceOverlay,
            is TransitionState.Transition.ShowOrHideOverlay ->
                content == overscrollContent ||
                    (content == transition.currentScene &&
                        !containingContents.contains(overscrollContent))
        }
    }

    val scenePicker = elementKey.contentPicker
    val pickedScene =
        scenePicker.contentDuringTransition(
+1 −9
Original line number Diff line number Diff line
@@ -558,15 +558,7 @@ private class LayoutNode(var layoutImpl: SceneTransitionLayoutImpl) :
                width = fromSize.width
                height = fromSize.height
            } else {
                val overscrollSpec = transition.currentOverscrollSpec
                val progress =
                    when {
                        overscrollSpec == null -> transition.progress
                        overscrollSpec.content == transition.toScene -> 1f
                        else -> 0f
                    }

                val size = lerp(fromSize, toSize, progress)
                val size = lerp(fromSize, toSize, transition.progress)
                width = size.width.coerceAtLeast(0)
                height = size.height.coerceAtLeast(0)
            }
Loading