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

Commit d1188672 authored by Omar Miatello's avatar Omar Miatello
Browse files

STL Element exposes a lookaheadScopeCoordinates

Test: atest ElementTest
Test: Manually tested on Flexiglass
Bug: 410524175
Flag: com.android.systemui.scene_container
Change-Id: Idba51cf8d92bc9fadd6b0d70c29ccefe6dba28f2
parent 5a1fade5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ internal class Element(val key: ElementKey) {
         * we are idle on this content.
         */
        var targetSize by mutableStateOf(SizeUnspecified)
        var targetCoordinates: LayoutCoordinates? by mutableStateOf(null)
        var targetOffset by mutableStateOf(Offset.Unspecified)

        /** The last state this element had in this content. */
@@ -375,6 +376,7 @@ internal class ElementNode(
                // this content when idle.
                coordinates?.let { coords ->
                    with(layoutImpl.lookaheadScope) {
                        stateInContent.targetCoordinates = lookaheadScopeCoordinates
                        stateInContent.targetOffset =
                            lookaheadScopeCoordinates.localLookaheadPositionOf(coords)
                    }
+8 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.PointerType
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.LookaheadScope
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
@@ -176,6 +177,13 @@ interface ElementStateScope {
     */
    fun ElementKey.targetOffset(content: ContentKey): Offset?

    /**
     * Return the *target* layout coordinates of [this] element in the given [content], i.e. the
     * LayoutCoordinates of the element when idle, or `null` if the element is not composed and
     * placed in that content (yet).
     */
    fun ElementKey.targetCoordinates(content: ContentKey): LayoutCoordinates?

    /**
     * Return the *target* size of [this] content, i.e. the size of the content when idle, or `null`
     * if the content was not composed (yet).
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.compose.animation.scene
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MotionScheme
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection
import com.android.compose.animation.scene.transformation.PropertyTransformationScope
@@ -43,6 +44,10 @@ internal class ElementStateScopeImpl(private val layoutImpl: SceneTransitionLayo
        }
    }

    override fun ElementKey.targetCoordinates(content: ContentKey): LayoutCoordinates? {
        return layoutImpl.elements[this]?.stateByContent?.get(content)?.targetCoordinates
    }

    override fun ContentKey.targetSize(): IntSize? {
        return layoutImpl.content(this).targetSize.takeIf { it != Element.SizeUnspecified }
    }
+1 −0
Original line number Diff line number Diff line
@@ -1490,6 +1490,7 @@ class ElementTest {

        assertThat(bState.targetSize).isNotEqualTo(Element.SizeUnspecified)
        assertThat(bState.targetOffset).isNotEqualTo(Offset.Unspecified)
        assertThat(bState.targetCoordinates).isNotEqualTo(null)
    }

    @Test