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

Commit 9978b835 authored by 0's avatar 0
Browse files

[flexiglass] Switch ShadeHeader expanded format to depend on layoutState

Moved ShadeHeader's expanded format to be derived from layoutState instead of using an animatedSceneFloat to avoid issues stemming from the animated value being incorrect at the very beginning of a transition (previous solution was meant to be a stopgap)

Bug: 333132303
Test: checked both dual sim icons and battery view change correctly according to QS expansion
Test: checked ShadeHeader does not recompose unnecessarily during Shade<->QS transition
Flag: ACONFIG com.android.systemui.scene_container DEVELOPMENT
Change-Id: I86af32e0a43c7f8d6b061c97d2d7c2642cebda69
parent 1265dc50
Loading
Loading
Loading
Loading
+22 −17
Original line number Diff line number Diff line
@@ -54,9 +54,9 @@ import androidx.compose.ui.viewinterop.AndroidView
import com.android.compose.animation.scene.ElementKey
import com.android.compose.animation.scene.LowestZIndexScenePicker
import com.android.compose.animation.scene.SceneScope
import com.android.compose.animation.scene.TransitionState
import com.android.compose.animation.scene.ValueKey
import com.android.compose.animation.scene.animateElementFloatAsState
import com.android.compose.animation.scene.animateSceneFloatAsState
import com.android.compose.windowsizeclass.LocalWindowSizeClass
import com.android.settingslib.Utils
import com.android.systemui.battery.BatteryMeterView
@@ -87,10 +87,6 @@ object ShadeHeader {
        val ShadeCarrierGroup = ElementKey("ShadeCarrierGroup")
    }

    object Keys {
        val transitionProgress = ValueKey("ShadeHeaderTransitionProgress")
    }

    object Values {
        val ClockScale = ValueKey("ShadeHeaderClockScale")
    }
@@ -119,19 +115,17 @@ fun SceneScope.CollapsedShadeHeader(
        return
    }

    val formatProgress =
        animateSceneFloatAsState(0f, ShadeHeader.Keys.transitionProgress)
            .unsafeCompositionState(initialValue = 0f)

    val cutoutWidth = LocalDisplayCutout.current.width()
    val cutoutLocation = LocalDisplayCutout.current.location

    val useExpandedFormat by
        remember(formatProgress) {
        remember(cutoutLocation) {
            derivedStateOf {
                cutoutLocation != CutoutLocation.CENTER || formatProgress.value > 0.5f
                cutoutLocation != CutoutLocation.CENTER ||
                    shouldUseExpandedFormat(layoutState.transitionState)
            }
        }

    val isPrivacyChipVisible by viewModel.isPrivacyChipVisible.collectAsState()

    // This layout assumes it is globally positioned at (0, 0) and is the
@@ -207,7 +201,7 @@ fun SceneScope.CollapsedShadeHeader(

        val screenWidth = constraints.maxWidth
        val cutoutWidthPx = cutoutWidth.roundToPx()
        val height = ShadeHeader.Dimensions.CollapsedHeight.roundToPx()
        val height = CollapsedHeight.roundToPx()
        val childConstraints = Constraints.fixed((screenWidth - cutoutWidthPx) / 2, height)

        val startMeasurable = measurables[0][0]
@@ -261,11 +255,10 @@ fun SceneScope.ExpandedShadeHeader(
        return
    }

    val formatProgress =
        animateSceneFloatAsState(1f, ShadeHeader.Keys.transitionProgress)
            .unsafeCompositionState(initialValue = 1f)
    val useExpandedFormat by
        remember(formatProgress) { derivedStateOf { formatProgress.value > 0.5f } }
    val useExpandedFormat by remember {
        derivedStateOf { shouldUseExpandedFormat(layoutState.transitionState) }
    }

    val isPrivacyChipVisible by viewModel.isPrivacyChipVisible.collectAsState()

    Box(modifier = modifier) {
@@ -530,3 +523,15 @@ private fun SceneScope.PrivacyChip(
        modifier = modifier.element(ShadeHeader.Elements.PrivacyChip),
    )
}

private fun shouldUseExpandedFormat(state: TransitionState): Boolean {
    return when (state) {
        is TransitionState.Idle -> {
            state.currentScene == Scenes.QuickSettings
        }
        is TransitionState.Transition -> {
            (state.isTransitioning(Scenes.Shade, Scenes.QuickSettings) && state.progress >= 0.5) ||
                (state.isTransitioning(Scenes.QuickSettings, Scenes.Shade) && state.progress < 0.5)
        }
    }
}