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

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

Allow to specify transitions between contents

This CL is a small refactor of the transition DSL API so that
transitions can now be defined between two contents rather than two
scenes.

Bug: 353679003
Test: atest PlatformComposeSceneTransitionLayoutTests
Flag: com.android.systemui.scene_container
Change-Id: Iab1d57563010c2a66b6ed759f2d9ac9cd18300e5
parent 8ad770b7
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -157,16 +157,16 @@ interface TransitionSpec {
    val key: TransitionKey?

    /**
     * The scene we are transitioning from. If `null`, this spec can be used to animate from any
     * scene.
     * The content we are transitioning from. If `null`, this spec can be used to animate from any
     * content.
     */
    val from: SceneKey?
    val from: ContentKey?

    /**
     * The scene we are transitioning to. If `null`, this spec can be used to animate from any
     * scene.
     * The content we are transitioning to. If `null`, this spec can be used to animate from any
     * content.
     */
    val to: SceneKey?
    val to: ContentKey?

    /**
     * Return a reversed version of this [TransitionSpec] for a transition going from [to] to
@@ -231,8 +231,8 @@ interface TransformationSpec {

internal class TransitionSpecImpl(
    override val key: TransitionKey?,
    override val from: SceneKey?,
    override val to: SceneKey?,
    override val from: ContentKey?,
    override val to: ContentKey?,
    private val previewTransformationSpec: (() -> TransformationSpecImpl)? = null,
    private val reversePreviewTransformationSpec: (() -> TransformationSpecImpl)? = null,
    private val transformationSpec: () -> TransformationSpecImpl
+11 −11
Original line number Diff line number Diff line
@@ -47,9 +47,9 @@ interface SceneTransitionsBuilder {
    var interruptionHandler: InterruptionHandler

    /**
     * Define the default animation to be played when transitioning [to] the specified scene, from
     * any scene. For the animation specification to apply only when transitioning between two
     * specific scenes, use [from] instead.
     * Define the default animation to be played when transitioning [to] the specified content, from
     * any content. For the animation specification to apply only when transitioning between two
     * specific contents, use [from] instead.
     *
     * If [key] is not `null`, then this transition will only be used if the same key is specified
     * when triggering the transition.
@@ -61,7 +61,7 @@ interface SceneTransitionsBuilder {
     * @see from
     */
    fun to(
        to: SceneKey,
        to: ContentKey,
        key: TransitionKey? = null,
        preview: (TransitionBuilder.() -> Unit)? = null,
        reversePreview: (TransitionBuilder.() -> Unit)? = null,
@@ -69,12 +69,12 @@ interface SceneTransitionsBuilder {
    ): TransitionSpec

    /**
     * Define the animation to be played when transitioning [from] the specified scene. For the
     * animation specification to apply only when transitioning between two specific scenes, pass
     * the destination scene via the [to] argument.
     * Define the animation to be played when transitioning [from] the specified content. For the
     * animation specification to apply only when transitioning between two specific contents, pass
     * the destination content via the [to] argument.
     *
     * When looking up which transition should be used when animating from scene A to scene B, we
     * pick the single transition with the given [key] and matching one of these predicates (in
     * When looking up which transition should be used when animating from content A to content B,
     * we pick the single transition with the given [key] and matching one of these predicates (in
     * order of importance):
     * 1. from == A && to == B
     * 2. to == A && from == B, which is then treated in reverse.
@@ -86,8 +86,8 @@ interface SceneTransitionsBuilder {
     * reversible with the reverse animation having a preview as well, define a [reversePreview].
     */
    fun from(
        from: SceneKey,
        to: SceneKey? = null,
        from: ContentKey,
        to: ContentKey? = null,
        key: TransitionKey? = null,
        preview: (TransitionBuilder.() -> Unit)? = null,
        reversePreview: (TransitionBuilder.() -> Unit)? = null,
+5 −5
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ private class SceneTransitionsBuilderImpl : SceneTransitionsBuilder {
    val transitionOverscrollSpecs = mutableListOf<OverscrollSpecImpl>()

    override fun to(
        to: SceneKey,
        to: ContentKey,
        key: TransitionKey?,
        preview: (TransitionBuilder.() -> Unit)?,
        reversePreview: (TransitionBuilder.() -> Unit)?,
@@ -70,8 +70,8 @@ private class SceneTransitionsBuilderImpl : SceneTransitionsBuilder {
    }

    override fun from(
        from: SceneKey,
        to: SceneKey?,
        from: ContentKey,
        to: ContentKey?,
        key: TransitionKey?,
        preview: (TransitionBuilder.() -> Unit)?,
        reversePreview: (TransitionBuilder.() -> Unit)?,
@@ -120,8 +120,8 @@ private class SceneTransitionsBuilderImpl : SceneTransitionsBuilder {
    }

    private fun transition(
        from: SceneKey?,
        to: SceneKey?,
        from: ContentKey?,
        to: ContentKey?,
        key: TransitionKey?,
        preview: (TransitionBuilder.() -> Unit)?,
        reversePreview: (TransitionBuilder.() -> Unit)?,
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ class TransitionDslTest {

        assertThat(transitions.transitionSpecs)
            .comparingElementsUsing(
                Correspondence.transforming<TransitionSpecImpl, Pair<SceneKey?, SceneKey?>>(
                Correspondence.transforming<TransitionSpecImpl, Pair<ContentKey?, ContentKey?>>(
                    { it?.from to it?.to },
                    "has (from, to) equal to"
                )