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

Commit c11cd39e authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Run ktfmt on packages/SystemUI/compose/scene/

Bug: 353679003
Test: N/A
Flag: EXEMPT pure code formatting
Change-Id: I7c1108b09de8f5f4679c92ac5216a7645d1a154c
parent 578a40d1
Loading
Loading
Loading
Loading
+4 −12
Original line number Diff line number Diff line
@@ -53,12 +53,7 @@ import org.junit.runner.RunWith
class AnimatedSharedAsStateTest {
    @get:Rule val rule = createComposeRule()

    private data class Values(
        val int: Int,
        val float: Float,
        val dp: Dp,
        val color: Color,
    )
    private data class Values(val int: Int, val float: Float, val dp: Dp, val color: Color)

    private fun lerp(start: Values, stop: Values, fraction: Float): Values {
        return Values(
@@ -70,10 +65,7 @@ class AnimatedSharedAsStateTest {
    }

    @Composable
    private fun ContentScope.Foo(
        targetValues: Values,
        onCurrentValueChanged: (Values) -> Unit,
    ) {
    private fun ContentScope.Foo(targetValues: Values, onCurrentValueChanged: (Values) -> Unit) {
        val key = TestElements.Foo
        Element(key, Modifier) {
            val int by animateElementIntAsState(targetValues.int, key = TestValues.Value1)
@@ -245,7 +237,7 @@ class AnimatedSharedAsStateTest {
            fromSceneContent = {
                SceneValues(
                    targetValues = fromValues,
                    onCurrentValueChanged = { lastValueInFrom = it }
                    onCurrentValueChanged = { lastValueInFrom = it },
                )
            },
            toSceneContent = {
@@ -457,7 +449,7 @@ class AnimatedSharedAsStateTest {
            rule.runOnUiThread {
                MutableSceneTransitionLayoutStateImpl(
                    SceneA,
                    transitions { overscrollDisabled(SceneB, Orientation.Horizontal) }
                    transitions { overscrollDisabled(SceneB, Orientation.Horizontal) },
                )
            }

+35 −56
Original line number Diff line number Diff line
@@ -53,9 +53,7 @@ private val LAYOUT_SIZE = IntSize(SCREEN_SIZE.toInt(), SCREEN_SIZE.toInt())

@RunWith(AndroidJUnit4::class)
class DraggableHandlerTest {
    private class TestGestureScope(
        val testScope: MonotonicClockTestScope,
    ) {
    private class TestGestureScope(val testScope: MonotonicClockTestScope) {
        var canChangeScene: (SceneKey) -> Boolean = { true }
        val layoutState =
            MutableSceneTransitionLayoutStateImpl(
@@ -83,24 +81,14 @@ class DraggableHandlerTest {
            }

        private val scenesBuilder: SceneTransitionLayoutScope.() -> Unit = {
            scene(
                key = SceneA,
                userActions = mutableUserActionsA,
            ) {
                Text("SceneA")
            }
            scene(
                key = SceneB,
                userActions = mutableUserActionsB,
            ) {
                Text("SceneB")
            }
            scene(key = SceneA, userActions = mutableUserActionsA) { Text("SceneA") }
            scene(key = SceneB, userActions = mutableUserActionsB) { Text("SceneB") }
            scene(
                key = SceneC,
                userActions =
                    mapOf(
                        Swipe.Up to SceneB,
                        Swipe(SwipeDirection.Up, fromSource = Edge.Bottom) to SceneA
                        Swipe(SwipeDirection.Up, fromSource = Edge.Bottom) to SceneA,
                    ),
            ) {
                Text("SceneC")
@@ -110,16 +98,12 @@ class DraggableHandlerTest {
                userActions =
                    mapOf(
                        Swipe.Up to UserActionResult.HideOverlay(OverlayA),
                        Swipe.Down to UserActionResult.ReplaceByOverlay(OverlayB)
                        Swipe.Down to UserActionResult.ReplaceByOverlay(OverlayB),
                    ),
            ) {
                Text("OverlayA")
            }
            overlay(
                key = OverlayB,
            ) {
                Text("OverlayB")
            }
            overlay(key = OverlayB) { Text("OverlayB") }
        }

        val transitionInterceptionThreshold = 0.05f
@@ -144,7 +128,7 @@ class DraggableHandlerTest {

        fun nestedScrollConnection(
            nestedScrollBehavior: NestedScrollBehavior,
            isExternalOverscrollGesture: Boolean = false
            isExternalOverscrollGesture: Boolean = false,
        ) =
            NestedScrollHandlerImpl(
                    layoutImpl = layoutImpl,
@@ -154,7 +138,7 @@ class DraggableHandlerTest {
                    isExternalOverscrollGesture = { isExternalOverscrollGesture },
                    pointersInfoOwner = {
                        PointersInfo(startedPosition = Offset.Zero, pointersDown = 1)
                    }
                    },
                )
                .connection

@@ -202,7 +186,7 @@ class DraggableHandlerTest {
            progress: Float? = null,
            previewProgress: Float? = null,
            isInPreviewStage: Boolean? = null,
            isUserInputOngoing: Boolean? = null
            isUserInputOngoing: Boolean? = null,
        ): Transition {
            val transition = assertThat(transitionState).isSceneTransition()
            currentScene?.let { assertThat(transition).hasCurrentScene(it) }
@@ -269,7 +253,7 @@ class DraggableHandlerTest {
        fun DragController.onDragStopped(
            velocity: Float,
            canChangeScene: Boolean = true,
            expectedConsumed: Boolean = true
            expectedConsumed: Boolean = true,
        ) {
            val consumed = onStop(velocity, canChangeScene)
            assertThat(consumed).isEqualTo(if (expectedConsumed) velocity else 0f)
@@ -280,16 +264,13 @@ class DraggableHandlerTest {
            consumedByScroll: Offset = Offset.Zero,
        ) {
            val consumedByPreScroll =
                onPreScroll(
                    available = available,
                    source = NestedScrollSource.Drag,
                )
                onPreScroll(available = available, source = NestedScrollSource.Drag)
            val consumed = consumedByPreScroll + consumedByScroll

            onPostScroll(
                consumed = consumed,
                available = available - consumed,
                source = NestedScrollSource.Drag
                source = NestedScrollSource.Drag,
            )
        }

@@ -376,7 +357,7 @@ class DraggableHandlerTest {
                currentScene = SceneA,
                isInPreviewStage = true,
                previewProgress = 0.1f,
                progress = 0f
                progress = 0f,
            )

            // wait for the stop animation
@@ -415,7 +396,7 @@ class DraggableHandlerTest {
            currentScene = SceneA,
            fromScene = SceneA,
            toScene = SceneB,
            progress = 0.6f
            progress = 0.6f,
        )

        // Reverse direction such that A -> C now with 0.4
@@ -424,7 +405,7 @@ class DraggableHandlerTest {
            currentScene = SceneA,
            fromScene = SceneA,
            toScene = SceneC,
            progress = 0.4f
            progress = 0.4f,
        )

        // After the drag stopped scene C should be committed
@@ -463,7 +444,7 @@ class DraggableHandlerTest {
            currentScene = SceneC,
            fromScene = SceneC,
            toScene = SceneB,
            progress = -0.1f
            progress = -0.1f,
        )

        // Reverse drag direction, it will consume the previous drag
@@ -472,7 +453,7 @@ class DraggableHandlerTest {
            currentScene = SceneC,
            fromScene = SceneC,
            toScene = SceneB,
            progress = 0.0f
            progress = 0.0f,
        )

        // Continue reverse drag direction, it should record progress to Scene B
@@ -481,7 +462,7 @@ class DraggableHandlerTest {
            currentScene = SceneC,
            fromScene = SceneC,
            toScene = SceneB,
            progress = 0.1f
            progress = 0.1f,
        )
    }

@@ -492,13 +473,13 @@ class DraggableHandlerTest {
        // Start dragging from the bottom
        onDragStarted(
            startedPosition = Offset(SCREEN_SIZE * 0.5f, SCREEN_SIZE),
            overSlop = up(fractionOfScreen = 0.1f)
            overSlop = up(fractionOfScreen = 0.1f),
        )
        assertTransition(
            currentScene = SceneC,
            fromScene = SceneC,
            toScene = SceneA,
            progress = 0.1f
            progress = 0.1f,
        )
    }

@@ -509,14 +490,14 @@ class DraggableHandlerTest {
            currentScene = SceneA,
            fromScene = SceneA,
            toScene = SceneC,
            progress = 0.3f
            progress = 0.3f,
        )
        dragController.onDragDelta(pixels = up(fractionOfScreen = 0.3f))
        assertTransition(
            currentScene = SceneA,
            fromScene = SceneA,
            toScene = SceneC,
            progress = 0.0f
            progress = 0.0f,
        )
    }

@@ -537,7 +518,7 @@ class DraggableHandlerTest {
            currentScene = SceneA,
            fromScene = SceneA,
            toScene = SceneB,
            progress = 0.2f
            progress = 0.2f,
        )

        // Start animation A -> B with progress 0.2 -> 1.0
@@ -552,7 +533,7 @@ class DraggableHandlerTest {
            currentScene = SceneB,
            fromScene = SceneB,
            toScene = SceneC,
            progress = 0.2f
            progress = 0.2f,
        )

        // After the drag stopped scene C should be committed
@@ -646,7 +627,7 @@ class DraggableHandlerTest {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
        nestedScroll.onPreScroll(
            available = downOffset(fractionOfScreen = 0.1f),
            source = NestedScrollSource.Drag
            source = NestedScrollSource.Drag,
        )
        assertIdle(currentScene = SceneA)
    }
@@ -658,7 +639,7 @@ class DraggableHandlerTest {
            nestedScroll.onPostScroll(
                consumed = Offset.Zero,
                available = Offset.Zero,
                source = NestedScrollSource.Drag
                source = NestedScrollSource.Drag,
            )

        assertIdle(currentScene = SceneA)
@@ -672,7 +653,7 @@ class DraggableHandlerTest {
            nestedScroll.onPostScroll(
                consumed = Offset.Zero,
                available = downOffset(fractionOfScreen = 0.1f),
                source = NestedScrollSource.Drag
                source = NestedScrollSource.Drag,
            )

        assertTransition(currentScene = SceneA)
@@ -692,7 +673,7 @@ class DraggableHandlerTest {
        val consumed =
            nestedScroll.onPreScroll(
                available = downOffset(fractionOfScreen = 0.1f),
                source = NestedScrollSource.Drag
                source = NestedScrollSource.Drag,
            )
        assertThat(progress).isEqualTo(0.2f)

@@ -700,7 +681,7 @@ class DraggableHandlerTest {
        nestedScroll.onPostScroll(
            consumed = consumed,
            available = Offset.Zero,
            source = NestedScrollSource.Drag
            source = NestedScrollSource.Drag,
        )
        assertThat(progress).isEqualTo(0.2f)

@@ -711,7 +692,7 @@ class DraggableHandlerTest {

    private fun TestGestureScope.preScrollAfterSceneTransition(
        firstScroll: Float,
        secondScroll: Float
        secondScroll: Float,
    ) {
        val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview)
        // start scene transition
@@ -723,7 +704,7 @@ class DraggableHandlerTest {
        // a pre scroll event, that could be intercepted by DraggableHandlerImpl
        nestedScroll.onPreScroll(
            available = Offset(0f, secondScroll),
            source = NestedScrollSource.Drag
            source = NestedScrollSource.Drag,
        )
    }

@@ -835,7 +816,7 @@ class DraggableHandlerTest {
        // scroll consumed in child
        nestedScroll.scroll(
            available = downOffset(fractionOfScreen = 0.1f),
            consumedByScroll = downOffset(fractionOfScreen = 0.1f)
            consumedByScroll = downOffset(fractionOfScreen = 0.1f),
        )

        // scroll offsetY10 is all available for parents
@@ -879,13 +860,11 @@ class DraggableHandlerTest {
        val nestedScroll =
            nestedScrollConnection(
                nestedScrollBehavior = EdgeWithPreview,
                isExternalOverscrollGesture = true
                isExternalOverscrollGesture = true,
            )

        // scroll not consumed in child
        nestedScroll.scroll(
            available = downOffset(fractionOfScreen = 0.1f),
        )
        nestedScroll.scroll(available = downOffset(fractionOfScreen = 0.1f))

        // scroll offsetY10 is all available for parents
        nestedScroll.scroll(available = downOffset(fractionOfScreen = 0.1f))
@@ -1015,7 +994,7 @@ class DraggableHandlerTest {

        layoutState.startTransitionImmediately(
            animationScope = testScope.backgroundScope,
            transition(SceneA, SceneB)
            transition(SceneA, SceneB),
        )
        assertThat(draggableHandler.shouldImmediatelyIntercept(startedPosition = null)).isFalse()
    }
+29 −36
Original line number Diff line number Diff line
@@ -229,11 +229,7 @@ class ElementTest {
                    scene(SceneA) {
                        Box(Modifier.size(layoutSize)) {
                            // Transformed element
                            Element(
                                TestElements.Bar,
                                elementSize,
                                elementOffset,
                            )
                            Element(TestElements.Bar, elementSize, elementOffset)
                        }
                    }
                    scene(SceneB) { Box(Modifier.size(layoutSize)) }
@@ -534,10 +530,7 @@ class ElementTest {
                scene(SceneA) {
                    // The pages are full-size and beyondBoundsPageCount is 0, so at rest only one
                    // page should be composed.
                    HorizontalPager(
                        pagerState,
                        beyondViewportPageCount = 0,
                    ) { page ->
                    HorizontalPager(pagerState, beyondViewportPageCount = 0) { page ->
                        when (page) {
                            0 -> Box(Modifier.element(TestElements.Foo).fillMaxSize())
                            1 -> Box(Modifier.fillMaxSize())
@@ -606,7 +599,7 @@ class ElementTest {
                scaleSize(TestElements.Foo, width = 2f, height = 0.5f)
                translate(TestElements.Foo, x = 10.dp, y = 10.dp)
                fade(TestElements.Foo)
            }
            },
        ) {
            before { assertThat(fooCompositions).isEqualTo(1) }
            at(16) { assertThat(fooCompositions).isEqualTo(1) }
@@ -627,7 +620,7 @@ class ElementTest {
                        from(SceneA, to = SceneB) {
                            scaleSize(TestElements.Foo, width = 2f, height = 2f)
                        }
                    }
                    },
                )
            }

@@ -676,13 +669,13 @@ class ElementTest {
            touchSlop = LocalViewConfiguration.current.touchSlop
            SceneTransitionLayout(
                state = state,
                modifier = Modifier.size(layoutWidth, layoutHeight)
                modifier = Modifier.size(layoutWidth, layoutHeight),
            ) {
                scene(key = SceneA, userActions = mapOf(Swipe.Down to SceneB)) {
                    animateContentFloatAsState(
                        value = animatedFloatRange.start,
                        key = TestValues.Value1,
                        false
                        false,
                    )
                    Spacer(Modifier.fillMaxSize())
                }
@@ -691,7 +684,7 @@ class ElementTest {
                        animateContentFloatAsState(
                            value = animatedFloatRange.endInclusive,
                            key = TestValues.Value1,
                            canOverflow = false
                            canOverflow = false,
                        )
                    Spacer(Modifier.element(TestElements.Foo).fillMaxSize())
                    LaunchedEffect(Unit) {
@@ -786,7 +779,7 @@ class ElementTest {
                                progressConverter = ProgressConverter.linear()
                                translate(TestElements.Foo, y = overscrollTranslateY)
                            }
                        }
                        },
                )
                    as MutableSceneTransitionLayoutStateImpl
            }
@@ -795,7 +788,7 @@ class ElementTest {
            touchSlop = LocalViewConfiguration.current.touchSlop
            SceneTransitionLayout(
                state = state,
                modifier = Modifier.size(layoutWidth, layoutHeight)
                modifier = Modifier.size(layoutWidth, layoutHeight),
            ) {
                scene(SceneA) { Spacer(Modifier.fillMaxSize()) }
                scene(SceneB, userActions = mapOf(Swipe.Up to SceneA)) {
@@ -804,7 +797,7 @@ class ElementTest {
                            // A scrollable that does not consume the scroll gesture
                            .scrollable(
                                rememberScrollableState(consumeScrollDelta = { 0f }),
                                Orientation.Vertical
                                Orientation.Vertical,
                            )
                            .fillMaxSize()
                    ) {
@@ -869,18 +862,18 @@ class ElementTest {
            touchSlop = LocalViewConfiguration.current.touchSlop
            SceneTransitionLayout(
                state = state,
                modifier = Modifier.size(layoutWidth, layoutHeight)
                modifier = Modifier.size(layoutWidth, layoutHeight),
            ) {
                scene(
                    SceneA,
                    userActions = mapOf(Swipe(SwipeDirection.Down, pointerCount = 2) to SceneB)
                    userActions = mapOf(Swipe(SwipeDirection.Down, pointerCount = 2) to SceneB),
                ) {
                    Box(
                        Modifier
                            // A scrollable that does not consume the scroll gesture
                            .scrollable(
                                rememberScrollableState(consumeScrollDelta = { 0f }),
                                Orientation.Vertical
                                Orientation.Vertical,
                            )
                            .fillMaxSize()
                    ) {
@@ -1203,7 +1196,7 @@ class ElementTest {
                                startsOutsideLayoutBounds = false,
                            )
                        }
                    }
                    },
                )
            }

@@ -1621,7 +1614,7 @@ class ElementTest {
            rule.runOnUiThread {
                MutableSceneTransitionLayoutStateImpl(
                    SceneA,
                    transitions { overscrollDisabled(SceneA, Orientation.Horizontal) }
                    transitions { overscrollDisabled(SceneA, Orientation.Horizontal) },
                )
            }

@@ -1644,7 +1637,7 @@ class ElementTest {
                    from = SceneA,
                    to = SceneB,
                    progress = { -1f },
                    orientation = Orientation.Horizontal
                    orientation = Orientation.Horizontal,
                )
            )
        }
@@ -1666,7 +1659,7 @@ class ElementTest {
            rule.runOnUiThread {
                MutableSceneTransitionLayoutStateImpl(
                    SceneA,
                    transitions { from(SceneA, to = SceneB) { fade(TestElements.Foo) } }
                    transitions { from(SceneA, to = SceneB) { fade(TestElements.Foo) } },
                )
            }

@@ -1730,7 +1723,7 @@ class ElementTest {
            rule.runOnUiThread {
                MutableSceneTransitionLayoutStateImpl(
                    SceneA,
                    transitions { from(SceneA, to = SceneB) { fade(TestElements.Foo) } }
                    transitions { from(SceneA, to = SceneB) { fade(TestElements.Foo) } },
                )
            }

@@ -1781,7 +1774,7 @@ class ElementTest {
                    transitions {
                        overscrollDisabled(SceneA, Orientation.Horizontal)
                        overscrollDisabled(SceneB, Orientation.Horizontal)
                    }
                    },
                )
            }

@@ -1830,7 +1823,7 @@ class ElementTest {
                    transitions {
                        overscrollDisabled(SceneA, Orientation.Horizontal)
                        overscrollDisabled(SceneB, Orientation.Horizontal)
                    }
                    },
                )
            }

@@ -1886,7 +1879,7 @@ class ElementTest {
                            progressConverter = ProgressConverter.linear()
                            translate(TestElements.Foo, y = 15.dp)
                        }
                    }
                    },
                )
            }

@@ -2053,7 +2046,7 @@ class ElementTest {
                        from(SceneB, to = SceneC) {
                            scaleSize(TestElements.Foo, width = 2f, height = 3f)
                        }
                    }
                    },
                )
            }

@@ -2171,7 +2164,7 @@ class ElementTest {
            rule.runOnIdle {
                MutableSceneTransitionLayoutStateImpl(
                    SceneA,
                    transitions { overscrollDisabled(SceneA, Orientation.Horizontal) }
                    transitions { overscrollDisabled(SceneA, Orientation.Horizontal) },
                )
            }

@@ -2231,7 +2224,7 @@ class ElementTest {
                            // In B => A, Foo is shared.
                            sharedElement(TestElements.Foo, enabled = true)
                        }
                    }
                    },
                )
            }

@@ -2363,7 +2356,7 @@ class ElementTest {
                },
                previewProgress = 0.5f,
                progress = 0f,
                isInPreviewStage = true
                isInPreviewStage = true,
            )

        // verify that preview transition for exiting elements is halfway played from
@@ -2419,7 +2412,7 @@ class ElementTest {
                },
                previewProgress = 0.5f,
                progress = 0.5f,
                isInPreviewStage = false
                isInPreviewStage = false,
            )

        // verify that exiting elements remain in the preview-end state if no further transition is
@@ -2459,13 +2452,13 @@ class ElementTest {
        transition: TransitionBuilder.() -> Unit,
        progress: Float = 0f,
        previewProgress: Float = 0.5f,
        isInPreviewStage: Boolean = true
        isInPreviewStage: Boolean = true,
    ): SceneTransitionLayoutImpl {
        val state =
            rule.runOnIdle {
                MutableSceneTransitionLayoutStateImpl(
                    from,
                    transitions { from(from, to = to, preview = preview, builder = transition) }
                    transitions { from(from, to = to, preview = preview, builder = transition) },
                )
            }

@@ -2489,7 +2482,7 @@ class ElementTest {
                to = to,
                progress = { progress },
                previewProgress = { previewProgress },
                isInPreviewStage = { isInPreviewStage }
                isInPreviewStage = { isInPreviewStage },
            )
        scope.launch { state.startTransition(bToA) }
        rule.waitForIdle()
+4 −4
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ class InterruptionHandlerTest {
                        object : InterruptionHandler {
                            override fun onInterruption(
                                interrupted: TransitionState.Transition.ChangeScene,
                                newTargetScene: SceneKey
                                newTargetScene: SceneKey,
                            ): InterruptionResult {
                                return InterruptionResult(
                                    animateFrom = interrupted.currentScene,
@@ -88,7 +88,7 @@ class InterruptionHandlerTest {
            .comparingElementsUsing(FromToCurrentTriple)
            .containsExactly(
                // B to C.
                Triple(SceneB, SceneC, SceneC),
                Triple(SceneB, SceneC, SceneC)
            )
            .inOrder()
    }
@@ -105,7 +105,7 @@ class InterruptionHandlerTest {
                        object : InterruptionHandler {
                            override fun onInterruption(
                                interrupted: TransitionState.Transition.ChangeScene,
                                newTargetScene: SceneKey
                                newTargetScene: SceneKey,
                            ): InterruptionResult {
                                return InterruptionResult(
                                    animateFrom =
@@ -217,7 +217,7 @@ class InterruptionHandlerTest {
                { transition: TransitionState.Transition.ChangeScene? ->
                    Triple(transition?.fromScene, transition?.toScene, transition?.currentScene)
                },
                "(from, to, current) triple"
                "(from, to, current) triple",
            )
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -161,7 +161,7 @@ class MovableElementTest {
                            element: ElementKey,
                            transition: TransitionState.Transition,
                            fromContentZIndex: Float,
                            toContentZIndex: Float
                            toContentZIndex: Float,
                        ): ContentKey {
                            transition as TransitionState.Transition.ChangeScene
                            assertThat(transition).hasFromScene(SceneA)
@@ -177,7 +177,7 @@ class MovableElementTest {
                                SceneB
                            }
                        }
                    }
                    },
            )

        rule.testTransition(
Loading