From d8b01cf3e7a4b3c5d70a6194e0e23121c0d823fe Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Mon, 27 Jul 2026 18:15:33 +0200 Subject: [PATCH] Fix `ContentErrorView` not calculating its text size synchronously (#7281) It was using a `LaunchedEffect` instead of relying on the `Text(onTextLayout)` parameter. --- .../contentvalidation/ContentErrorView.kt | 43 +++---------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/contentvalidation/ContentErrorView.kt b/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/contentvalidation/ContentErrorView.kt index 85753246d3..24f4a15200 100644 --- a/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/contentvalidation/ContentErrorView.kt +++ b/libraries/matrixui/src/main/kotlin/io/element/android/libraries/matrix/ui/media/contentvalidation/ContentErrorView.kt @@ -9,26 +9,17 @@ package io.element.android.libraries.matrix.ui.media.contentvalidation import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.movableContentOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberUpdatedState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.TextLayoutResult -import androidx.compose.ui.text.rememberTextMeasurer -import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import io.element.android.compound.theme.ElementTheme import io.element.android.compound.tokens.generated.CompoundIcons @@ -41,7 +32,6 @@ internal fun ContentErrorView( contentPadding: PaddingValues = PaddingValues.Zero, onTextLayout: ((TextLayoutResult) -> Unit)? = null, ) { - val updatedOnTextLayout by rememberUpdatedState(onTextLayout) Row( modifier = modifier .background(color = ElementTheme.colors.bgCriticalSubtle) @@ -61,33 +51,12 @@ internal fun ContentErrorView( color = ElementTheme.colors.textCriticalPrimary, style = ElementTheme.typography.fontBodyMdMedium, ) - val textMeasurer = rememberTextMeasurer() - val textContent = remember(message) { - movableContentOf( - @Composable { - Text( - text = message, - color = ElementTheme.colors.textSecondary, - style = ElementTheme.typography.fontBodySmRegular, - ) - } - ) - } - - // BoxWithConstraints is needed to be able to calculate the text layout in the current constraints, so we can pass it to the onTextLayout callback. - // However, this can't be used inside a SubComposeLayout (like the one in the text composer), so we only use it when the onTextLayout callback - // is provided. - if (updatedOnTextLayout != null) { - BoxWithConstraints(modifier = Modifier.fillMaxWidth()) { - LaunchedEffect(message) { - updatedOnTextLayout?.invoke(textMeasurer.measure(message, overflow = TextOverflow.Visible, constraints = constraints)) - } - - textContent() - } - } else { - textContent() - } + Text( + text = message, + color = ElementTheme.colors.textSecondary, + style = ElementTheme.typography.fontBodySmRegular, + onTextLayout = onTextLayout, + ) } } }