diff --git a/App/src/main/kotlin/ru/reosfire/pixorio/app/AppWindow.kt b/App/src/main/kotlin/ru/reosfire/pixorio/app/AppWindow.kt index ca9ea3a..c250655 100644 --- a/App/src/main/kotlin/ru/reosfire/pixorio/app/AppWindow.kt +++ b/App/src/main/kotlin/ru/reosfire/pixorio/app/AppWindow.kt @@ -51,7 +51,7 @@ import kotlin.math.max import kotlin.math.min class FilePickerState { - var shown by mutableStateOf(true) + var shown by mutableStateOf(false) private var cachedSaveLocation by mutableStateOf(null) private var lastContinuation: CancellableContinuation? = null diff --git a/App/src/main/kotlin/ru/reosfire/pixorio/app/filepicker/FilePicker.kt b/App/src/main/kotlin/ru/reosfire/pixorio/app/filepicker/FilePicker.kt index 2cf1fd3..b5c3f59 100644 --- a/App/src/main/kotlin/ru/reosfire/pixorio/app/filepicker/FilePicker.kt +++ b/App/src/main/kotlin/ru/reosfire/pixorio/app/filepicker/FilePicker.kt @@ -1,23 +1,19 @@ package ru.reosfire.pixorio.app.filepicker import androidx.compose.foundation.background -import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.foundation.text.BasicTextField import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.ImageBitmap -import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.res.loadImageBitmap import androidx.compose.ui.res.useResource -import androidx.compose.ui.text.TextStyle import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp import androidx.compose.ui.window.DialogWindow @@ -72,22 +68,15 @@ fun FilePickerDialog( .padding(8.dp) ) { Row(Modifier.fillMaxWidth()) { - BasicTextField( + CommonTextField( value = fileName, onValueChange = { fileName = it }, - textStyle = TextStyle.Default.copy( - color = MaterialTheme.colors.onBackground, - ), singleLine = true, - cursorBrush = SolidColor(MaterialTheme.colors.onBackground), modifier = Modifier .padding(end = 8.dp) .weight(1f) - .border(1.dp, MaterialTheme.colors.onBackground, RoundedCornerShape(4.dp)) - .background(MaterialTheme.colors.background) - .padding(horizontal = 4.dp, vertical = 4.dp) ) DropdownSelector(extensionSelectorState) diff --git a/App/src/main/kotlin/ru/reosfire/pixorio/app/filepicker/TextFilePicker.kt b/App/src/main/kotlin/ru/reosfire/pixorio/app/filepicker/TextFilePicker.kt index 69c5387..90194b6 100644 --- a/App/src/main/kotlin/ru/reosfire/pixorio/app/filepicker/TextFilePicker.kt +++ b/App/src/main/kotlin/ru/reosfire/pixorio/app/filepicker/TextFilePicker.kt @@ -1,20 +1,12 @@ package ru.reosfire.pixorio.app.filepicker -import androidx.compose.foundation.background -import androidx.compose.foundation.border import androidx.compose.foundation.focusable -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.foundation.text.BasicTextField -import androidx.compose.material.MaterialTheme import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.focus.onFocusChanged -import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.input.key.* import androidx.compose.ui.platform.LocalFocusManager -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.unit.dp +import ru.reosfire.pixorio.designsystem.componentes.CommonTextField import java.io.File @Composable @@ -31,7 +23,7 @@ fun TextFilePicker( val focusManager = LocalFocusManager.current - BasicTextField( + CommonTextField( value = text, onValueChange = { val file = File(it.trim()) @@ -42,15 +34,8 @@ fun TextFilePicker( text = it } }, - textStyle = TextStyle.Default.copy( - color = MaterialTheme.colors.onBackground, - ), singleLine = true, - cursorBrush = SolidColor(MaterialTheme.colors.onBackground), modifier = modifier - .border(1.dp, MaterialTheme.colors.onBackground, RoundedCornerShape(4.dp)) - .background(MaterialTheme.colors.background) - .padding(horizontal = 4.dp) .onPreviewKeyEvent { if (it.key == Key.Enter && it.type == KeyEventType.KeyUp) { focusManager.clearFocus() diff --git a/DesignSystem/src/main/kotlin/ru/reosfire/pixorio/designsystem/componentes/CommonTextField.kt b/DesignSystem/src/main/kotlin/ru/reosfire/pixorio/designsystem/componentes/CommonTextField.kt new file mode 100644 index 0000000..4d51056 --- /dev/null +++ b/DesignSystem/src/main/kotlin/ru/reosfire/pixorio/designsystem/componentes/CommonTextField.kt @@ -0,0 +1,65 @@ +package ru.reosfire.pixorio.designsystem.componentes + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.text.BasicTextField +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.material.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.text.TextLayoutResult +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.input.VisualTransformation +import androidx.compose.ui.unit.dp + +@Composable +fun CommonTextField( + value: String, + onValueChange: (String) -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, + readOnly: Boolean = false, + textStyle: TextStyle = TextStyle.Default.copy( + color = MaterialTheme.colors.onBackground, + ), + keyboardOptions: KeyboardOptions = KeyboardOptions.Default, + keyboardActions: KeyboardActions = KeyboardActions.Default, + singleLine: Boolean = false, + maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE, + minLines: Int = 1, + visualTransformation: VisualTransformation = VisualTransformation.None, + onTextLayout: (TextLayoutResult) -> Unit = {}, + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, + cursorBrush: Brush = SolidColor(MaterialTheme.colors.onBackground), + decorationBox: @Composable (innerTextField: @Composable () -> Unit) -> Unit = + @Composable { innerTextField -> innerTextField() } +) { + BasicTextField( + value = value, + onValueChange = onValueChange, + modifier = modifier + .border(1.dp, MaterialTheme.colors.onBackground, RoundedCornerShape(4.dp)) + .background(MaterialTheme.colors.background) + .padding(4.dp), + enabled = enabled, + readOnly = readOnly, + textStyle = textStyle, + keyboardOptions = keyboardOptions, + keyboardActions = keyboardActions, + singleLine = singleLine, + maxLines = maxLines, + minLines = minLines, + visualTransformation = visualTransformation, + onTextLayout = onTextLayout, + interactionSource = interactionSource, + cursorBrush = cursorBrush, + decorationBox = decorationBox, + ) +}