From dd708abddffa95ed4f157f54909c1b5f7224696a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 29 Jun 2023 12:55:07 +0200 Subject: [PATCH] Animate rounded corner size change to avoid blink effect when changing number of lines from 1 <-> 2 in the composer. --- .../libraries/textcomposer/TextComposer.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt b/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt index e8791f8938..69c04b6f87 100644 --- a/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt +++ b/libraries/textcomposer/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt @@ -16,6 +16,8 @@ package io.element.android.libraries.textcomposer +import androidx.compose.animation.core.animateDpAsState +import androidx.compose.animation.core.tween import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -105,14 +107,20 @@ fun TextComposer( AttachmentButton(onClick = onAddAttachment, modifier = Modifier.padding(vertical = 6.dp)) Spacer(modifier = Modifier.width(12.dp)) var lineCount by remember { mutableStateOf(0) } - val roundedCorners = remember(lineCount, composerMode) { + val roundedCornerSize = remember(lineCount, composerMode) { if (lineCount > 1 || composerMode is MessageComposerMode.Special) { - RoundedCornerShape(20.dp) + 20.dp } else { - RoundedCornerShape(28.dp) + 28.dp } } - + val roundedCornerSizeState = animateDpAsState( + targetValue = roundedCornerSize, + animationSpec = tween( + durationMillis = 100, + ) + ) + val roundedCorners = RoundedCornerShape(roundedCornerSizeState.value) val minHeight = 42.dp val bgColor = ElementTheme.colors.bgSubtleSecondary val borderColor = ElementTheme.colors.borderDisabled