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

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

Merge "STL improve Swipe definition API 1/2" into main

parents edea2a4a a62c2873
Loading
Loading
Loading
Loading
+13 −26
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import com.android.compose.animation.scene.SceneKey
import com.android.compose.animation.scene.SceneScope
import com.android.compose.animation.scene.SceneTransitionLayout
import com.android.compose.animation.scene.Swipe
import com.android.compose.animation.scene.SwipeDirection
import com.android.compose.animation.scene.observableTransitionState
import com.android.compose.animation.scene.transitions
import com.android.systemui.communal.shared.model.CommunalBackgroundType
@@ -124,7 +123,7 @@ val sceneTransitions = transitions {
        }
        timestampRange(
            startMillis = TransitionDuration.EDIT_MODE_TO_HUB_GRID_DELAY_MS,
            endMillis = TransitionDuration.EDIT_MODE_TO_HUB_GRID_END_MS
            endMillis = TransitionDuration.EDIT_MODE_TO_HUB_GRID_END_MS,
        ) {
            fade(Communal.Elements.Grid)
        }
@@ -187,14 +186,13 @@ fun CommunalContainer(
    ) {
        scene(
            CommunalScenes.Blank,
            userActions =
                mapOf(Swipe(SwipeDirection.Start, fromSource = Edge.End) to CommunalScenes.Communal)
            userActions = mapOf(Swipe.Start(fromSource = Edge.End) to CommunalScenes.Communal),
        ) {
            // This scene shows nothing only allowing for transitions to the communal scene.
            Box(modifier = Modifier.fillMaxSize())
        }

        val userActions = mapOf(Swipe(SwipeDirection.End) to CommunalScenes.Blank)
        val userActions = mapOf(Swipe.End to CommunalScenes.Blank)

        scene(CommunalScenes.Communal, userActions = userActions) {
            CommunalScene(
@@ -257,13 +255,9 @@ fun SceneScope.CommunalScene(

/** Default background of the hub, a single color */
@Composable
private fun BoxScope.DefaultBackground(
    colors: CommunalColors,
) {
private fun BoxScope.DefaultBackground(colors: CommunalColors) {
    val backgroundColor by colors.backgroundColor.collectAsStateWithLifecycle()
    Box(
        modifier = Modifier.matchParentSize().background(Color(backgroundColor.toArgb())),
    )
    Box(modifier = Modifier.matchParentSize().background(Color(backgroundColor.toArgb())))
}

/** Experimental hub background, static linear gradient */
@@ -273,7 +267,7 @@ private fun BoxScope.StaticLinearGradient() {
    Box(
        Modifier.matchParentSize()
            .background(
                Brush.linearGradient(colors = listOf(colors.primary, colors.primaryContainer)),
                Brush.linearGradient(colors = listOf(colors.primary, colors.primaryContainer))
            )
    )
    BackgroundTopScrim()
@@ -288,7 +282,7 @@ private fun BoxScope.AnimatedLinearGradient() {
            .background(colors.primary)
            .animatedRadialGradientBackground(
                toColor = colors.primary,
                fromColor = colors.primaryContainer.copy(alpha = 0.6f)
                fromColor = colors.primaryContainer.copy(alpha = 0.6f),
            )
    )
    BackgroundTopScrim()
@@ -324,9 +318,9 @@ fun Modifier.animatedRadialGradientBackground(toColor: Color, fromColor: Color):
                            durationMillis = ANIMATION_DURATION_MS,
                            easing = CubicBezierEasing(0.33f, 0f, 0.67f, 1f),
                        ),
                    repeatMode = RepeatMode.Reverse
                    repeatMode = RepeatMode.Reverse,
                ),
            label = "radial gradient center fraction"
            label = "radial gradient center fraction",
        )

    // Offset to place the center of the gradients offscreen. This is applied to both the
@@ -337,16 +331,9 @@ fun Modifier.animatedRadialGradientBackground(toColor: Color, fromColor: Color):
        val gradientRadius = (size.width / 2) + offsetPx
        val totalHeight = size.height + 2 * offsetPx

        val leftCenter =
            Offset(
                x = -offsetPx,
                y = totalHeight * centerFraction - offsetPx,
            )
        val leftCenter = Offset(x = -offsetPx, y = totalHeight * centerFraction - offsetPx)
        val rightCenter =
            Offset(
                x = offsetPx + size.width,
                y = totalHeight * (1f - centerFraction) - offsetPx,
            )
            Offset(x = offsetPx + size.width, y = totalHeight * (1f - centerFraction) - offsetPx)

        // Right gradient
        drawCircle(
@@ -354,7 +341,7 @@ fun Modifier.animatedRadialGradientBackground(toColor: Color, fromColor: Color):
                Brush.radialGradient(
                    colors = listOf(fromColor, toColor),
                    center = rightCenter,
                    radius = gradientRadius
                    radius = gradientRadius,
                ),
            center = rightCenter,
            radius = gradientRadius,
@@ -367,7 +354,7 @@ fun Modifier.animatedRadialGradientBackground(toColor: Color, fromColor: Color):
                Brush.radialGradient(
                    colors = listOf(fromColor, toColor),
                    center = leftCenter,
                    radius = gradientRadius
                    radius = gradientRadius,
                ),
            center = leftCenter,
            radius = gradientRadius,
+38 −1
Original line number Diff line number Diff line
@@ -405,7 +405,8 @@ data object Back : UserAction() {
}

/** The user swiped on the container. */
data class Swipe(
data class Swipe
private constructor(
    val direction: SwipeDirection,
    val pointerCount: Int = 1,
    val pointersType: PointerType? = null,
@@ -418,6 +419,42 @@ data class Swipe(
        val Down = Swipe(SwipeDirection.Down)
        val Start = Swipe(SwipeDirection.Start)
        val End = Swipe(SwipeDirection.End)

        fun Left(
            pointerCount: Int = 1,
            pointersType: PointerType? = null,
            fromSource: SwipeSource? = null,
        ) = Swipe(SwipeDirection.Left, pointerCount, pointersType, fromSource)

        fun Up(
            pointerCount: Int = 1,
            pointersType: PointerType? = null,
            fromSource: SwipeSource? = null,
        ) = Swipe(SwipeDirection.Up, pointerCount, pointersType, fromSource)

        fun Right(
            pointerCount: Int = 1,
            pointersType: PointerType? = null,
            fromSource: SwipeSource? = null,
        ) = Swipe(SwipeDirection.Right, pointerCount, pointersType, fromSource)

        fun Down(
            pointerCount: Int = 1,
            pointersType: PointerType? = null,
            fromSource: SwipeSource? = null,
        ) = Swipe(SwipeDirection.Down, pointerCount, pointersType, fromSource)

        fun Start(
            pointerCount: Int = 1,
            pointersType: PointerType? = null,
            fromSource: SwipeSource? = null,
        ) = Swipe(SwipeDirection.Start, pointerCount, pointersType, fromSource)

        fun End(
            pointerCount: Int = 1,
            pointersType: PointerType? = null,
            fromSource: SwipeSource? = null,
        ) = Swipe(SwipeDirection.End, pointerCount, pointersType, fromSource)
    }

    override fun resolve(layoutDirection: LayoutDirection): UserAction.Resolved {
+2 −5
Original line number Diff line number Diff line
@@ -101,10 +101,7 @@ class DraggableHandlerTest {
            scene(
                key = SceneC,
                userActions =
                    mapOf(
                        Swipe.Up to SceneB,
                        Swipe(SwipeDirection.Up, fromSource = Edge.Bottom) to SceneA,
                    ),
                    mapOf(Swipe.Up to SceneB, Swipe.Up(fromSource = Edge.Bottom) to SceneA),
            ) {
                Text("SceneC")
            }
@@ -1231,7 +1228,7 @@ class DraggableHandlerTest {
        assertTransition(
            currentScene = SceneC,
            fromScene = SceneC,
            // userAction: Swipe(SwipeDirection.Up, fromSource = Edge.Bottom) to SceneA
            // userAction: Swipe.Up(fromSource = Edge.Bottom) to SceneA
            toScene = SceneA,
            progress = 0.1f,
        )
+1 −4
Original line number Diff line number Diff line
@@ -869,10 +869,7 @@ class ElementTest {
                state = state,
                modifier = Modifier.size(layoutWidth, layoutHeight),
            ) {
                scene(
                    SceneA,
                    userActions = mapOf(Swipe(SwipeDirection.Down, pointerCount = 2) to SceneB),
                ) {
                scene(SceneA, userActions = mapOf(Swipe.Down(pointerCount = 2) to SceneB)) {
                    Box(
                        Modifier
                            // A scrollable that does not consume the scroll gesture
+4 −4
Original line number Diff line number Diff line
@@ -128,10 +128,10 @@ class SwipeToSceneTest {
                    if (swipesEnabled())
                        mapOf(
                            Swipe.Down to SceneA,
                            Swipe(SwipeDirection.Down, pointerCount = 2) to SceneB,
                            Swipe(SwipeDirection.Down, pointersType = PointerType.Mouse) to SceneD,
                            Swipe(SwipeDirection.Right, fromSource = Edge.Left) to SceneB,
                            Swipe(SwipeDirection.Down, fromSource = Edge.Top) to SceneB,
                            Swipe.Down(pointerCount = 2) to SceneB,
                            Swipe.Down(pointersType = PointerType.Mouse) to SceneD,
                            Swipe.Down(fromSource = Edge.Top) to SceneB,
                            Swipe.Right(fromSource = Edge.Left) to SceneB,
                        )
                    else emptyMap(),
            ) {
Loading