Loading core/ui/compose/designsystem/src/main/kotlin/app/k9mail/core/ui/compose/designsystem/atom/textfield/TextFieldCommon.kt +7 −0 Original line number Diff line number Diff line package app.k9mail.core.ui.compose.designsystem.atom.textfield import androidx.compose.runtime.Composable import androidx.compose.ui.text.input.TextFieldValue private val LINE_BREAK = "[\\r\\n]".toRegex() Loading @@ -8,6 +9,12 @@ internal fun stripLineBreaks(onValueChange: (String) -> Unit): (String) -> Unit onValueChange(value.replace(LINE_BREAK, replacement = "")) } internal fun stripTextFieldValueLineBreaks(onValueChange: (TextFieldValue) -> Unit): (TextFieldValue) -> Unit { return { value -> onValueChange(value.copy(text = value.text.replace(LINE_BREAK, replacement = ""))) } } internal fun selectLabel( label: String?, isRequired: Boolean, Loading core/ui/compose/designsystem/src/main/kotlin/app/k9mail/core/ui/compose/designsystem/atom/textfield/TextFieldOutlined.kt +33 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ package app.k9mail.core.ui.compose.designsystem.atom.textfield import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.material3.OutlinedTextField as Material3OutlinedTextField @Suppress("LongParameterList") Loading Loading @@ -33,3 +34,35 @@ fun TextFieldOutlined( keyboardOptions = keyboardOptions, ) } /** * Overload of [TextFieldOutlined] that accepts a [TextFieldValue] instead of a [String]. */ @Suppress("LongParameterList") @Composable fun TextFieldOutlined( value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, modifier: Modifier = Modifier, label: String? = null, trailingIcon: @Composable (() -> Unit)? = null, isEnabled: Boolean = true, isReadOnly: Boolean = false, isRequired: Boolean = false, hasError: Boolean = false, isSingleLine: Boolean = true, keyboardOptions: KeyboardOptions = KeyboardOptions.Default, ) { Material3OutlinedTextField( value = value, onValueChange = if (isSingleLine) stripTextFieldValueLineBreaks(onValueChange) else onValueChange, modifier = modifier, enabled = isEnabled, label = selectLabel(label, isRequired), trailingIcon = trailingIcon, readOnly = isReadOnly, isError = hasError, singleLine = isSingleLine, keyboardOptions = keyboardOptions, ) } Loading
core/ui/compose/designsystem/src/main/kotlin/app/k9mail/core/ui/compose/designsystem/atom/textfield/TextFieldCommon.kt +7 −0 Original line number Diff line number Diff line package app.k9mail.core.ui.compose.designsystem.atom.textfield import androidx.compose.runtime.Composable import androidx.compose.ui.text.input.TextFieldValue private val LINE_BREAK = "[\\r\\n]".toRegex() Loading @@ -8,6 +9,12 @@ internal fun stripLineBreaks(onValueChange: (String) -> Unit): (String) -> Unit onValueChange(value.replace(LINE_BREAK, replacement = "")) } internal fun stripTextFieldValueLineBreaks(onValueChange: (TextFieldValue) -> Unit): (TextFieldValue) -> Unit { return { value -> onValueChange(value.copy(text = value.text.replace(LINE_BREAK, replacement = ""))) } } internal fun selectLabel( label: String?, isRequired: Boolean, Loading
core/ui/compose/designsystem/src/main/kotlin/app/k9mail/core/ui/compose/designsystem/atom/textfield/TextFieldOutlined.kt +33 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ package app.k9mail.core.ui.compose.designsystem.atom.textfield import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.material3.OutlinedTextField as Material3OutlinedTextField @Suppress("LongParameterList") Loading Loading @@ -33,3 +34,35 @@ fun TextFieldOutlined( keyboardOptions = keyboardOptions, ) } /** * Overload of [TextFieldOutlined] that accepts a [TextFieldValue] instead of a [String]. */ @Suppress("LongParameterList") @Composable fun TextFieldOutlined( value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, modifier: Modifier = Modifier, label: String? = null, trailingIcon: @Composable (() -> Unit)? = null, isEnabled: Boolean = true, isReadOnly: Boolean = false, isRequired: Boolean = false, hasError: Boolean = false, isSingleLine: Boolean = true, keyboardOptions: KeyboardOptions = KeyboardOptions.Default, ) { Material3OutlinedTextField( value = value, onValueChange = if (isSingleLine) stripTextFieldValueLineBreaks(onValueChange) else onValueChange, modifier = modifier, enabled = isEnabled, label = selectLabel(label, isRequired), trailingIcon = trailingIcon, readOnly = isReadOnly, isError = hasError, singleLine = isSingleLine, keyboardOptions = keyboardOptions, ) }