Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/AnimatedSharedAsStateTest.kt +4 −12 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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) Loading Loading @@ -245,7 +237,7 @@ class AnimatedSharedAsStateTest { fromSceneContent = { SceneValues( targetValues = fromValues, onCurrentValueChanged = { lastValueInFrom = it } onCurrentValueChanged = { lastValueInFrom = it }, ) }, toSceneContent = { Loading Loading @@ -457,7 +449,7 @@ class AnimatedSharedAsStateTest { rule.runOnUiThread { MutableSceneTransitionLayoutStateImpl( SceneA, transitions { overscrollDisabled(SceneB, Orientation.Horizontal) } transitions { overscrollDisabled(SceneB, Orientation.Horizontal) }, ) } Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt +35 −56 Original line number Diff line number Diff line Loading @@ -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( Loading Loading @@ -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") Loading @@ -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 Loading @@ -144,7 +128,7 @@ class DraggableHandlerTest { fun nestedScrollConnection( nestedScrollBehavior: NestedScrollBehavior, isExternalOverscrollGesture: Boolean = false isExternalOverscrollGesture: Boolean = false, ) = NestedScrollHandlerImpl( layoutImpl = layoutImpl, Loading @@ -154,7 +138,7 @@ class DraggableHandlerTest { isExternalOverscrollGesture = { isExternalOverscrollGesture }, pointersInfoOwner = { PointersInfo(startedPosition = Offset.Zero, pointersDown = 1) } }, ) .connection Loading Loading @@ -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) } Loading Loading @@ -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) Loading @@ -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, ) } Loading Loading @@ -376,7 +357,7 @@ class DraggableHandlerTest { currentScene = SceneA, isInPreviewStage = true, previewProgress = 0.1f, progress = 0f progress = 0f, ) // wait for the stop animation Loading Loading @@ -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 Loading @@ -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 Loading Loading @@ -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 Loading @@ -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 Loading @@ -481,7 +462,7 @@ class DraggableHandlerTest { currentScene = SceneC, fromScene = SceneC, toScene = SceneB, progress = 0.1f progress = 0.1f, ) } Loading @@ -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, ) } Loading @@ -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, ) } Loading @@ -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 Loading @@ -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 Loading Loading @@ -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) } Loading @@ -658,7 +639,7 @@ class DraggableHandlerTest { nestedScroll.onPostScroll( consumed = Offset.Zero, available = Offset.Zero, source = NestedScrollSource.Drag source = NestedScrollSource.Drag, ) assertIdle(currentScene = SceneA) Loading @@ -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) Loading @@ -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) Loading @@ -700,7 +681,7 @@ class DraggableHandlerTest { nestedScroll.onPostScroll( consumed = consumed, available = Offset.Zero, source = NestedScrollSource.Drag source = NestedScrollSource.Drag, ) assertThat(progress).isEqualTo(0.2f) Loading @@ -711,7 +692,7 @@ class DraggableHandlerTest { private fun TestGestureScope.preScrollAfterSceneTransition( firstScroll: Float, secondScroll: Float secondScroll: Float, ) { val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview) // start scene transition Loading @@ -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, ) } Loading Loading @@ -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 Loading Loading @@ -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)) Loading Loading @@ -1015,7 +994,7 @@ class DraggableHandlerTest { layoutState.startTransitionImmediately( animationScope = testScope.backgroundScope, transition(SceneA, SceneB) transition(SceneA, SceneB), ) assertThat(draggableHandler.shouldImmediatelyIntercept(startedPosition = null)).isFalse() } Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt +29 −36 Original line number Diff line number Diff line Loading @@ -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)) } Loading Loading @@ -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()) Loading Loading @@ -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) } Loading @@ -627,7 +620,7 @@ class ElementTest { from(SceneA, to = SceneB) { scaleSize(TestElements.Foo, width = 2f, height = 2f) } } }, ) } Loading Loading @@ -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()) } Loading @@ -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) { Loading Loading @@ -786,7 +779,7 @@ class ElementTest { progressConverter = ProgressConverter.linear() translate(TestElements.Foo, y = overscrollTranslateY) } } }, ) as MutableSceneTransitionLayoutStateImpl } Loading @@ -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)) { Loading @@ -804,7 +797,7 @@ class ElementTest { // A scrollable that does not consume the scroll gesture .scrollable( rememberScrollableState(consumeScrollDelta = { 0f }), Orientation.Vertical Orientation.Vertical, ) .fillMaxSize() ) { Loading Loading @@ -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() ) { Loading Loading @@ -1203,7 +1196,7 @@ class ElementTest { startsOutsideLayoutBounds = false, ) } } }, ) } Loading Loading @@ -1621,7 +1614,7 @@ class ElementTest { rule.runOnUiThread { MutableSceneTransitionLayoutStateImpl( SceneA, transitions { overscrollDisabled(SceneA, Orientation.Horizontal) } transitions { overscrollDisabled(SceneA, Orientation.Horizontal) }, ) } Loading @@ -1644,7 +1637,7 @@ class ElementTest { from = SceneA, to = SceneB, progress = { -1f }, orientation = Orientation.Horizontal orientation = Orientation.Horizontal, ) ) } Loading @@ -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) } }, ) } Loading Loading @@ -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) } }, ) } Loading Loading @@ -1781,7 +1774,7 @@ class ElementTest { transitions { overscrollDisabled(SceneA, Orientation.Horizontal) overscrollDisabled(SceneB, Orientation.Horizontal) } }, ) } Loading Loading @@ -1830,7 +1823,7 @@ class ElementTest { transitions { overscrollDisabled(SceneA, Orientation.Horizontal) overscrollDisabled(SceneB, Orientation.Horizontal) } }, ) } Loading Loading @@ -1886,7 +1879,7 @@ class ElementTest { progressConverter = ProgressConverter.linear() translate(TestElements.Foo, y = 15.dp) } } }, ) } Loading Loading @@ -2053,7 +2046,7 @@ class ElementTest { from(SceneB, to = SceneC) { scaleSize(TestElements.Foo, width = 2f, height = 3f) } } }, ) } Loading Loading @@ -2171,7 +2164,7 @@ class ElementTest { rule.runOnIdle { MutableSceneTransitionLayoutStateImpl( SceneA, transitions { overscrollDisabled(SceneA, Orientation.Horizontal) } transitions { overscrollDisabled(SceneA, Orientation.Horizontal) }, ) } Loading Loading @@ -2231,7 +2224,7 @@ class ElementTest { // In B => A, Foo is shared. sharedElement(TestElements.Foo, enabled = true) } } }, ) } Loading Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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) }, ) } Loading @@ -2489,7 +2482,7 @@ class ElementTest { to = to, progress = { progress }, previewProgress = { previewProgress }, isInPreviewStage = { isInPreviewStage } isInPreviewStage = { isInPreviewStage }, ) scope.launch { state.startTransition(bToA) } rule.waitForIdle() Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/InterruptionHandlerTest.kt +4 −4 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -88,7 +88,7 @@ class InterruptionHandlerTest { .comparingElementsUsing(FromToCurrentTriple) .containsExactly( // B to C. Triple(SceneB, SceneC, SceneC), Triple(SceneB, SceneC, SceneC) ) .inOrder() } Loading @@ -105,7 +105,7 @@ class InterruptionHandlerTest { object : InterruptionHandler { override fun onInterruption( interrupted: TransitionState.Transition.ChangeScene, newTargetScene: SceneKey newTargetScene: SceneKey, ): InterruptionResult { return InterruptionResult( animateFrom = Loading Loading @@ -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", ) } } packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/MovableElementTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -177,7 +177,7 @@ class MovableElementTest { SceneB } } } }, ) rule.testTransition( Loading Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/AnimatedSharedAsStateTest.kt +4 −12 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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) Loading Loading @@ -245,7 +237,7 @@ class AnimatedSharedAsStateTest { fromSceneContent = { SceneValues( targetValues = fromValues, onCurrentValueChanged = { lastValueInFrom = it } onCurrentValueChanged = { lastValueInFrom = it }, ) }, toSceneContent = { Loading Loading @@ -457,7 +449,7 @@ class AnimatedSharedAsStateTest { rule.runOnUiThread { MutableSceneTransitionLayoutStateImpl( SceneA, transitions { overscrollDisabled(SceneB, Orientation.Horizontal) } transitions { overscrollDisabled(SceneB, Orientation.Horizontal) }, ) } Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/DraggableHandlerTest.kt +35 −56 Original line number Diff line number Diff line Loading @@ -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( Loading Loading @@ -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") Loading @@ -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 Loading @@ -144,7 +128,7 @@ class DraggableHandlerTest { fun nestedScrollConnection( nestedScrollBehavior: NestedScrollBehavior, isExternalOverscrollGesture: Boolean = false isExternalOverscrollGesture: Boolean = false, ) = NestedScrollHandlerImpl( layoutImpl = layoutImpl, Loading @@ -154,7 +138,7 @@ class DraggableHandlerTest { isExternalOverscrollGesture = { isExternalOverscrollGesture }, pointersInfoOwner = { PointersInfo(startedPosition = Offset.Zero, pointersDown = 1) } }, ) .connection Loading Loading @@ -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) } Loading Loading @@ -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) Loading @@ -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, ) } Loading Loading @@ -376,7 +357,7 @@ class DraggableHandlerTest { currentScene = SceneA, isInPreviewStage = true, previewProgress = 0.1f, progress = 0f progress = 0f, ) // wait for the stop animation Loading Loading @@ -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 Loading @@ -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 Loading Loading @@ -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 Loading @@ -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 Loading @@ -481,7 +462,7 @@ class DraggableHandlerTest { currentScene = SceneC, fromScene = SceneC, toScene = SceneB, progress = 0.1f progress = 0.1f, ) } Loading @@ -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, ) } Loading @@ -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, ) } Loading @@ -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 Loading @@ -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 Loading Loading @@ -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) } Loading @@ -658,7 +639,7 @@ class DraggableHandlerTest { nestedScroll.onPostScroll( consumed = Offset.Zero, available = Offset.Zero, source = NestedScrollSource.Drag source = NestedScrollSource.Drag, ) assertIdle(currentScene = SceneA) Loading @@ -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) Loading @@ -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) Loading @@ -700,7 +681,7 @@ class DraggableHandlerTest { nestedScroll.onPostScroll( consumed = consumed, available = Offset.Zero, source = NestedScrollSource.Drag source = NestedScrollSource.Drag, ) assertThat(progress).isEqualTo(0.2f) Loading @@ -711,7 +692,7 @@ class DraggableHandlerTest { private fun TestGestureScope.preScrollAfterSceneTransition( firstScroll: Float, secondScroll: Float secondScroll: Float, ) { val nestedScroll = nestedScrollConnection(nestedScrollBehavior = EdgeWithPreview) // start scene transition Loading @@ -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, ) } Loading Loading @@ -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 Loading Loading @@ -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)) Loading Loading @@ -1015,7 +994,7 @@ class DraggableHandlerTest { layoutState.startTransitionImmediately( animationScope = testScope.backgroundScope, transition(SceneA, SceneB) transition(SceneA, SceneB), ) assertThat(draggableHandler.shouldImmediatelyIntercept(startedPosition = null)).isFalse() } Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt +29 −36 Original line number Diff line number Diff line Loading @@ -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)) } Loading Loading @@ -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()) Loading Loading @@ -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) } Loading @@ -627,7 +620,7 @@ class ElementTest { from(SceneA, to = SceneB) { scaleSize(TestElements.Foo, width = 2f, height = 2f) } } }, ) } Loading Loading @@ -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()) } Loading @@ -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) { Loading Loading @@ -786,7 +779,7 @@ class ElementTest { progressConverter = ProgressConverter.linear() translate(TestElements.Foo, y = overscrollTranslateY) } } }, ) as MutableSceneTransitionLayoutStateImpl } Loading @@ -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)) { Loading @@ -804,7 +797,7 @@ class ElementTest { // A scrollable that does not consume the scroll gesture .scrollable( rememberScrollableState(consumeScrollDelta = { 0f }), Orientation.Vertical Orientation.Vertical, ) .fillMaxSize() ) { Loading Loading @@ -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() ) { Loading Loading @@ -1203,7 +1196,7 @@ class ElementTest { startsOutsideLayoutBounds = false, ) } } }, ) } Loading Loading @@ -1621,7 +1614,7 @@ class ElementTest { rule.runOnUiThread { MutableSceneTransitionLayoutStateImpl( SceneA, transitions { overscrollDisabled(SceneA, Orientation.Horizontal) } transitions { overscrollDisabled(SceneA, Orientation.Horizontal) }, ) } Loading @@ -1644,7 +1637,7 @@ class ElementTest { from = SceneA, to = SceneB, progress = { -1f }, orientation = Orientation.Horizontal orientation = Orientation.Horizontal, ) ) } Loading @@ -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) } }, ) } Loading Loading @@ -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) } }, ) } Loading Loading @@ -1781,7 +1774,7 @@ class ElementTest { transitions { overscrollDisabled(SceneA, Orientation.Horizontal) overscrollDisabled(SceneB, Orientation.Horizontal) } }, ) } Loading Loading @@ -1830,7 +1823,7 @@ class ElementTest { transitions { overscrollDisabled(SceneA, Orientation.Horizontal) overscrollDisabled(SceneB, Orientation.Horizontal) } }, ) } Loading Loading @@ -1886,7 +1879,7 @@ class ElementTest { progressConverter = ProgressConverter.linear() translate(TestElements.Foo, y = 15.dp) } } }, ) } Loading Loading @@ -2053,7 +2046,7 @@ class ElementTest { from(SceneB, to = SceneC) { scaleSize(TestElements.Foo, width = 2f, height = 3f) } } }, ) } Loading Loading @@ -2171,7 +2164,7 @@ class ElementTest { rule.runOnIdle { MutableSceneTransitionLayoutStateImpl( SceneA, transitions { overscrollDisabled(SceneA, Orientation.Horizontal) } transitions { overscrollDisabled(SceneA, Orientation.Horizontal) }, ) } Loading Loading @@ -2231,7 +2224,7 @@ class ElementTest { // In B => A, Foo is shared. sharedElement(TestElements.Foo, enabled = true) } } }, ) } Loading Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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) }, ) } Loading @@ -2489,7 +2482,7 @@ class ElementTest { to = to, progress = { progress }, previewProgress = { previewProgress }, isInPreviewStage = { isInPreviewStage } isInPreviewStage = { isInPreviewStage }, ) scope.launch { state.startTransition(bToA) } rule.waitForIdle() Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/InterruptionHandlerTest.kt +4 −4 Original line number Diff line number Diff line Loading @@ -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, Loading @@ -88,7 +88,7 @@ class InterruptionHandlerTest { .comparingElementsUsing(FromToCurrentTriple) .containsExactly( // B to C. Triple(SceneB, SceneC, SceneC), Triple(SceneB, SceneC, SceneC) ) .inOrder() } Loading @@ -105,7 +105,7 @@ class InterruptionHandlerTest { object : InterruptionHandler { override fun onInterruption( interrupted: TransitionState.Transition.ChangeScene, newTargetScene: SceneKey newTargetScene: SceneKey, ): InterruptionResult { return InterruptionResult( animateFrom = Loading Loading @@ -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", ) } }
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/MovableElementTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -177,7 +177,7 @@ class MovableElementTest { SceneB } } } }, ) rule.testTransition( Loading