Fix ContentInViewModifier to not read layout coordinates unless attached.
This fix was originally made in aosp/2147367, I'm not sure how it got
removed but probably had something to do with a refactor/rebase while
working on the ContentInViewModifier.
This change should be cherry-picked into the 1.3 release branch.
Fixes: b/244824895
Test: I'm not sure how to write tests for this, but I'm pretty confident
that this missing check is what is causing the crash.
Change-Id: I69efb5713dc18b2364c97b51add2780ced714a8f
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/ContentInViewModifier.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/ContentInViewModifier.kt
index 5b6159f..bd044c3 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/ContentInViewModifier.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/ContentInViewModifier.kt
@@ -130,7 +130,7 @@
// soon be _more_ visible, so don't scroll.
if (!containerShrunk) return
- val focusedChild = focusedChild ?: return
+ val focusedChild = focusedChild?.takeIf { it.isAttached } ?: return
val focusedBounds = coordinates.localBoundingBoxOf(focusedChild, clipBounds = false)
// In order to check if we need to scroll to bring the focused child into view, it's not