From 4db78310f94e2be934e7c6a70fd8e116d29173a6 Mon Sep 17 00:00:00 2001 From: Super12138 <70494801+Super12138@users.noreply.github.com> Date: Fri, 4 Jul 2025 12:39:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=BC=8F=E5=8A=A0=E7=9A=84=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/ui/pages/editor/TodoEditorPage.kt | 9 +++++++++ .../pages/editor/components/TodoEditorTextFields.kt | 12 +++--------- .../todo/ui/pages/editor/state/EditorState.kt | 4 +++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt index c77b033..eb2db7f 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/TodoEditorPage.kt @@ -205,6 +205,15 @@ fun TodoEditorPage( value = uiState.categoryContent, onValueChange = { uiState.categoryContent = it }, isError = uiState.isErrorCategory, + supportingText = when { + uiState.categoryContent.trim().isEmpty() -> + stringResource(R.string.error_no_content_entered) + + uiState.categoryContent.length > 5 -> + stringResource(R.string.error_exceeds_5_chars) + + else -> stringResource(R.string.tip_max_length_5) + }, modifier = Modifier .fillMaxWidth() /*.sharedBounds( diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/components/TodoEditorTextFields.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/components/TodoEditorTextFields.kt index fa4e520..457a096 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/components/TodoEditorTextFields.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/components/TodoEditorTextFields.kt @@ -42,6 +42,7 @@ fun TodoCategoryTextField( value: String, onValueChange: (String) -> Unit, isError: Boolean, + supportingText: String = stringResource(R.string.tip_max_length_5), modifier: Modifier = Modifier ) { TextField( @@ -49,15 +50,8 @@ fun TodoCategoryTextField( onValueChange = onValueChange, label = { Text(stringResource(R.string.label_enter_category_name)) }, isError = isError, - supportingText = { - AnimatedVisibility( - visible = isError, - enter = fadeIn() + expandVertically(), - exit = fadeOut() + shrinkVertically() - ) { - Text(stringResource(R.string.error_no_content_entered)) - } - }, + supportingText = { Text(supportingText) }, + maxLines = 1, modifier = modifier ) } \ No newline at end of file diff --git a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/state/EditorState.kt b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/state/EditorState.kt index c8c54a5..308a988 100644 --- a/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/state/EditorState.kt +++ b/app/src/main/kotlin/cn/super12138/todo/ui/pages/editor/state/EditorState.kt @@ -29,7 +29,9 @@ class EditorState(val initialTodo: TodoEntity? = null) { */ fun setErrorIfNotValid(): Boolean { isErrorContent = toDoContent.trim().isEmpty() - isErrorCategory = if (selectedCategoryIndex == -1) categoryContent.trim().isEmpty() else false + isErrorCategory = if (selectedCategoryIndex == -1) { + categoryContent.trim().isEmpty() || categoryContent.trim().length > 5 + } else false return isErrorContent || isErrorCategory }