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

Commit 9fdd961e authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Use approachLayout for squishiness

That way, we can report the height of QQS measured without squishiness.
This is needed because QuickSettingsController and NPVC need the
measured height at the final step of the animation.

Test: manual
Bug: 369657526
Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Change-Id: Ie66b64b0d71021ee59aca28f4024c3841e5f7660
parent b084a6aa
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -52,8 +52,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.approachLayout
import androidx.compose.ui.layout.onPlaced
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.dimensionResource
@@ -536,6 +536,10 @@ constructor(

            onDispose { qqsVisible.value = false }
        }
        val squishiness by
            viewModel.containerViewModel.quickQuickSettingsViewModel.squishinessViewModel
                .squishiness
                .collectAsStateWithLifecycle()
        Column(modifier = Modifier.sysuiResTag("quick_qs_panel")) {
            Box(
                modifier =
@@ -549,7 +553,16 @@ constructor(
                                topFromRoot + coordinates.size.height,
                            )
                        }
                        .onSizeChanged { size -> qqsHeight.value = size.height }
                        // Use an approach layout to determien the height without squishiness, as
                        // that's the value that NPVC and QuickSettingsController care about
                        // (measured height).
                        .approachLayout(isMeasurementApproachInProgress = { squishiness < 1f }) {
                            measurable,
                            constraints ->
                            qqsHeight.value = lookaheadSize.height
                            val placeable = measurable.measure(constraints)
                            layout(placeable.width, placeable.height) { placeable.place(0, 0) }
                        }
                        .padding(top = { qqsPadding }, bottom = { bottomPadding.roundToPx() })
            ) {
                val qsEnabled by viewModel.qsEnabled.collectAsStateWithLifecycle()
+14 −9
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.systemui.qs.panels.ui.compose.infinitegrid

import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.layout
import androidx.compose.ui.layout.approachLayout
import kotlin.math.roundToInt

/**
@@ -27,17 +27,22 @@ import kotlin.math.roundToInt
 * [squishiness] on the measure/layout pass.
 *
 * The squished composable will be center aligned.
 *
 * Use an [approachLayout] to indicate that this should be measured in the lookahead step without
 * using squishiness. If a parent of this node needs to determine unsquished height, they should
 * also use an approachLayout tracking the squishiness.
 */
fun Modifier.verticalSquish(squishiness: () -> Float): Modifier {
    return layout { measurable, constraints ->
        val placeable = measurable.measure(constraints)
        val actualHeight = placeable.height
        val squishedHeight = actualHeight * squishiness()
    return approachLayout(isMeasurementApproachInProgress = { squishiness() < 1 }) { measurable, _
        ->
        val squishinessValue = squishiness()
        val expectedHeight = lookaheadSize.height

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

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