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

Commit b5ea1f2b authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Fix flicker when swiping to shade or QS

This CL fixes the check done in NotificationScrollingStack to understand
if the current scene is invisible even if it is composed. This can
happen when using alwaysCompose.

Before this CL, we would check the lifecycle of the Content, but this
lifecycle is updated in a SideEffect and therefore later than the first
composed frame when starting a transition.

After this CL, we directly check the source of truth (the
SceneTransitionLayoutState) so that it is consistent with what is
composed by STL.

Bug: 437888180
Fixes: 437888180
Test: Manual, swiped down the shade from Gone & LS
Flag: com.android.systemui.scene_container
Change-Id: I45d2ccaa4bd51862d4d0bc69f6a027ace95c224e
parent 20189081
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -85,11 +85,9 @@ import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.constrainHeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastAny
import androidx.compose.ui.util.lerp
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.currentStateAsState
import com.android.compose.animation.scene.ContentKey
import com.android.compose.animation.scene.ContentScope
import com.android.compose.animation.scene.ElementKey
@@ -298,6 +296,15 @@ fun ContentScope.ConstrainedNotificationStack(
    }
}

private fun ContentScope.isAlwaysComposedContentVisible(): Boolean {
    val thisContent = this.contentKey
    return layoutState.currentScene == thisContent ||
        layoutState.currentOverlays.contains(thisContent) ||
        layoutState.currentTransitions.fastAny {
            it.fromContent == thisContent || it.toContent == thisContent
        }
}

/**
 * Adds the space where notification stack should appear in the scene, with a scrim and nested
 * scrolling.
@@ -320,8 +327,7 @@ fun ContentScope.NotificationScrollingStack(
    supportNestedScrolling: Boolean,
    onEmptySpaceClick: (() -> Unit)? = null,
) {
    val lifecycleState by LocalLifecycleOwner.current.lifecycle.currentStateAsState()
    if (!lifecycleState.isAtLeast(Lifecycle.State.STARTED)) {
    if (!isAlwaysComposedContentVisible()) {
        // Some scenes or overlays that use this Composable may be using alwaysCompose=true which
        // will cause them to compose everything but not be visible. Because this Composable has
        // many side effects that push UI state upstream to its view-model, interactors, and