[go: nahoru, domu]

Add Inspector Info to animation modifier

Bug: 169686792
Fixes: 172374370
Test: Unit test added
Change-Id: Ia259a1671608d6b2430ce21f7f1c19b3491947ef
diff --git a/compose/animation/animation/lint-baseline.xml b/compose/animation/animation/lint-baseline.xml
deleted file mode 100644
index c8e378e..0000000
--- a/compose/animation/animation/lint-baseline.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<issues format="5" by="lint 4.2.0-alpha06" client="gradle" variant="debug" version="4.2.0-alpha06">
-
-    <issue
-        id="ModifierInspectorInfo"
-        message="Modifiers should include inspectorInfo for the Layout Inspector"
-        errorLine1="): Modifier = composed {"
-        errorLine2="              ~~~~~~~~">
-        <location
-            file="src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt"
-            line="62"
-            column="15"/>
-    </issue>
-
-</issues>
diff --git a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimationModifierTest.kt b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimationModifierTest.kt
index e3d82e6..e27f2e1 100644
--- a/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimationModifierTest.kt
+++ b/compose/animation/animation/src/androidAndroidTest/kotlin/androidx/compose/animation/AnimationModifierTest.kt
@@ -23,11 +23,14 @@
 import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
 import androidx.compose.runtime.setValue
+import androidx.compose.ui.Modifier
 import androidx.compose.ui.layout.LayoutModifier
 import androidx.compose.ui.layout.Measurable
 import androidx.compose.ui.layout.MeasureResult
 import androidx.compose.ui.layout.MeasureScope
 import androidx.compose.ui.platform.DensityAmbient
+import androidx.compose.ui.platform.InspectableValue
+import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
 import androidx.compose.ui.test.junit4.createComposeRule
 import androidx.compose.ui.unit.Constraints
 import androidx.compose.ui.unit.IntSize
@@ -37,6 +40,11 @@
 import junit.framework.TestCase.assertEquals
 import junit.framework.TestCase.assertNotNull
 import junit.framework.TestCase.assertNull
+import org.hamcrest.CoreMatchers.`is`
+import org.hamcrest.CoreMatchers.nullValue
+import org.junit.After
+import org.junit.Assert.assertThat
+import org.junit.Before
 import org.junit.Rule
 import org.junit.Test
 import org.junit.runner.RunWith
@@ -48,6 +56,16 @@
     @get:Rule
     val rule = createComposeRule()
 
+    @Before
+    fun before() {
+        isDebugInspectorInfoEnabled = true
+    }
+
+    @After
+    fun after() {
+        isDebugInspectorInfoEnabled = false
+    }
+
     @Test
     fun animateContentSizeTest() {
         val startWidth = 100
@@ -116,6 +134,19 @@
             rule.waitForIdle()
         }
     }
+
+    @Test
+    fun testInspectorValue() {
+        rule.setContent {
+            val modifier = Modifier.animateContentSize() as InspectableValue
+            assertThat(modifier.nameFallback, `is`("animateContentSize"))
+            assertThat(modifier.valueOverride, nullValue())
+            assertThat(
+                modifier.inspectableElements.map { it.name }.toList(),
+                `is`(listOf("animSpec", "clip", "endListener"))
+            )
+        }
+    }
 }
 
 internal class TestModifier : LayoutModifier {
diff --git a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt
index f93a2cd..bf2a5c9 100644
--- a/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt
+++ b/compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt
@@ -31,6 +31,7 @@
 import androidx.compose.ui.draw.clipToBounds
 import androidx.compose.ui.layout.MeasureResult
 import androidx.compose.ui.platform.AnimationClockAmbient
+import androidx.compose.ui.platform.debugInspectorInfo
 import androidx.compose.ui.unit.Constraints
 import androidx.compose.ui.unit.IntSize
 
@@ -59,7 +60,14 @@
     animSpec: AnimationSpec<IntSize> = spring(),
     clip: Boolean = true,
     endListener: ((startSize: IntSize, endSize: IntSize) -> Unit)? = null
-): Modifier = composed {
+): Modifier = composed(
+    inspectorInfo = debugInspectorInfo {
+        name = "animateContentSize"
+        properties["animSpec"] = animSpec
+        properties["clip"] = clip
+        properties["endListener"] = endListener
+    }
+) {
     // TODO: Listener could be a fun interface after 1.4
     val clock = AnimationClockAmbient.current.asDisposableClock()
     val animModifier = remember {