[go: nahoru, domu]

Fixes existing UnnecessaryComposedModifier issues

Bug: b/191017532
Test: lintDebug
Change-Id: I1a4db29446accdd136e4d94a855fc0f3e25b58d7
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/SelectableTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/SelectableTest.kt
index 7d83865..094c042 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/SelectableTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/SelectableTest.kt
@@ -317,7 +317,7 @@
                 false,
                 interactionSource = remember { MutableInteractionSource() },
                 indication = null
-            ) {} as InspectableValue
+            ) {}.toList().first() as InspectableValue
             assertThat(modifier.nameFallback).isEqualTo("selectable")
             assertThat(modifier.valueOverride).isNull()
             assertThat(modifier.inspectableElements.map { it.name }.asIterable()).containsExactly(
@@ -330,4 +330,7 @@
             )
         }
     }
+
+    private fun Modifier.toList(): List<Modifier.Element> =
+        foldIn(mutableListOf()) { acc, e -> acc.apply { acc.add(e) } }
 }
\ No newline at end of file
diff --git a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ToggleableTest.kt b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ToggleableTest.kt
index b637719..68f79936 100644
--- a/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ToggleableTest.kt
+++ b/compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ToggleableTest.kt
@@ -412,7 +412,7 @@
                 >
                 interactionSource = remember { MutableInteractionSource() },
                 indication = null
-            ) as InspectableValue
+            ).toList().first() as InspectableValue
             assertThat(modifier.nameFallback).isEqualTo("toggleable")
             assertThat(modifier.valueOverride).isNull()
             assertThat(modifier.inspectableElements.map { it.name }.asIterable()).containsExactly(
@@ -450,8 +450,7 @@
                 interactionSource = remember { MutableInteractionSource() },
                 indication = null,
                 >
-            )
-                as InspectableValue
+            ).toList().first() as InspectableValue
             assertThat(modifier.nameFallback).isEqualTo("triStateToggleable")
             assertThat(modifier.valueOverride).isNull()
             assertThat(modifier.inspectableElements.map { it.name }.asIterable()).containsExactly(
@@ -524,4 +523,7 @@
                 click(position = Offset(pokePoint, pokePoint))
             }.assertIsOn()
     }
+
+    private fun Modifier.toList(): List<Modifier.Element> =
+        foldIn(mutableListOf()) { acc, e -> acc.apply { acc.add(e) } }
 }
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Border.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Border.kt
index bf670c8..0f0816b 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Border.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Border.kt
@@ -90,8 +90,6 @@
  * @param brush brush to paint the border with
  * @param shape shape of the border
  */
