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

Commit cfd36ae7 authored by Anvesh Renikindi's avatar Anvesh Renikindi Committed by Gerrit Code Review
Browse files

Merge "[STL] Address API council feedback on ApproachLayoutModifierNode" into main

parents 2d140714 ed805680
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -32,10 +32,11 @@ import androidx.compose.ui.geometry.isUnspecified
import androidx.compose.ui.geometry.lerp
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
import androidx.compose.ui.graphics.drawscope.scale
import androidx.compose.ui.layout.IntermediateMeasureScope
import androidx.compose.ui.layout.ApproachMeasureScope
import androidx.compose.ui.layout.LookaheadScope
import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.Placeable
import androidx.compose.ui.layout.intermediateLayout
import androidx.compose.ui.layout.approachLayout
import androidx.compose.ui.node.DrawModifierNode
import androidx.compose.ui.node.ModifierNodeElement
import androidx.compose.ui.platform.testTag
@@ -153,7 +154,9 @@ internal fun Modifier.element(
    return this.then(ElementModifier(layoutImpl, scene, element, sceneValues))
        // TODO(b/311132415): Move this into ElementNode once we can create a delegate
        // IntermediateLayoutModifierNode.
        .intermediateLayout { measurable, constraints ->
        .approachLayout(
            isMeasurementApproachInProgress = { layoutImpl.state.isTransitioning() },
        ) { measurable, constraints ->
            val placeable =
                measure(layoutImpl, scene, element, sceneValues, measurable, constraints)
            layout(placeable.width, placeable.height) {
@@ -428,7 +431,7 @@ private fun elementAlpha(
}

@OptIn(ExperimentalComposeUiApi::class)
private fun IntermediateMeasureScope.measure(
private fun ApproachMeasureScope.measure(
    layoutImpl: SceneTransitionLayoutImpl,
    scene: Scene,
    element: Element,
@@ -505,7 +508,7 @@ private fun getDrawScale(
}

@OptIn(ExperimentalComposeUiApi::class)
private fun IntermediateMeasureScope.place(
private fun ApproachMeasureScope.place(
    layoutImpl: SceneTransitionLayoutImpl,
    scene: Scene,
    element: Element,
@@ -513,6 +516,8 @@ private fun IntermediateMeasureScope.place(
    placeable: Placeable,
    placementScope: Placeable.PlacementScope,
) {
    this as LookaheadScope

    with(placementScope) {
        // Update the offset (relative to the SceneTransitionLayout) this element has in this scene
        // when idle.
+4 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.layout.intermediateLayout
import androidx.compose.ui.layout.approachLayout
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.zIndex
@@ -60,7 +60,9 @@ internal class Scene(
        Box(
            modifier
                .zIndex(zIndex)
                .intermediateLayout { measurable, constraints ->
                .approachLayout(
                    isMeasurementApproachInProgress = { scope.layoutState.isTransitioning() }
                ) { measurable, constraints ->
                    targetSize = lookaheadSize
                    val placeable = measurable.measure(constraints)
                    layout(placeable.width, placeable.height) { placeable.place(0, 0) }
+4 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.layout.LookaheadScope
import androidx.compose.ui.layout.intermediateLayout
import androidx.compose.ui.layout.approachLayout
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.util.fastForEach
@@ -150,7 +150,9 @@ internal class SceneTransitionLayoutImpl(
                .swipeToScene(horizontalGestureHandler)
                .swipeToScene(verticalGestureHandler)
                // Animate the size of this layout.
                .intermediateLayout { measurable, constraints ->
                .approachLayout(
                    isMeasurementApproachInProgress = { state.isTransitioning() },
                ) { measurable, constraints ->
                    // Measure content normally.
                    val placeable = measurable.measure(constraints)

+5 −3
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.intermediateLayout
import androidx.compose.ui.layout.approachLayout
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -67,7 +67,9 @@ class ElementTest {
            modifier
                .offset(offset)
                .element(key)
                .intermediateLayout { measurable, constraints ->
                .approachLayout(
                    isMeasurementApproachInProgress = { layoutState.isTransitioning() },
                ) { measurable, constraints ->
                    onLayout()
                    val placement = measurable.measure(constraints)
                    layout(placement.width, placement.height) {
@@ -436,7 +438,7 @@ class ElementTest {
                    // page should be composed.
                    HorizontalPager(
                        pagerState,
                        outOfBoundsPageCount = 0,
                        beyondViewportPageCount = 0,
                    ) { page ->
                        when (page) {
                            0 -> Box(Modifier.element(TestElements.Foo).fillMaxSize())