diff --git a/changelog.d/2260.bugfix b/changelog.d/2260.bugfix new file mode 100644 index 0000000000..23501e3264 --- /dev/null +++ b/changelog.d/2260.bugfix @@ -0,0 +1 @@ +Edited text message bubbles should resize when edited diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/layout/ContentAvoidingLayout.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/layout/ContentAvoidingLayout.kt index 5df38c1845..334899288d 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/layout/ContentAvoidingLayout.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/layout/ContentAvoidingLayout.kt @@ -18,10 +18,11 @@ package io.element.android.features.messages.impl.timeline.components.layout import android.text.Layout import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.layout.Layout -import androidx.compose.ui.layout.SubcomposeLayout import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.text.TextLayoutResult import androidx.compose.ui.unit.Constraints @@ -59,23 +60,27 @@ fun ContentAvoidingLayout( ) { val scope = remember { ContentAvoidingLayoutScopeInstance() } - SubcomposeLayout( + Layout( modifier = modifier, - ) { constraints -> + content = { + scope.content() + overlay() + } + ) { measurables, constraints -> // Measure the `overlay` view first, in case we need to shrink the `content` - val overlayPlaceable = subcompose(0, overlay).first().measure(Constraints(minWidth = 0, maxWidth = constraints.maxWidth)) + val overlayPlaceable = measurables.last().measure(Constraints(minWidth = 0, maxWidth = constraints.maxWidth)) val contentConstraints = if (shrinkContent) { Constraints(minWidth = 0, maxWidth = constraints.maxWidth - overlayPlaceable.width) } else { Constraints(minWidth = 0, maxWidth = constraints.maxWidth) } - val contentPlaceable = subcompose(1) { scope.content() }.first().measure(contentConstraints) + val contentPlaceable = measurables.first().measure(contentConstraints) var layoutWidth = contentPlaceable.width var layoutHeight = contentPlaceable.height - val data = scope.data + val data = scope.data.value // Free space = width of the whole component - width of its non overlapping contents val freeSpace = max(contentPlaceable.width - data.nonOverlappingContentWidth, 0) @@ -135,13 +140,10 @@ interface ContentAvoidingLayoutScope { } private class ContentAvoidingLayoutScopeInstance( - val data: ContentAvoidingLayoutData = ContentAvoidingLayoutData(), + val data: MutableState = mutableStateOf(ContentAvoidingLayoutData()), ) : ContentAvoidingLayoutScope { override fun onContentLayoutChanged(data: ContentAvoidingLayoutData) { - this.data.contentWidth = data.contentWidth - this.data.contentHeight = data.contentHeight - this.data.nonOverlappingContentWidth = data.nonOverlappingContentWidth - this.data.nonOverlappingContentHeight = data.nonOverlappingContentHeight + this.data.value = data } }