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

Commit 4fd8e124 authored by Shawn Lee's avatar Shawn Lee Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Only punch hole in notif scrim during transitions" into main

parents f51a4c83 ae9ca52c
Loading
Loading
Loading
Loading
+13 −17
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ import androidx.compose.ui.util.lerp
import com.android.compose.animation.scene.ElementKey
import com.android.compose.animation.scene.NestedScrollBehavior
import com.android.compose.animation.scene.SceneScope
import com.android.compose.animation.scene.SceneTransitionLayoutState
import com.android.compose.modifiers.height
import com.android.systemui.common.ui.compose.windowinsets.LocalRawScreenHeight
import com.android.systemui.common.ui.compose.windowinsets.LocalScreenCornerRadius
@@ -157,6 +156,7 @@ fun SceneScope.ConstrainedNotificationStack(
fun SceneScope.NotificationScrollingStack(
    viewModel: NotificationsPlaceholderViewModel,
    maxScrimTop: () -> Float,
    shouldPunchHoleBehindScrim: Boolean,
    modifier: Modifier = Modifier,
) {
    val density = LocalDensity.current
@@ -233,7 +233,8 @@ fun SceneScope.NotificationScrollingStack(
                    // in step with the transition so that it is 0 when it completes.
                    if (
                        scrimOffset.value < 0 &&
                            layoutState.isTransitioning(from = Scenes.Shade, to = Scenes.Gone)
                            layoutState.isTransitioning(from = Scenes.Shade, to = Scenes.Gone) ||
                            layoutState.isTransitioning(from = Scenes.Shade, to = Scenes.Lockscreen)
                    ) {
                        IntOffset(x = 0, y = (scrimOffset.value * expansionFraction).roundToInt())
                    } else {
@@ -246,7 +247,7 @@ fun SceneScope.NotificationScrollingStack(
                                scrimCornerRadius,
                                screenCornerRadius,
                                { expansionFraction },
                                layoutState.isNotificationScrimTransitioning(),
                                shouldPunchHoleBehindScrim,
                            )
                            .let { scrimRounding.value.toRoundedCornerShape(it) }
                    clip = true
@@ -270,18 +271,20 @@ fun SceneScope.NotificationScrollingStack(
    ) {
        // Creates a cutout in the background scrim in the shape of the notifications scrim.
        // Only visible when notif scrim alpha < 1, during shade expansion.
        if (shouldPunchHoleBehindScrim) {
            Spacer(
                modifier =
                    Modifier.fillMaxSize().drawBehind {
                        drawRect(Color.Black, blendMode = BlendMode.DstOut)
                    }
            )
        }
        Box(
            modifier =
                Modifier.fillMaxSize()
                    .graphicsLayer {
                        alpha =
                            if (layoutState.isNotificationScrimTransitioning()) {
                            if (shouldPunchHoleBehindScrim) {
                                (expansionFraction / EXPANSION_FOR_MAX_SCRIM_ALPHA).coerceAtMost(1f)
                            } else 1f
                    }
@@ -429,13 +432,6 @@ private fun ShadeScrimRounding.toRoundedCornerShape(radius: Dp): RoundedCornerSh
    )
}

private fun SceneTransitionLayoutState.isNotificationScrimTransitioning(): Boolean {
    return isTransitioningBetween(Scenes.Gone, Scenes.Shade) ||
        isTransitioningBetween(Scenes.Lockscreen, Scenes.Shade) ||
        isTransitioningBetween(Scenes.Gone, Scenes.QuickSettings) ||
        isTransitioningBetween(Scenes.Lockscreen, Scenes.QuickSettings)
}

private const val TAG = "FlexiNotifs"
private val DEBUG_STACK_COLOR = Color(1f, 0f, 0f, 0.2f)
private val DEBUG_HUN_COLOR = Color(0f, 0f, 1f, 0.2f)
+15 −6
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import androidx.compose.ui.unit.dp
import com.android.compose.animation.scene.SceneScope
import com.android.compose.animation.scene.TransitionState
import com.android.compose.animation.scene.animateSceneFloatAsState
import com.android.compose.modifiers.thenIf
import com.android.compose.windowsizeclass.LocalWindowSizeClass
import com.android.systemui.battery.BatteryMeterViewController
import com.android.systemui.common.ui.compose.windowinsets.LocalRawScreenHeight
@@ -155,14 +156,21 @@ private fun SceneScope.QuickSettingsScene(
        qsSceneAdapter = viewModel.qsSceneAdapter
    )

    val shouldPunchHoleBehindScrim =
        layoutState.isTransitioningBetween(Scenes.Gone, Scenes.QuickSettings) ||
            layoutState.isTransitioningBetween(Scenes.Lockscreen, Scenes.QuickSettings)

    // TODO(b/280887232): implement the real UI.
    Box(
        modifier =
            modifier.fillMaxSize().graphicsLayer {
                // Render the scene to an offscreen buffer so that BlendMode.DstOut only clears this
            modifier
                .fillMaxSize()
                .graphicsLayer { alpha = contentAlpha }
                .thenIf(shouldPunchHoleBehindScrim) {
                    // Render the scene to an offscreen buffer so that BlendMode.DstOut only clears
                    // this
                    // scene (and not the one under it) during a scene transition.
                compositingStrategy = CompositingStrategy.Offscreen
                alpha = contentAlpha
                    Modifier.graphicsLayer(compositingStrategy = CompositingStrategy.Offscreen)
                }
    ) {
        val isCustomizing by viewModel.qsSceneAdapter.isCustomizing.collectAsState()
@@ -313,6 +321,7 @@ private fun SceneScope.QuickSettingsScene(
        NotificationScrollingStack(
            viewModel = notificationsPlaceholderViewModel,
            maxScrimTop = { screenHeight },
            shouldPunchHoleBehindScrim = shouldPunchHoleBehindScrim,
            modifier =
                Modifier.fillMaxWidth().offset { IntOffset(x = 0, y = screenHeight.roundToInt()) },
        )
+15 −3
Original line number Diff line number Diff line
@@ -204,9 +204,19 @@ private fun SceneScope.SingleShade(
        )
    val isClickable by viewModel.isClickable.collectAsState()

    // Render the scene to an offscreen buffer so that BlendMode.DstOut only clears this scene
    val shouldPunchHoleBehindScrim =
        layoutState.isTransitioningBetween(Scenes.Gone, Scenes.Shade) ||
            layoutState.isTransitioningBetween(Scenes.Lockscreen, Scenes.Shade)

    Box(
        modifier =
            modifier.thenIf(shouldPunchHoleBehindScrim) {
                // Render the scene to an offscreen buffer so that BlendMode.DstOut only clears this
                // scene
                // (and not the one under it) during a scene transition.
    Box(modifier = modifier.graphicsLayer(compositingStrategy = CompositingStrategy.Offscreen)) {
                Modifier.graphicsLayer(compositingStrategy = CompositingStrategy.Offscreen)
            }
    ) {
        Box(
            modifier =
                Modifier.fillMaxSize()
@@ -257,6 +267,7 @@ private fun SceneScope.SingleShade(
                        NotificationScrollingStack(
                            viewModel = viewModel.notifications,
                            maxScrimTop = { maxNotifScrimTop.value },
                            shouldPunchHoleBehindScrim = shouldPunchHoleBehindScrim,
                        )
                    },
                )
@@ -428,6 +439,7 @@ private fun SceneScope.SplitShade(
                NotificationScrollingStack(
                    viewModel = viewModel.notifications,
                    maxScrimTop = { 0f },
                    shouldPunchHoleBehindScrim = false,
                    modifier =
                        Modifier.weight(1f)
                            .fillMaxHeight()