Loading packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/Element.kt +13 −10 Original line number Diff line number Diff line Loading @@ -261,16 +261,19 @@ private fun shouldDrawElement( scene: Scene, element: Element, ): Boolean { val transition = layoutImpl.state.currentTransition // Always draw the element if there is no ongoing transition or if the element is not shared or // if the current scene is the one that is currently over scrolling with [OverscrollSpec]. if ( transition == null || transition.fromScene !in element.sceneStates || transition.toScene !in element.sceneStates || transition.currentOverscrollSpec?.scene == scene.key ) { val transition = layoutImpl.state.currentTransition ?: return true val inFromScene = transition.fromScene in element.sceneStates val inToScene = transition.toScene in element.sceneStates // If an element is not present in any scene, it should not be drawn. if (!inFromScene && !inToScene) { return false } // Always draw if the element is not shared or if the current scene is the one that is currently // over scrolling with [OverscrollSpec]. if (!inFromScene || !inToScene || transition.currentOverscrollSpec?.scene == scene.key) { return true } Loading packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt +55 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.layout.intermediateLayout import androidx.compose.ui.platform.LocalViewConfiguration import androidx.compose.ui.test.assertIsNotDisplayed import androidx.compose.ui.test.assertTopPositionInRootIsEqualTo import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag Loading Loading @@ -174,6 +175,60 @@ class ElementTest { } } @Test fun elementsNotInTransition_shouldNotBeDrawn() { val nFrames = 20 val frameDuration = 16L val tween = tween<Float>(nFrames * frameDuration.toInt()) val layoutSize = 100.dp val elementSize = 50.dp val elementOffset = 20.dp lateinit var changeScene: (SceneKey) -> Unit rule.testTransition( from = TestScenes.SceneA, to = TestScenes.SceneB, transitionLayout = { currentScene, onChangeScene -> changeScene = onChangeScene SceneTransitionLayout( currentScene, onChangeScene, transitions { from(TestScenes.SceneA, to = TestScenes.SceneB) { spec = tween } from(TestScenes.SceneB, to = TestScenes.SceneC) { spec = tween } }, ) { scene(TestScenes.SceneA) { Box(Modifier.size(layoutSize)) { // Transformed element Element( TestElements.Bar, elementSize, elementOffset, ) } } scene(TestScenes.SceneB) { Box(Modifier.size(layoutSize)) } scene(TestScenes.SceneC) { Box(Modifier.size(layoutSize)) } } }, ) { // Start transition from SceneA to SceneB at(1 * frameDuration) { onElement(TestElements.Bar).assertExists() // Start transition from SceneB to SceneC changeScene(TestScenes.SceneC) } at(2 * frameDuration) { onElement(TestElements.Bar).assertIsNotDisplayed() } at(3 * frameDuration) { onElement(TestElements.Bar).assertDoesNotExist() } } } @Test fun onlyMovingElements_noLayout_onlyPlacement() { val nFrames = 20 Loading Loading
packages/SystemUI/compose/scene/src/com/android/compose/animation/scene/Element.kt +13 −10 Original line number Diff line number Diff line Loading @@ -261,16 +261,19 @@ private fun shouldDrawElement( scene: Scene, element: Element, ): Boolean { val transition = layoutImpl.state.currentTransition // Always draw the element if there is no ongoing transition or if the element is not shared or // if the current scene is the one that is currently over scrolling with [OverscrollSpec]. if ( transition == null || transition.fromScene !in element.sceneStates || transition.toScene !in element.sceneStates || transition.currentOverscrollSpec?.scene == scene.key ) { val transition = layoutImpl.state.currentTransition ?: return true val inFromScene = transition.fromScene in element.sceneStates val inToScene = transition.toScene in element.sceneStates // If an element is not present in any scene, it should not be drawn. if (!inFromScene && !inToScene) { return false } // Always draw if the element is not shared or if the current scene is the one that is currently // over scrolling with [OverscrollSpec]. if (!inFromScene || !inToScene || transition.currentOverscrollSpec?.scene == scene.key) { return true } Loading
packages/SystemUI/compose/scene/tests/src/com/android/compose/animation/scene/ElementTest.kt +55 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.layout.intermediateLayout import androidx.compose.ui.platform.LocalViewConfiguration import androidx.compose.ui.test.assertIsNotDisplayed import androidx.compose.ui.test.assertTopPositionInRootIsEqualTo import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag Loading Loading @@ -174,6 +175,60 @@ class ElementTest { } } @Test fun elementsNotInTransition_shouldNotBeDrawn() { val nFrames = 20 val frameDuration = 16L val tween = tween<Float>(nFrames * frameDuration.toInt()) val layoutSize = 100.dp val elementSize = 50.dp val elementOffset = 20.dp lateinit var changeScene: (SceneKey) -> Unit rule.testTransition( from = TestScenes.SceneA, to = TestScenes.SceneB, transitionLayout = { currentScene, onChangeScene -> changeScene = onChangeScene SceneTransitionLayout( currentScene, onChangeScene, transitions { from(TestScenes.SceneA, to = TestScenes.SceneB) { spec = tween } from(TestScenes.SceneB, to = TestScenes.SceneC) { spec = tween } }, ) { scene(TestScenes.SceneA) { Box(Modifier.size(layoutSize)) { // Transformed element Element( TestElements.Bar, elementSize, elementOffset, ) } } scene(TestScenes.SceneB) { Box(Modifier.size(layoutSize)) } scene(TestScenes.SceneC) { Box(Modifier.size(layoutSize)) } } }, ) { // Start transition from SceneA to SceneB at(1 * frameDuration) { onElement(TestElements.Bar).assertExists() // Start transition from SceneB to SceneC changeScene(TestScenes.SceneC) } at(2 * frameDuration) { onElement(TestElements.Bar).assertIsNotDisplayed() } at(3 * frameDuration) { onElement(TestElements.Bar).assertDoesNotExist() } } } @Test fun onlyMovingElements_noLayout_onlyPlacement() { val nFrames = 20 Loading