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 }