aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-06 22:03:00 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-12-06 22:03:00 +0000
commit224977ad5d1e9eb74a78a3fbe81ec2f27bf2ff6c (patch)
tree2a947999f12a88d19fa7d9c4291342a6c6386c8f
parent9a00eb71bcaceef443e73b391042b4954be46e62 (diff)
parentd194e75af4fb7b01a66bd7bb2dac8ebfd5b80405 (diff)
downloadsupport-224977ad5d1e9eb74a78a3fbe81ec2f27bf2ff6c.tar.gz
Merge "Guard against unattached coordinates" into snap-temp-L11100030000693181
-rw-r--r--compose/ui/ui-inspection/src/androidTest/java/androidx/compose/ui/inspection/inspector/LayoutInspectorTreeTest.kt36
-rw-r--r--compose/ui/ui-inspection/src/main/java/androidx/compose/ui/inspection/inspector/LayoutInspectorTree.kt2
-rw-r--r--compose/ui/ui-tooling-data/src/jvmMain/kotlin/androidx/compose/ui/tooling/data/SlotTree.jvm.kt7
3 files changed, 40 insertions, 5 deletions
diff --git a/compose/ui/ui-inspection/src/androidTest/java/androidx/compose/ui/inspection/inspector/LayoutInspectorTreeTest.kt b/compose/ui/ui-inspection/src/androidTest/java/androidx/compose/ui/inspection/inspector/LayoutInspectorTreeTest.kt
index 635450c1319..2da7184b7e5 100644
--- a/compose/ui/ui-inspection/src/androidTest/java/androidx/compose/ui/inspection/inspector/LayoutInspectorTreeTest.kt
+++ b/compose/ui/ui-inspection/src/androidTest/java/androidx/compose/ui/inspection/inspector/LayoutInspectorTreeTest.kt
@@ -31,6 +31,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.BasicText
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
@@ -60,17 +61,21 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.inspection.compose.flatten
import androidx.compose.ui.inspection.testdata.TestActivity
+import androidx.compose.ui.inspection.util.ThreadUtils
import androidx.compose.ui.layout.GraphicLayerInfo
import androidx.compose.ui.node.Ref
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.isDebugInspectorInfoEnabled
+import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.text
import androidx.compose.ui.test.junit4.createAndroidComposeRule
+import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
+import androidx.compose.ui.test.performScrollToIndex
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
@@ -974,7 +979,36 @@ class LayoutInspectorTreeTest {
val builder = LayoutInspectorTree()
builder.hideSystemNodes = false
builder.includeAllParameters = false
- builder.convert(androidComposeView)
+ }
+
+ @Test // regression test for b/311436726
+ fun testLazyColumn() {
+ val slotTableRecord = CompositionDataRecord.create()
+
+ show {
+ Inspectable(slotTableRecord) {
+ LazyColumn(modifier = Modifier.testTag("LazyColumn")) {
+ items(100) { index ->
+ Text(text = "Item: $index")
+ }
+ }
+ }
+ }
+
+ val androidComposeView = findAndroidComposeView()
+ androidComposeView.setTag(R.id.inspection_slot_table_set, slotTableRecord.store)
+ val builder = LayoutInspectorTree()
+ builder.hideSystemNodes = false
+ builder.includeAllParameters = true
+ ThreadUtils.runOnMainThread {
+ builder.convert(androidComposeView)
+ }
+ for (index in 20..40) {
+ composeTestRule.onNodeWithTag("LazyColumn").performScrollToIndex(index)
+ }
+ ThreadUtils.runOnMainThread {
+ builder.convert(androidComposeView)
+ }
}
@Suppress("SameParameterValue")
diff --git a/compose/ui/ui-inspection/src/main/java/androidx/compose/ui/inspection/inspector/LayoutInspectorTree.kt b/compose/ui/ui-inspection/src/main/java/androidx/compose/ui/inspection/inspector/LayoutInspectorTree.kt
index a36e3d6c183..8a72392e270 100644
--- a/compose/ui/ui-inspection/src/main/java/androidx/compose/ui/inspection/inspector/LayoutInspectorTree.kt
+++ b/compose/ui/ui-inspection/src/main/java/androidx/compose/ui/inspection/inspector/LayoutInspectorTree.kt
@@ -503,7 +503,7 @@ class LayoutInspectorTree {
val size = box.size.toSize()
val coordinates = layoutInfo.coordinates
var bounds: QuadBounds? = null
- if (layoutInfo.isAttached) {
+ if (layoutInfo.isAttached && coordinates.isAttached) {
val topLeft = toIntOffset(coordinates.localToWindow(Offset.Zero))
val topRight = toIntOffset(coordinates.localToWindow(Offset(size.width, 0f)))
val bottomRight =
diff --git a/compose/ui/ui-tooling-data/src/jvmMain/kotlin/androidx/compose/ui/tooling/data/SlotTree.jvm.kt b/compose/ui/ui-tooling-data/src/jvmMain/kotlin/androidx/compose/ui/tooling/data/SlotTree.jvm.kt
index d2505dbe97f..c4397660107 100644
--- a/compose/ui/ui-tooling-data/src/jvmMain/kotlin/androidx/compose/ui/tooling/data/SlotTree.jvm.kt
+++ b/compose/ui/ui-tooling-data/src/jvmMain/kotlin/androidx/compose/ui/tooling/data/SlotTree.jvm.kt
@@ -557,7 +557,8 @@ private fun CompositionGroup.getGroup(parentContext: SourceInformationContext?):
}
private fun boundsOfLayoutNode(node: LayoutInfo): IntRect {
- if (!node.isAttached) {
+ val coordinates = node.coordinates
+ if (!node.isAttached || !coordinates.isAttached) {
return IntRect(
left = 0,
top = 0,
@@ -565,8 +566,8 @@ private fun boundsOfLayoutNode(node: LayoutInfo): IntRect {
bottom = node.height
)
}
- val position = node.coordinates.positionInWindow()
- val size = node.coordinates.size
+ val position = coordinates.positionInWindow()
+ val size = coordinates.size
val left = position.x.roundToInt()
val top = position.y.roundToInt()
val right = left + size.width