From a4523a8de1a13abd4057ace5c5870fa4f3f76ec1 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 19 Jun 2025 09:43:48 +0200 Subject: [PATCH] Inline `TextInput` so that we have code parity in the when statement --- .../libraries/textcomposer/TextComposer.kt | 74 ++++++------------- 1 file changed, 24 insertions(+), 50 deletions(-) diff --git a/libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt b/libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt index 29a5f22449..0014634b7f 100644 --- a/libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt +++ b/libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt @@ -81,7 +81,6 @@ import io.element.android.libraries.textcomposer.model.aTextEditorStateRich import io.element.android.libraries.textcomposer.model.showCaptionCompatibilityWarning import io.element.android.libraries.ui.strings.CommonStrings import io.element.android.wysiwyg.compose.RichTextEditor -import io.element.android.wysiwyg.compose.RichTextEditorState import io.element.android.wysiwyg.display.TextDisplay import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf @@ -174,18 +173,29 @@ fun TextComposer( is TextEditorState.Rich -> { remember(state.richTextEditorState, subcomposing, composerMode, onResetComposerMode, onError) { @Composable { - TextInput( - state = state.richTextEditorState, - subcomposing = subcomposing, - placeholder = placeholder, + TextInputBox( composerMode = composerMode, onResetComposerMode = onResetComposerMode, - resolveMentionDisplay = resolveMentionDisplay, - resolveRoomMentionDisplay = resolveAtRoomMentionDisplay, - onError = onError, - onTyping = onTyping, - onSelectRichContent = onSelectRichContent, - ) + placeholder = placeholder, + showPlaceholder = state.richTextEditorState.messageHtml.isEmpty(), + subcomposing = subcomposing, + ) { + RichTextEditor( + state = state.richTextEditorState, + // Disable most of the editor functionality if it's just being measured for a subcomposition. + // This prevents it gaining focus and mutating the state. + registerStateUpdates = !subcomposing, + modifier = Modifier + .padding(top = 6.dp, bottom = 6.dp) + .fillMaxWidth(), + style = ElementRichTextEditorStyle.composerStyle(hasFocus = state.richTextEditorState.hasFocus), + resolveMentionDisplay = resolveMentionDisplay, + resolveRoomMentionDisplay = resolveAtRoomMentionDisplay, + onError = onError, + onRichContentSelected = onSelectRichContent, + onTyping = onTyping, + ) + } } } } @@ -437,7 +447,9 @@ private fun TextFormattingLayout( ) { val bottomPadding = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() + 8.dp } Column( - modifier = modifier.padding(vertical = 4.dp).padding(bottom = bottomPadding), + modifier = modifier + .padding(vertical = 4.dp) + .padding(bottom = bottomPadding), verticalArrangement = Arrangement.spacedBy(4.dp), ) { if (isRoomEncrypted == false) { @@ -546,44 +558,6 @@ private fun TextInputBox( } } -@Composable -private fun TextInput( - state: RichTextEditorState, - subcomposing: Boolean, - placeholder: String, - composerMode: MessageComposerMode, - onResetComposerMode: () -> Unit, - resolveRoomMentionDisplay: () -> TextDisplay, - resolveMentionDisplay: (text: String, url: String) -> TextDisplay, - onError: (Throwable) -> Unit, - onTyping: (Boolean) -> Unit, - onSelectRichContent: ((Uri) -> Unit)?, -) { - TextInputBox( - composerMode = composerMode, - onResetComposerMode = onResetComposerMode, - placeholder = placeholder, - showPlaceholder = state.messageHtml.isEmpty(), - subcomposing = subcomposing, - ) { - RichTextEditor( - state = state, - // Disable most of the editor functionality if it's just being measured for a subcomposition. - // This prevents it gaining focus and mutating the state. - registerStateUpdates = !subcomposing, - modifier = Modifier - .padding(top = 6.dp, bottom = 6.dp) - .fillMaxWidth(), - style = ElementRichTextEditorStyle.composerStyle(hasFocus = state.hasFocus), - resolveMentionDisplay = resolveMentionDisplay, - resolveRoomMentionDisplay = resolveRoomMentionDisplay, - onError = onError, - onRichContentSelected = onSelectRichContent, - onTyping = onTyping, - ) - } -} - private fun aTextEditorStateMarkdownList(isRoomEncrypted: Boolean? = null) = persistentListOf( aTextEditorStateMarkdown(initialText = "", initialFocus = true, isRoomEncrypted = isRoomEncrypted), aTextEditorStateMarkdown(initialText = "A message", initialFocus = true, isRoomEncrypted = isRoomEncrypted),