From 4b28a882a9d9aced18ebd558cb49d113d91923e7 Mon Sep 17 00:00:00 2001 From: AllenTom Date: Sun, 15 Sep 2024 09:16:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AF=84=E8=AE=BA=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/composables/EditCommentBottomModal.kt | 32 +++++++++++++------ .../res/drawable/rider_pro_send_disable.xml | 13 ++++++++ 2 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/drawable/rider_pro_send_disable.xml diff --git a/app/src/main/java/com/aiosman/riderpro/ui/composables/EditCommentBottomModal.kt b/app/src/main/java/com/aiosman/riderpro/ui/composables/EditCommentBottomModal.kt index f4a6bbc..3fd49c8 100644 --- a/app/src/main/java/com/aiosman/riderpro/ui/composables/EditCommentBottomModal.kt +++ b/app/src/main/java/com/aiosman/riderpro/ui/composables/EditCommentBottomModal.kt @@ -1,5 +1,7 @@ package com.aiosman.riderpro.ui.composables +import androidx.compose.animation.Crossfade +import androidx.compose.animation.core.tween import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box @@ -24,6 +26,7 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -74,16 +77,25 @@ fun EditCommentBottomModal( fontSize = 20.sp, fontStyle = FontStyle.Italic ) - Image( - painter = painterResource(id = R.drawable.rider_pro_send), - contentDescription = "Send", - modifier = Modifier - .size(32.dp) - .noRippleClickable { - onSend(text) - text = "" - }, - ) + Crossfade(targetState = text.isNotEmpty(), animationSpec = tween(500)) { isNotEmpty -> + Image( + painter = rememberUpdatedState( + if (isNotEmpty) painterResource(id = R.drawable.rider_pro_send) else painterResource( + id = R.drawable.rider_pro_send_disable + ) + ).value, + contentDescription = "Send", + modifier = Modifier + .size(32.dp) + .noRippleClickable { + if (text.isNotEmpty()){ + onSend(text) + text = "" + } + + }, + ) + } } Spacer(modifier = Modifier.height(16.dp)) if (replyComment != null) { diff --git a/app/src/main/res/drawable/rider_pro_send_disable.xml b/app/src/main/res/drawable/rider_pro_send_disable.xml new file mode 100644 index 0000000..2e25ffc --- /dev/null +++ b/app/src/main/res/drawable/rider_pro_send_disable.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + +