Impose note editor length limit

This commit is contained in:
imkunet 2024-02-20 02:43:16 -05:00 committed by imkunet
parent f262f68ea7
commit 05fc1d7b4f
No known key found for this signature in database
GPG Key ID: 32E0ECFB90A68C42

View File

@ -1,8 +1,12 @@
package eu.kanade.presentation.manga.components package eu.kanade.presentation.manga.components
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
@ -11,12 +15,15 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.text.TextRange import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.input.TextFieldValue
import eu.kanade.tachiyomi.ui.manga.notes.MangaNotesScreenState import eu.kanade.tachiyomi.ui.manga.notes.MangaNotesScreenState
private const val MAX_LENGTH = 10_000
@Composable @Composable
fun MangaNotesTextArea( fun MangaNotesTextArea(
state: MangaNotesScreenState.Success, state: MangaNotesScreenState.Success,
@ -34,10 +41,28 @@ fun MangaNotesTextArea(
) { ) {
OutlinedTextField( OutlinedTextField(
value = text, value = text,
onValueChange = { text = it }, onValueChange = { if (it.text.length <= MAX_LENGTH) text = it },
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.focusRequester(focusRequester), .focusRequester(focusRequester),
supportingText = {
val displayWarning = text.text.length > MAX_LENGTH / 10 * 9
if (!displayWarning) {
Text(
text = "0",
modifier = Modifier.alpha(0f),
)
}
AnimatedVisibility(
displayWarning,
enter = fadeIn(),
exit = fadeOut(),
) {
Text(
text = "${text.text.length} / $MAX_LENGTH",
)
}
},
) )
} }