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

Commit 9ab1cab6 authored by Omar Miatello's avatar Omar Miatello
Browse files

QS skip squishing during lookahead or when squishiness is 1.0

Why?
QS skips squishing when performing lookaheads to ensure accurate
pre-layout sizing, or when the squishiness is set to 1.0 to avoid
unnecessary calculations.

Test: Manually tested on Flexiglass ON and Flexiglass OFF
Bug: 410524175
Flag: com.android.systemui.scene_container
Change-Id: I89ce6f0002e0cd2e0ce0dbf1f699c62f8292c8e8
parent 2a96c7d0
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -33,16 +33,28 @@ import kotlin.math.roundToInt
 * also use an approachLayout tracking the squishiness.
 */
fun Modifier.verticalSquish(squishiness: () -> Float): Modifier {
    return approachLayout(isMeasurementApproachInProgress = { squishiness() < 1 }) { measurable, _
        ->
        val squishinessValue = squishiness()
    return approachLayout(
        isMeasurementApproachInProgress = { squishiness() < 1 },
        approachMeasure = { measurable, constraints ->
            val value = squishiness()

            // Skip squishing during lookahead or when squishiness is 1.0.
            // Lookahead: Ensures accurate pre-layout size.
            // Squishiness 1f: Prevents unnecessary calculations when no squishing is needed.
            if (isLookingAhead || value == 1f) {
                return@approachLayout measurable.measure(constraints).run {
                    layout(width, height) { place(0, 0) }
                }
            }

            val expectedHeight = lookaheadSize.height

            val placeable = measurable.measure(lookaheadConstraints)
        val squishedHeight = (expectedHeight * squishinessValue).roundToInt()
            val squishedHeight = (expectedHeight * value).roundToInt()
            // Center the content by moving it UP (squishedHeight < actualHeight)
            val scroll = (squishedHeight - expectedHeight) / 2

            layout(placeable.width, squishedHeight) { placeable.place(0, scroll) }
    }
        },
    )
}