• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.testing
18 
19 import androidx.compose.ui.geometry.Offset
20 import androidx.compose.ui.semantics.SemanticsNode
21 import androidx.compose.ui.unit.IntSize
22 import com.android.compose.animation.scene.Element
23 import com.android.compose.animation.scene.Element.Companion.AlphaUnspecified
24 import com.android.compose.animation.scene.Element.Companion.SizeUnspecified
25 import com.android.compose.animation.scene.ElementModifier
26 import com.android.compose.animation.scene.Scale
27 
28 val SemanticsNode.lastAlphaForTesting: Float?
<lambda>null29     get() = elementState.lastAlpha.takeIf { it != AlphaUnspecified }
30 
31 val SemanticsNode.lastScaleForTesting: Scale?
<lambda>null32     get() = elementState.lastScale.takeIf { it != Scale.Unspecified }
33 
34 val SemanticsNode.lastOffsetForTesting: Offset?
<lambda>null35     get() = elementState.lastOffset.takeIf { it != Offset.Unspecified }
36 
37 val SemanticsNode.lastSizeForTesting: IntSize?
<lambda>null38     get() = elementState.lastSize.takeIf { it != SizeUnspecified }
39 
40 private val SemanticsNode.elementState: Element.State
41     get() {
42         val elementModifier =
43             layoutInfo
44                 .getModifierInfo()
<lambda>null45                 .map { it.modifier }
46                 .filterIsInstance<ElementModifier>()
47                 .firstOrNull()
<lambda>null48         requireNotNull(elementModifier) {
49             "No ElementModifier found. Did you use the Modifier.element(...)?"
50         }
<lambda>null51         return with(elementModifier) {
52             val element =
53                 requireNotNull(layoutImpl.elements[key]) {
54                     "No element found in STL layout with key: ${key.testTag}"
55                 }
56             requireNotNull(element.stateByContent[content.key]) {
57                 "No state found for given content key: ${content.key.testTag}"
58             }
59         }
60     }
61