Don't cache intrinsicHeight through text changes

Only applies to annotatedstring / layout result implementation

Fixes: b/217910352
Test: ./gradlew :com:found:found:cAT
(cherry picked from https://android-review.googlesource.com/q/commit:e9ef4f948b25c55dd15eecf31476b287fd3966d8)
Merged-In: Ied047b99122e43d1a0c088f742fe090df5c0c4c2
Change-Id: Ied047b99122e43d1a0c088f742fe090df5c0c4c2
diff --git a/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/modifiers/MultiParagraphLayoutCacheTest.kt b/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/modifiers/MultiParagraphLayoutCacheTest.kt
index 9cd1aab..6a51fca 100644
--- a/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/modifiers/MultiParagraphLayoutCacheTest.kt
+++ b/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/modifiers/MultiParagraphLayoutCacheTest.kt
@@ -69,6 +69,34 @@
     }
 
     @Test
+    fun intrinsicHeight_invalidates() {
+        val fontSize = 20.sp
+        val text = "Hello"
+        val spanStyle = SpanStyle(fontSize = fontSize, fontFamily = fontFamily)
+        val annotatedString = AnnotatedString(text, spanStyle)
+        val textDelegate = MultiParagraphLayoutCache(
+            text = annotatedString,
+            style = TextStyle.Default,
+            fontFamilyResolver = fontFamilyResolver,
+        ).also {
+            it.density = density
+        }
+
+        val original = textDelegate.intrinsicHeight(20, LayoutDirection.Ltr)
+        textDelegate.update(AnnotatedString("Longer\ntext\ngoes\nhere\n\n\n."),
+            TextStyle.Default,
+            fontFamilyResolver,
+            TextOverflow.Visible,
+            true,
+            Int.MAX_VALUE,
+            -1,
+            null
+        )
+        val after = textDelegate.intrinsicHeight(20, LayoutDirection.Ltr)
+        assertThat(original).isLessThan(after)
+    }
+
+    @Test
     fun maxIntrinsicWidth_getter() {
         with(density) {
             val fontSize = 20.sp
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/modifiers/MultiParagraphLayoutCache.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/modifiers/MultiParagraphLayoutCache.kt
index f9bb08d..accb3b5 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/modifiers/MultiParagraphLayoutCache.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/modifiers/MultiParagraphLayoutCache.kt
@@ -337,6 +337,8 @@
     private fun markDirty() {
         paragraphIntrinsics = null
         layoutCache = null
+        cachedIntrinsicHeight = -1
+        cachedIntrinsicHeightInputWidth = -1
     }
 
     /**