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

Commit 9bd93474 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Support contents (overlays) in ElementStateScope

Bug: 373799480
Test: N/A
Flag: com.android.systemui.scene_container
Change-Id: I65bedb3fb4972a7e237e318298a8c148684ed1fa
parent 58613adc
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -127,22 +127,23 @@ interface SceneTransitionLayoutScope {
/** A scope that can be used to query the target state of an element or scene. */
interface ElementStateScope {
    /**
     * Return the *target* size of [this] element in the given [scene], i.e. the size of the element
     * when idle, or `null` if the element is not composed and measured in that scene (yet).
     * Return the *target* size of [this] element in the given [content], i.e. the size of the
     * element when idle, or `null` if the element is not composed and measured in that content
     * (yet).
     */
    fun ElementKey.targetSize(scene: SceneKey): IntSize?
    fun ElementKey.targetSize(content: ContentKey): IntSize?

    /**
     * Return the *target* offset of [this] element in the given [scene], i.e. the size of the
     * element when idle, or `null` if the element is not composed and placed in that scene (yet).
     * Return the *target* offset of [this] element in the given [content], i.e. the size of the
     * element when idle, or `null` if the element is not composed and placed in that content (yet).
     */
    fun ElementKey.targetOffset(scene: SceneKey): Offset?
    fun ElementKey.targetOffset(content: ContentKey): Offset?

    /**
     * Return the *target* size of [this] scene, i.e. the size of the scene when idle, or `null` if
     * the scene was never composed.
     * Return the *target* size of [this] content, i.e. the size of the content when idle, or `null`
     * if the content was not composed (yet).
     */
    fun SceneKey.targetSize(): IntSize?
    fun ContentKey.targetSize(): IntSize?
}

@Stable
+6 −1
Original line number Diff line number Diff line
@@ -172,7 +172,12 @@ internal class SceneTransitionLayoutImpl(
        return scenes[key] ?: error("Scene $key is not configured")
    }

    internal fun sceneOrNull(key: SceneKey): Scene? = scenes[key]
    internal fun contentOrNull(key: ContentKey): Content? {
        return when (key) {
            is SceneKey -> scenes[key]
            is OverlayKey -> overlays[key]
        }
    }

    internal fun overlay(key: OverlayKey): Overlay {
        return overlays[key] ?: error("Overlay $key is not configured")
+6 −6
Original line number Diff line number Diff line
@@ -21,20 +21,20 @@ import androidx.compose.ui.unit.IntSize

internal class ElementStateScopeImpl(private val layoutImpl: SceneTransitionLayoutImpl) :
    ElementStateScope {
    override fun ElementKey.targetSize(scene: SceneKey): IntSize? {
        return layoutImpl.elements[this]?.stateByContent?.get(scene)?.targetSize.takeIf {
    override fun ElementKey.targetSize(content: ContentKey): IntSize? {
        return layoutImpl.elements[this]?.stateByContent?.get(content)?.targetSize.takeIf {
            it != Element.SizeUnspecified
        }
    }

    override fun ElementKey.targetOffset(scene: SceneKey): Offset? {
        return layoutImpl.elements[this]?.stateByContent?.get(scene)?.targetOffset.takeIf {
    override fun ElementKey.targetOffset(content: ContentKey): Offset? {
        return layoutImpl.elements[this]?.stateByContent?.get(content)?.targetOffset.takeIf {
            it != Offset.Unspecified
        }
    }

    override fun SceneKey.targetSize(): IntSize? {
        return layoutImpl.sceneOrNull(this)?.targetSize.takeIf { it != IntSize.Zero }
    override fun ContentKey.targetSize(): IntSize? {
        return layoutImpl.contentOrNull(this)?.targetSize.takeIf { it != IntSize.Zero }
    }
}