1 /* 2 * Copyright 2023 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.transformation 18 19 import androidx.compose.ui.unit.IntSize 20 import com.android.compose.animation.scene.Element 21 import com.android.compose.animation.scene.ElementMatcher 22 import com.android.compose.animation.scene.SceneKey 23 import com.android.compose.animation.scene.SceneTransitionLayoutImpl 24 import com.android.compose.animation.scene.TransitionState 25 import kotlin.math.roundToInt 26 27 /** 28 * Scales the size of an element. Note that this makes the element resize every frame and will 29 * therefore impact the layout of other elements. 30 */ 31 internal class ScaleSize( 32 override val matcher: ElementMatcher, 33 private val width: Float = 1f, 34 private val height: Float = 1f, 35 ) : PropertyTransformation<IntSize> { transformnull36 override fun transform( 37 layoutImpl: SceneTransitionLayoutImpl, 38 scene: SceneKey, 39 element: Element, 40 sceneState: Element.SceneState, 41 transition: TransitionState.Transition, 42 value: IntSize, 43 ): IntSize { 44 return IntSize( 45 width = (value.width * width).roundToInt(), 46 height = (value.height * height).roundToInt(), 47 ) 48 } 49 } 50