-// TODO: b/191017532 remove Modifier.composed
-@Suppress("UnnecessaryComposedModifier")
 fun Modifier.border(width: Dp, brush: Brush, shape: Shape): Modifier = composed(
     factory = {
         // BorderCache object that is lazily allocated depending on the type of shape
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Selectable.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Selectable.kt
index 9f9ca9b..5b3869a 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Selectable.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Selectable.kt
@@ -24,6 +24,7 @@
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.composed
 import androidx.compose.ui.platform.debugInspectorInfo
+import androidx.compose.ui.platform.inspectable
 import androidx.compose.ui.semantics.Role
 import androidx.compose.ui.semantics.selected
 import androidx.compose.ui.semantics.semantics
@@ -102,8 +103,6 @@
  * to describe the element or do customizations
  * @param onClick callback to invoke when this item is clicked
  */
-// TODO: b/191017532 remove Modifier.composed
-@Suppress("UnnecessaryComposedModifier")
 fun Modifier.selectable(
     selected: Boolean,
     interactionSource: MutableInteractionSource,
@@ -111,7 +110,16 @@
     enabled: Boolean = true,
     role: Role? = null,
     onClick: () -> Unit
-) = composed(
+) = inspectable(
+    inspectorInfo = debugInspectorInfo {
+        name = "selectable"
+        properties["selected"] = selected
+        properties["interactionSource"] = interactionSource
+        properties["indication"] = indication
+        properties["enabled"] = enabled
+        properties["role"] = role
+        properties["onClick"] = onClick
+    },
     factory = {
         Modifier.clickable(
             enabled = enabled,
@@ -122,14 +130,5 @@
         ).semantics {
             this.selected = selected
         }
-    },
-    inspectorInfo = debugInspectorInfo {
-        name = "selectable"
-        properties["selected"] = selected
-        properties["enabled"] = enabled
-        properties["role"] = role
-        properties["interactionSource"] = interactionSource
-        properties["indication"] = indication
-        properties["onClick"] = onClick
     }
 )
\ No newline at end of file
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Toggleable.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Toggleable.kt
index 500a875..7fff3e0 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Toggleable.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Toggleable.kt
@@ -31,6 +31,7 @@
 import androidx.compose.ui.composed
 import androidx.compose.ui.input.pointer.pointerInput
 import androidx.compose.ui.platform.debugInspectorInfo
+import androidx.compose.ui.platform.inspectable
 import androidx.compose.ui.semantics.Role
 import androidx.compose.ui.semantics.disabled
 import androidx.compose.ui.semantics.onClick
@@ -105,8 +106,6 @@
  * @param onValueChange callback to be invoked when toggleable is clicked,
  * therefore the change of the state in requested.
  */
-// TODO: b/191017532 remove Modifier.composed
-@Suppress("UnnecessaryComposedModifier")
 fun Modifier.toggleable(
     value: Boolean,
     interactionSource: MutableInteractionSource,
@@ -114,14 +113,14 @@
     enabled: Boolean = true,
     role: Role? = null,
     onValueChange: (Boolean) -> Unit
-) = composed(
+) = inspectable(
     inspectorInfo = debugInspectorInfo {
         name = "toggleable"
         properties["value"] = value
-        properties["enabled"] = enabled
-        properties["role"] = role
         properties["interactionSource"] = interactionSource
         properties["indication"] = indication
+        properties["enabled"] = enabled
+        properties["role"] = role
         properties["onValueChange"] = onValueChange
     },
     factory = {
@@ -208,8 +207,6 @@
  * to describe the element or do customizations
  * @param onClick will be called when user clicks the toggleable.
  */
-// TODO: b/191017532 remove Modifier.composed
-@Suppress("UnnecessaryComposedModifier")
 fun Modifier.triStateToggleable(
     state: ToggleableState,
     interactionSource: MutableInteractionSource,
@@ -217,7 +214,7 @@
     enabled: Boolean = true,
     role: Role? = null,
     onClick: () -> Unit
-) = composed(
+) = inspectable(
     inspectorInfo = debugInspectorInfo {
         name = "triStateToggleable"
         properties["state"] = state
diff --git a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/ShadowTest.kt b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/ShadowTest.kt
index 82b4ab1..a661597 100644
--- a/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/ShadowTest.kt
+++ b/compose/ui/ui/src/androidAndroidTest/kotlin/androidx/compose/ui/draw/ShadowTest.kt
@@ -226,7 +226,7 @@
     @Test
     fun testInspectorValue() {
         rule.runOnUiThreadIR {
-            val modifier = Modifier.shadow(4.0.dp) as InspectableValue
+            val modifier = Modifier.shadow(4.0.dp).toList().first() as InspectableValue
             assertThat(modifier.nameFallback).isEqualTo("shadow")
             assertThat(modifier.valueOverride).isNull()
             assertThat(modifier.inspectableElements.asIterable()).containsExactly(
@@ -344,4 +344,7 @@
         assertEquals(height, bitmap.height)
         return bitmap
     }
+
+    private fun Modifier.toList(): List<Modifier.Element> =
+        foldIn(mutableListOf()) { acc, e -> acc.apply { acc.add(e) } }
 }
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/draw/Shadow.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/draw/Shadow.kt
index b7be049..dc975c9 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/draw/Shadow.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/draw/Shadow.kt
@@ -18,11 +18,11 @@
 
 import androidx.compose.runtime.Stable
 import androidx.compose.ui.Modifier
-import androidx.compose.ui.composed
 import androidx.compose.ui.graphics.RectangleShape
 import androidx.compose.ui.graphics.Shape
 import androidx.compose.ui.graphics.graphicsLayer
 import androidx.compose.ui.platform.debugInspectorInfo
+import androidx.compose.ui.platform.inspectable
 import androidx.compose.ui.unit.Dp
 import androidx.compose.ui.unit.dp
 
@@ -47,15 +47,13 @@
  * @param shape Defines a shape of the physical object
  * @param clip When active, the content drawing clips to the shape.
  */
-// TODO: b/191017532 remove Modifier.composed
-@Suppress("UnnecessaryComposedModifier")
 @Stable
 fun Modifier.shadow(
     elevation: Dp,
     shape: Shape = RectangleShape,
     clip: Boolean = elevation > 0.dp
 ) = if (elevation > 0.dp || clip) {
-    composed(
+    inspectable(
         inspectorInfo = debugInspectorInfo {
             name = "shadow"
             properties["elevation"] = elevation
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/KeyInputModifier.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/KeyInputModifier.kt
index 7aeab72..d441a8a 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/KeyInputModifier.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/input/key/KeyInputModifier.kt
@@ -17,10 +17,10 @@
 package androidx.compose.ui.input.key
 
 import androidx.compose.ui.Modifier
-import androidx.compose.ui.composed
 import androidx.compose.ui.focus.findActiveFocusNode
 import androidx.compose.ui.node.ModifiedKeyInputNode
 import androidx.compose.ui.platform.debugInspectorInfo
+import androidx.compose.ui.platform.inspectable
 
 /**
  * Adding this [modifier][Modifier] to the [modifier][Modifier] parameter of a component will
@@ -32,9 +32,7 @@
  *
  * @sample androidx.compose.ui.samples.KeyEventSample
  */
-// TODO: b/191017532 remove Modifier.composed
-@Suppress("UnnecessaryComposedModifier")
-fun Modifier.onKeyEvent(onKeyEvent: (KeyEvent) -> Boolean): Modifier = composed(
+fun Modifier.onKeyEvent(onKeyEvent: (KeyEvent) -> Boolean): Modifier = inspectable(
     inspectorInfo = debugInspectorInfo {
         name = "onKeyEvent"
         properties["onKeyEvent"] = onKeyEvent
@@ -55,9 +53,7 @@
  *
  * @sample androidx.compose.ui.samples.KeyEventSample
  */
-// TODO: b/191017532 remove Modifier.composed
-@Suppress("UnnecessaryComposedModifier")
-fun Modifier.onPreviewKeyEvent(onPreviewKeyEvent: (KeyEvent) -> Boolean): Modifier = composed(
+fun Modifier.onPreviewKeyEvent(onPreviewKeyEvent: (KeyEvent) -> Boolean): Modifier = inspectable(
     inspectorInfo = debugInspectorInfo {
         name = "onPreviewKeyEvent"
         properties["onPreviewKeyEvent"] = onPreviewKeyEvent
diff --git a/compose/ui/ui/src/test/kotlin/androidx/compose/ui/input/key/KeyInputModifierTest.kt b/compose/ui/ui/src/test/kotlin/androidx/compose/ui/input/key/KeyInputModifierTest.kt
index b29c924..d856367 100644
--- a/compose/ui/ui/src/test/kotlin/androidx/compose/ui/input/key/KeyInputModifierTest.kt
+++ b/compose/ui/ui/src/test/kotlin/androidx/compose/ui/input/key/KeyInputModifierTest.kt
@@ -39,7 +39,7 @@
     @Test
     fun testInspectorValueForKeyEvent() {
         val onKeyEvent: (KeyEvent) -> Boolean = { true }
-        val modifier = Modifier.onKeyEvent(onKeyEvent) as InspectableValue
+        val modifier = Modifier.onKeyEvent(onKeyEvent).first() as InspectableValue
         assertThat(modifier.nameFallback).isEqualTo("onKeyEvent")
         assertThat(modifier.valueOverride).isNull()
         assertThat(modifier.inspectableElements.asIterable()).containsExactly(
@@ -50,11 +50,17 @@
     @Test
     fun testInspectorValueForPreviewKeyEvent() {
         val onPreviewKeyEvent: (KeyEvent) -> Boolean = { true }
-        val modifier = Modifier.onPreviewKeyEvent(onPreviewKeyEvent) as InspectableValue
+        val modifier = Modifier.onPreviewKeyEvent(onPreviewKeyEvent).first() as InspectableValue
         assertThat(modifier.nameFallback).isEqualTo("onPreviewKeyEvent")
         assertThat(modifier.valueOverride).isNull()
         assertThat(modifier.inspectableElements.asIterable()).containsExactly(
             ValueElement("onPreviewKeyEvent", onPreviewKeyEvent)
         )
     }
+
+    private fun Modifier.toList(): List<Modifier.Element> =
+        foldIn(mutableListOf()) { acc, e -> acc.apply { acc.add(e) } }
+
+    private fun Modifier.first(): Modifier.Element =
+        toList().first()
 }