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.geometry.Offset
20 import com.android.compose.animation.scene.ContentKey
21 import com.android.compose.animation.scene.ElementKey
22 import com.android.compose.animation.scene.Scale
23 import com.android.compose.animation.scene.content.state.TransitionState
24 
25 /**
26  * Scales the draw size of an element. Note this will only scale the draw inside of an element,
27  * therefore it won't impact layout of elements around it.
28  */
29 internal class DrawScale
30 private constructor(
31     private val scaleX: Float,
32     private val scaleY: Float,
33     private val pivot: Offset,
34 ) : InterpolatedPropertyTransformation<Scale> {
35     override val property = PropertyTransformation.Property.Scale
36 
transformnull37     override fun PropertyTransformationScope.transform(
38         content: ContentKey,
39         element: ElementKey,
40         transition: TransitionState.Transition,
41         idleValue: Scale,
42     ): Scale {
43         return Scale(scaleX, scaleY, pivot)
44     }
45 
46     class Factory(private val scaleX: Float, private val scaleY: Float, private val pivot: Offset) :
47         Transformation.Factory {
createnull48         override fun create(): Transformation = DrawScale(scaleX, scaleY, pivot)
49     }
50 }
51