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

Commit 3f943b8a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add overlay.alwaysCompose to STL overlays" into main

parents 3b321d7c a215c18f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ interface SceneTransitionLayoutScope<out CS : ContentScope> {
        alignment: Alignment = Alignment.Center,
        isModal: Boolean = true,
        effectFactory: OverscrollFactory? = null,
        alwaysCompose: Boolean = false,
        content: @Composable CS.() -> Unit,
    )
}
+49 −28
Original line number Diff line number Diff line
@@ -209,6 +209,7 @@ internal class SceneTransitionLayoutImpl(

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

    init {
        updateContents(builder, layoutDirection, defaultEffectFactory)
@@ -368,7 +369,8 @@ internal class SceneTransitionLayoutImpl(
                    alignment: Alignment,
                    isModal: Boolean,
                    effectFactory: OverscrollFactory?,
                    content: @Composable (InternalContentScope.() -> Unit),
                    alwaysCompose: Boolean,
                    content: @Composable InternalContentScope.() -> Unit,
                ) {
                    overlaysDefined = true
                    overlaysToRemove.remove(key)
@@ -379,6 +381,10 @@ internal class SceneTransitionLayoutImpl(
                        Content.calculateGlobalZIndex(parentZIndex, ++zIndex, ancestors.size)
                    val factory = effectFactory ?: defaultEffectFactory
                    if (overlay != null) {
                        check(alwaysCompose == overlay.alwaysCompose) {
                            "overlay.alwaysCompose can not change"
                        }

                        // Update an existing overlay.
                        overlay.content = content
                        overlay.zIndex = zIndex.toFloat()
@@ -389,7 +395,7 @@ internal class SceneTransitionLayoutImpl(
                        overlay.maybeUpdateEffects(factory)
                    } else {
                        // New overlay.
                        overlays[key] =
                        val overlay =
                            Overlay(
                                key,
                                this@SceneTransitionLayoutImpl,
@@ -400,7 +406,17 @@ internal class SceneTransitionLayoutImpl(
                                alignment,
                                isModal,
                                factory,
                                alwaysCompose,
                            )
                        overlays[key] = overlay

                        if (alwaysCompose) {
                            (overlaysToAlwaysCompose
                                    ?: mutableListOf<Overlay>().also {
                                        overlaysToAlwaysCompose = it
                                    })
                                .add(overlay)
                        }
                    }
                }
            }
@@ -532,6 +548,8 @@ internal class SceneTransitionLayoutImpl(

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

    private data class OverlayToCompose(val overlay: Overlay, val isInvisible: Boolean)

    @Composable
    private fun BoxScope.Overlays() {
        val overlaysOrderedByZIndex = overlaysToComposeOrderedByZIndex()
@@ -539,7 +557,7 @@ internal class SceneTransitionLayoutImpl(
            return
        }

        overlaysOrderedByZIndex.fastForEach { overlay ->
        overlaysOrderedByZIndex.fastForEach { (overlay, isInvisible) ->
            val key = overlay.key
            key(key) {
                // We put the overlays inside a Box that is matching the layout size so that they
@@ -561,27 +579,27 @@ internal class SceneTransitionLayoutImpl(
                        )
                    }

                    overlay.Content(Modifier.align(overlay.alignment))
                    overlay.Content(Modifier.align(overlay.alignment), isInvisible = isInvisible)
                }
            }
        }
    }

    private fun overlaysToComposeOrderedByZIndex(): List<Overlay> {
    private fun overlaysToComposeOrderedByZIndex(): List<OverlayToCompose> {
        if (_overlays == null) return emptyList()

        val transitions = state.currentTransitions
        return if (transitions.isEmpty()) {
                state.transitionState.currentOverlays.map { overlay(it) }
            } else {
                buildList {
        val overlays = buildList {
            val visited = mutableSetOf<OverlayKey>()
                    fun maybeAdd(key: OverlayKey) {
                        if (visited.add(key)) {
                            add(overlay(key))
            fun maybeAdd(overlay: OverlayKey, isInvisible: Boolean = false) {
                if (visited.add(overlay)) {
                    add(OverlayToCompose(overlay(overlay), isInvisible))
                }
            }

            if (transitions.isEmpty()) {
                state.transitionState.currentOverlays.forEach { maybeAdd(it) }
            } else {
                transitions.fastForEach { transition ->
                    when (transition) {
                        is TransitionState.Transition.ChangeScene -> {}
@@ -598,8 +616,11 @@ internal class SceneTransitionLayoutImpl(
                // Make sure that all current overlays are composed.
                transitions.last().currentOverlays.forEach { maybeAdd(it) }
            }

            overlaysToAlwaysCompose?.fastForEach { maybeAdd(it.key, isInvisible = true) }
        }
            .sortedBy { it.zIndex }

        return overlays.sortedBy { it.overlay.zIndex }
    }

    internal fun hideOverlays(hide: HideCurrentOverlays) {
+1 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ internal sealed class Content(
    zIndex: Float,
    globalZIndex: Long,
    effectFactory: OverscrollFactory,
    val alwaysCompose: Boolean,
) {
    private val nestedScrollControlState = NestedScrollControlState()
    internal val scope = ContentScopeImpl(layoutImpl, content = this, nestedScrollControlState)
+2 −1
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@ internal class Overlay(
    alignment: Alignment,
    isModal: Boolean,
    effectFactory: OverscrollFactory,
) : Content(key, layoutImpl, content, actions, zIndex, globalZIndex, effectFactory) {
    alwaysCompose: Boolean,
) : Content(key, layoutImpl, content, actions, zIndex, globalZIndex, effectFactory, alwaysCompose) {
    var alignment by mutableStateOf(alignment)
    var isModal by mutableStateOf(isModal)

+2 −2
Original line number Diff line number Diff line
@@ -35,8 +35,8 @@ internal class Scene(
    zIndex: Float,
    globalZIndex: Long,
    effectFactory: OverscrollFactory,
    val alwaysCompose: Boolean,
) : Content(key, layoutImpl, content, actions, zIndex, globalZIndex, effectFactory) {
    alwaysCompose: Boolean,
) : Content(key, layoutImpl, content, actions, zIndex, globalZIndex, effectFactory, alwaysCompose) {
    override fun toString(): String {
        return "Scene(key=$key)"
    }
Loading