From 0e55b13d9019c20b508f32366446e3390224557b Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:20:09 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20Pad=20=E5=9B=9E=E5=A4=8D=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/ui/page/reply/ReplyPage.kt | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/reply/ReplyPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/reply/ReplyPage.kt index 9b2f2446..a7b5adeb 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/reply/ReplyPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/reply/ReplyPage.kt @@ -92,6 +92,7 @@ import com.huanchengfly.tieba.post.pxToDpFloat import com.huanchengfly.tieba.post.toMD5 import com.huanchengfly.tieba.post.toastShort import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme +import com.huanchengfly.tieba.post.ui.page.destinations.ReplyPageDestination import com.huanchengfly.tieba.post.ui.page.reply.ReplyPanelType.EMOJI import com.huanchengfly.tieba.post.ui.page.reply.ReplyPanelType.IMAGE import com.huanchengfly.tieba.post.ui.page.reply.ReplyPanelType.NONE @@ -99,6 +100,7 @@ import com.huanchengfly.tieba.post.ui.utils.imeNestedScroll import com.huanchengfly.tieba.post.ui.widgets.compose.Dialog import com.huanchengfly.tieba.post.ui.widgets.compose.DialogNegativeButton import com.huanchengfly.tieba.post.ui.widgets.compose.DialogPositiveButton +import com.huanchengfly.tieba.post.ui.widgets.compose.MyBackHandler import com.huanchengfly.tieba.post.ui.widgets.compose.VerticalDivider import com.huanchengfly.tieba.post.ui.widgets.compose.rememberDialogState import com.huanchengfly.tieba.post.ui.widgets.edittext.widget.UndoableEditText @@ -124,6 +126,7 @@ import org.litepal.extension.deleteAllAsync import org.litepal.extension.findFirstAsync import java.util.UUID import kotlin.concurrent.thread +import kotlin.math.max // TODO: 将软键盘状态相关逻辑抽离出来 @OptIn( @@ -296,6 +299,13 @@ fun ReplyPage( } } + MyBackHandler( + enabled = curKeyboardType != NONE, + currentScreen = ReplyPageDestination + ) { + switchToPanel(NONE) + } + val density = LocalDensity.current val imeInset = WindowInsets.ime val imeAnimationTargetInset = WindowInsets.imeAnimationTarget @@ -315,7 +325,7 @@ fun ReplyPage( .collect { value = it } } val imeAnimationEnd by remember { derivedStateOf { imeCurrentHeight == imeAnimationTargetHeight } } - val imeVisibleHeight by produceState( + val imeVisibleHeightPx by produceState( initialValue = remember { context.appPreferences.imeHeight }, imeAnimationTargetInset, density @@ -329,6 +339,10 @@ fun ReplyPage( } } + val panelHeight by remember { + derivedStateOf { max(imeVisibleHeightPx.pxToDpFloat(), 150f).dp } + } + val textMeasurer = rememberTextMeasurer() val minResult = textMeasurer.measure( @@ -561,7 +575,7 @@ fun ReplyPage( .windowInsetsBottomHeight(WindowInsets.ime) ) if (curKeyboardType != NONE) { - Column(modifier = Modifier.height(imeVisibleHeight.pxToDpFloat().dp)) { + Column(modifier = Modifier.height(panelHeight)) { when (curKeyboardType) { EMOJI -> { EmoticonPanel( @@ -600,7 +614,7 @@ fun ReplyPage( Spacer( modifier = Modifier .fillMaxWidth() - .height(imeVisibleHeight.pxToDpFloat().dp) + .height(panelHeight) ) } }