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

Commit 33746bcb authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Android (Google) Code Review
Browse files

Merge changes I5a89c485,I17462c64 into main

* changes:
  Add flag for always composed QSFragmentCompose
  Add scene.alwaysCompose flag to STL scenes
parents 77baad59 c474a3cc
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -2093,3 +2093,13 @@ flag {
        purpose: PURPOSE_BUGFIX
   }
}

flag {
    name: "always_compose_qs_ui_fragment"
    namespace: "systemui"
    description: "Have QQS and QS scenes in the Compose fragment always composed, not just when it should be visible."
    bug: "389985793"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ interface SceneTransitionLayoutScope<out CS : ContentScope> {
        key: SceneKey,
        userActions: Map<UserAction, UserActionResult> = emptyMap(),
        effectFactory: OverscrollFactory? = null,
        alwaysCompose: Boolean = false,
        content: @Composable CS.() -> Unit,
    )

+35 −12
Original line number Diff line number Diff line
@@ -207,6 +207,9 @@ internal class SceneTransitionLayoutImpl(
    private val nestedScrollDispatcher = NestedScrollDispatcher()
    private val nestedScrollConnection = object : NestedScrollConnection {}

    // TODO(b/399825091): Remove this.
    private var scenesToAlwaysCompose: MutableList<Scene>? = null

    init {
        updateContents(builder, layoutDirection, defaultEffectFactory)

@@ -312,6 +315,7 @@ internal class SceneTransitionLayoutImpl(
                    key: SceneKey,
                    userActions: Map<UserAction, UserActionResult>,
                    effectFactory: OverscrollFactory?,
                    alwaysCompose: Boolean,
                    content: @Composable InternalContentScope.() -> Unit,
                ) {
                    require(!overlaysDefined) { "all scenes must be defined before overlays" }
@@ -324,6 +328,10 @@ internal class SceneTransitionLayoutImpl(
                        Content.calculateGlobalZIndex(parentZIndex, ++zIndex, ancestors.size)
                    val factory = effectFactory ?: defaultEffectFactory
                    if (scene != null) {
                        check(alwaysCompose == scene.alwaysCompose) {
                            "scene.alwaysCompose can not change"
                        }

                        // Update an existing scene.
                        scene.content = content
                        scene.userActions = resolvedUserActions
@@ -332,7 +340,7 @@ internal class SceneTransitionLayoutImpl(
                        scene.maybeUpdateEffects(factory)
                    } else {
                        // New scene.
                        scenes[key] =
                        val scene =
                            Scene(
                                key,
                                this@SceneTransitionLayoutImpl,
@@ -341,7 +349,16 @@ internal class SceneTransitionLayoutImpl(
                                zIndex.toFloat(),
                                globalZIndex,
                                factory,
                                alwaysCompose,
                            )

                        scenes[key] = scene

                        if (alwaysCompose) {
                            (scenesToAlwaysCompose
                                    ?: mutableListOf<Scene>().also { scenesToAlwaysCompose = it })
                                .add(scene)
                        }
                    }
                }

@@ -470,22 +487,24 @@ internal class SceneTransitionLayoutImpl(

    @Composable
    private fun Scenes() {
        scenesToCompose().fastForEach { scene -> key(scene.key) { scene.Content() } }
        scenesToCompose().fastForEach { (scene, isInvisible) ->
            key(scene.key) { scene.Content(isInvisible = isInvisible) }
        }
    }

    private fun scenesToCompose(): List<Scene> {
    private fun scenesToCompose(): List<SceneToCompose> {
        val transitions = state.currentTransitions
        return if (transitions.isEmpty()) {
            listOf(scene(state.transitionState.currentScene))
        } else {
            buildList {
        return buildList {
            val visited = mutableSetOf<SceneKey>()
                fun maybeAdd(sceneKey: SceneKey) {
            fun maybeAdd(sceneKey: SceneKey, isInvisible: Boolean = false) {
                if (visited.add(sceneKey)) {
                        add(scene(sceneKey))
                    add(SceneToCompose(scene(sceneKey), isInvisible))
                }
            }

            if (transitions.isEmpty()) {
                maybeAdd(state.transitionState.currentScene)
            } else {
                // Compose the new scene we are going to first.
                transitions.fastForEachReversed { transition ->
                    when (transition) {
@@ -504,9 +523,13 @@ internal class SceneTransitionLayoutImpl(
                // Make sure that the current scene is always composed.
                maybeAdd(transitions.last().currentScene)
            }

            scenesToAlwaysCompose?.fastForEach { maybeAdd(it.key, isInvisible = true) }
        }
    }

    private data class SceneToCompose(val scene: Scene, val isInvisible: Boolean)

    @Composable
    private fun BoxScope.Overlays() {
        val overlaysOrderedByZIndex = overlaysToComposeOrderedByZIndex()
+8 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.LookaheadScope
import androidx.compose.ui.layout.approachLayout
import androidx.compose.ui.layout.layout
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.zIndex
@@ -154,11 +155,12 @@ internal sealed class Content(

    @SuppressLint("NotConstructor")
    @Composable
    fun Content(modifier: Modifier = Modifier) {
    fun Content(modifier: Modifier = Modifier, isInvisible: Boolean = false) {
        // If this content has a custom factory, provide it to the content so that the factory is
        // automatically used when calling rememberOverscrollEffect().
        Box(
            modifier
                .thenIf(isInvisible) { InvisibleModifier }
                .zIndex(zIndex)
                .approachLayout(
                    isMeasurementApproachInProgress = { layoutImpl.state.isTransitioning() }
@@ -305,3 +307,8 @@ internal class ContentScopeImpl(
        )
    }
}

private val InvisibleModifier =
    Modifier.layout { measurable, constraints ->
        measurable.measure(constraints).run { layout(width, height) {} }
    }
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ internal class Scene(
    zIndex: Float,
    globalZIndex: Long,
    effectFactory: OverscrollFactory,
    val alwaysCompose: Boolean,
) : Content(key, layoutImpl, content, actions, zIndex, globalZIndex, effectFactory) {
    override fun toString(): String {
        return "Scene(key=$key)"
Loading