1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.compose.animation.scene.transition.link 18 19 import com.android.compose.animation.scene.SceneKey 20 import com.android.compose.animation.scene.TransitionKey 21 import com.android.compose.animation.scene.TransitionState 22 import kotlinx.coroutines.Job 23 24 /** A linked transition which is driven by a [originalTransition]. */ 25 internal class LinkedTransition( 26 private val originalTransition: TransitionState.Transition, 27 fromScene: SceneKey, 28 toScene: SceneKey, 29 override val key: TransitionKey? = null, 30 ) : TransitionState.Transition(fromScene, toScene) { 31 32 override val currentScene: SceneKey 33 get() { 34 return when (originalTransition.currentScene) { 35 originalTransition.fromScene -> fromScene 36 originalTransition.toScene -> toScene 37 else -> error("Original currentScene is neither FromScene nor ToScene") 38 } 39 } 40 41 override val isInitiatedByUserInput: Boolean 42 get() = originalTransition.isInitiatedByUserInput 43 44 override val isUserInputOngoing: Boolean 45 get() = originalTransition.isUserInputOngoing 46 47 override val progress: Float 48 get() = originalTransition.progress 49 50 override val progressVelocity: Float 51 get() = originalTransition.progressVelocity 52 finishnull53 override fun finish(): Job = originalTransition.finish() 54 } 55