From b366446cabca26b3f64a63a099ae937cf3fa90d0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 2 Dec 2025 16:36:30 +0100 Subject: [PATCH] Let the composer takes at max half of the available height. The value will be different if the soft keyboard is displayed or not. Closes #3851 --- .../features/messages/impl/MessagesView.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt index 1f62adeb23..14a021a067 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt @@ -29,10 +29,15 @@ import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.shadow import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.Role @@ -82,6 +87,7 @@ import io.element.android.libraries.designsystem.components.rememberExpandableBo import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.text.toAnnotatedString +import io.element.android.libraries.designsystem.text.toDp import io.element.android.libraries.designsystem.theme.components.BottomSheetDragHandle import io.element.android.libraries.designsystem.theme.components.Scaffold import io.element.android.libraries.designsystem.theme.components.Text @@ -129,6 +135,8 @@ fun MessagesView( val snackbarHostState = rememberSnackbarHostState(snackbarMessage = state.snackbarMessage) + var maxComposerHeightPx by remember { mutableIntStateOf(120) } + // This is needed because the composer is inside an AndroidView that can't be affected by the FocusManager in Compose val localView = LocalView.current @@ -179,7 +187,13 @@ fun MessagesView( modifier = modifier .fillMaxSize() .imePadding() - .systemBarsPadding(), + .systemBarsPadding() + .onSizeChanged { size -> + // Let the composer takes at max half of the available height. + // The value will be different if the soft keyboard is displayed + // or not. + maxComposerHeightPx = (size.height * 0.5f).toInt() + }, content = { Scaffold( contentWindowInsets = WindowInsets.statusBars, @@ -313,7 +327,7 @@ fun MessagesView( } else { RectangleShape }, - maxBottomSheetContentHeight = 360.dp, + maxBottomSheetContentHeight = maxComposerHeightPx.toDp(), ) ActionListView(