From 9bf1df3618f0a7a409ffcf5886623b68aaf6d836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Mon, 22 Jan 2024 11:08:25 +0100 Subject: [PATCH 1/2] Make `ContentAvoidingLayoutScopeInstance` scope aware so message bubbles are resized when edited. --- changelog.d/2260.bugfix | 1 + .../components/layout/ContentAvoidingLayout.kt | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 changelog.d/2260.bugfix 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..f530427d4f 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,6 +18,8 @@ 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 @@ -75,7 +77,7 @@ fun ContentAvoidingLayout( 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 +137,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 } } From 8d376fbe6606890998e2adb73b5458c3cd04827c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Mon, 22 Jan 2024 11:44:46 +0100 Subject: [PATCH 2/2] Move back to using `Layout` instead of `SubcomposeLayout` --- .../components/layout/ContentAvoidingLayout.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 f530427d4f..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 @@ -23,7 +23,6 @@ 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 @@ -61,18 +60,22 @@ 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