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

Commit d0ea0006 authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

[STL] Inline UserActionResult copy for predictive back

Bug: 350705972
Test: TransitionDslTest
Flag: com.android.systemui.scene_container
Change-Id: I65bc60ec3ec8101fb7cb7792a4840c7751d83b7a
parent f74f3941
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -21,6 +21,10 @@ import androidx.activity.compose.PredictiveBackHandler
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.runtime.Composable
import com.android.compose.animation.scene.UserActionResult.ChangeScene
import com.android.compose.animation.scene.UserActionResult.HideOverlay
import com.android.compose.animation.scene.UserActionResult.ReplaceByOverlay
import com.android.compose.animation.scene.UserActionResult.ShowOverlay
import kotlin.coroutines.cancellation.CancellationException
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
@@ -44,9 +48,11 @@ internal fun PredictiveBackHandler(
        val animation =
            createSwipeAnimation(
                layoutImpl,
                result.userActionCopy(
                    transitionKey = result.transitionKey ?: TransitionKey.PredictiveBack
                ),
                if (result.transitionKey != null) {
                    result
                } else {
                    result.copy(transitionKey = TransitionKey.PredictiveBack)
                },
                isUpOrLeft = false,
                // Note that the orientation does not matter here given that it's only used to
                // compute the distance. In our case the distance is always 1f.
@@ -98,3 +104,14 @@ private suspend fun <T : ContentKey> animate(
        layoutImpl.state.startTransition(animation.contentTransition)
    }
}

private fun UserActionResult.copy(
    transitionKey: TransitionKey? = this.transitionKey
): UserActionResult {
    return when (this) {
        is ChangeScene -> copy(transitionKey = transitionKey)
        is ShowOverlay -> copy(transitionKey = transitionKey)
        is HideOverlay -> copy(transitionKey = transitionKey)
        is ReplaceByOverlay -> copy(transitionKey = transitionKey)
    }
}
+0 −11
Original line number Diff line number Diff line
@@ -492,17 +492,6 @@ sealed class UserActionResult(
) {
    internal abstract fun toContent(currentScene: SceneKey): ContentKey

    internal fun userActionCopy(
        transitionKey: TransitionKey? = this.transitionKey
    ): UserActionResult {
        return when (this) {
            is ChangeScene -> copy(transitionKey = transitionKey)
            is ShowOverlay -> copy(transitionKey = transitionKey)
            is HideOverlay -> copy(transitionKey = transitionKey)
            is ReplaceByOverlay -> copy(transitionKey = transitionKey)
        }
    }

    data class ChangeScene
    internal constructor(
        /** The scene we should be transitioning to during the [UserAction]. */