Skip to content

Commit

Permalink
CommonTextField
Browse files Browse the repository at this point in the history
  • Loading branch information
reosfire committed Aug 30, 2024
1 parent 65240bd commit bcd8d4c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 30 deletions.
2 changes: 1 addition & 1 deletion App/src/main/kotlin/ru/reosfire/pixorio/app/AppWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<File?>(null)
private var lastContinuation: CancellableContinuation<File>? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -31,7 +23,7 @@ fun TextFilePicker(

val focusManager = LocalFocusManager.current

BasicTextField(
CommonTextField(
value = text,
onValueChange = {
val file = File(it.trim())
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
}

0 comments on commit bcd8d4c

Please sign in to comment.